diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-09-09 04:15:05 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-09-09 04:15:05 +0200 |
commit | b3b606e7f3e2f8bab7c92e70e8d0e15bf06e3e3b (patch) | |
tree | 408de7c36f52f91b32963cd036d35d047848bf1c /ffd/util.c | |
parent | f22dc0880f1b9348dc8c056cba0bbce223a39e62 (diff) | |
download | ffd-b3b606e7f3e2f8bab7c92e70e8d0e15bf06e3e3b.tar ffd-b3b606e7f3e2f8bab7c92e70e8d0e15bf06e3e3b.zip |
Implement sending of neigh announcements
Diffstat (limited to 'ffd/util.c')
-rw-r--r-- | ffd/util.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -24,9 +24,16 @@ */ +#define _GNU_SOURCE + #include "util.h" +#include <errno.h> +#include <fcntl.h> #include <stdio.h> +#include <unistd.h> + +#include <sys/stat.h> bool file_readv(const char *file, const char *format, va_list ap) { @@ -40,3 +47,32 @@ bool file_readv(const char *file, const char *format, va_list ap) { return (ret > 0); } + + + +void random_bytes(void *buffer, size_t len) { + size_t read_bytes = 0; + + int fd = open("/dev/urandom", O_RDONLY); + + if (fd < 0) { + fprintf(stderr, "unable to open random device: %m\n"); + exit(1); + } + + while (read_bytes < len) { + ssize_t ret = read(fd, ((char*)buffer)+read_bytes, len-read_bytes); + + if (ret < 0) { + if (errno == EINTR) + continue; + + fprintf(stderr, "unable to read from random device: %m\n"); + exit(1); + } + + read_bytes += ret; + } + + close(fd); +} |