diff options
| author | Roy Marples <roy@marples.name> | 2008-05-19 09:16:55 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-05-19 09:16:55 +0000 |
| commit | 32391c95110f44cd7dd0245221c21b7e0d7e5d5a (patch) | |
| tree | 64329bbd21d08e82b82cac5ddcf6fce2ebc5e422 /common.c | |
| parent | c30da3c20325f4ddbf797bc5f30e5e422b185b6e (diff) | |
| download | dhcpcd-32391c95110f44cd7dd0245221c21b7e0d7e5d5a.tar.xz | |
Create a real arc4linux function so we don't have to visible seed random in dhcpcd main.
Diffstat (limited to 'common.c')
| -rw-r--r-- | common.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -33,9 +33,11 @@ #ifdef BSD # include <paths.h> #endif +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "common.h" @@ -74,6 +76,27 @@ get_line(char **line, size_t *len, FILE *fp) return last; } +/* Simple hack to return a random number without arc4random */ +#ifndef HAVE_ARC4RANDOM +uint32_t arc4random(void) +{ + int fd; + static unsigned long seed = 0; + + if (!seed) { + fd = open("/dev/urandom", 0); + if (fd == -1 || read(fd, &seed, sizeof(seed)) == -1) + seed = time(0); + if (fd >= 0) + close(fd); + + srandom(seed); + } + + return (uint32_t)random(); +} +#endif + /* strlcpy is nice, shame glibc does not define it */ #if HAVE_STRLCPY #else |
