]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Create a real arc4linux function so we don't have to visible seed random in dhcpcd...
authorRoy Marples <roy@marples.name>
Mon, 19 May 2008 09:16:55 +0000 (09:16 +0000)
committerRoy Marples <roy@marples.name>
Mon, 19 May 2008 09:16:55 +0000 (09:16 +0000)
common.c
common.h
dhcpcd.c

index e207258ed0c1434c32ffeae964de16b45e87965a..91fcd7a9ae6b6064e3ac693526b12cd9530c756b 100644 (file)
--- a/common.c
+++ b/common.c
 #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
index 4191846787b93da5f2cc538292ab64cabd46e666..9df668a809cde7a4d60fc868ea2bfc6260a76233 100644 (file)
--- a/common.h
+++ b/common.h
@@ -29,9 +29,9 @@
 #define COMMON_H
 
 /* string.h pulls in features.h so the below define checks work */
-#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 
 # define _unused
 #endif
 
-#ifdef __GLIBC__
-#define arc4random (uint32_t)random
+#ifndef HAVE_ARC4RANDOM
+# ifdef __GLIBC__
+uint32_t arc4random(void);
+#else
+# define HAVE_ARC4RANDOM
+# endif
 #endif
 
 #ifndef HAVE_STRLCPY
index 4f2725bfc65f67da9ebcda96e904c26bcc5e9537..92701094f8db45a0b07de1508fbfc68850a36f76 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -40,9 +40,6 @@ const char copyright[] = "Copyright (c) 2006-2008 Roy Marples";
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef __GLIBC__
-#  include <time.h> /* for srandomdev */
-#endif
 #include <unistd.h>
 
 #include "config.h"
@@ -136,22 +133,6 @@ atoint(const char *s)
        return (int)n;
 }
 
-#ifdef __GLIBC__
-static void srandomdev(void)
-{
-       int fd;
-       unsigned long 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);
-}
-#endif
-
 static pid_t
 read_pid(const char *pidfile)
 {
@@ -789,11 +770,6 @@ main(int argc, char **argv)
                logger(LOG_INFO, PACKAGE " " VERSION " starting");
        }
 
-#ifdef __GLIBC__
-       /* We need to seed random for our fake arc4random call */
-       srandomdev();
-#endif
-
 #ifdef __linux__
        /* Massage our filters per platform */
        setup_packet_filters();