Use /dev/urandom (which is non-blocking) instead of /dev/random (which
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 6 Jan 2010 17:18:57 +0000 (17:18 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 6 Jan 2010 17:18:57 +0000 (17:18 +0000)
can block forever) for our seed. This fixes a problem with our new Linux
build slave, which is running Linux 2.6 as a VM guest, and which was
timing out waiting for entropy.

Add a comment about using CryptGenRandom on Windows.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31456 f5534014-38df-0310-8fa8-9805f1628bb7

randpkt.c

index a018265112fb07fd37cef50a3fa09e9d38ff1146..4b6644fa68ef2a74c9ef050306b7a5d65008bbcf 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
@@ -688,17 +688,19 @@ seed(void)
        int             fd;
        ssize_t         ret;
 
+#define RANDOM_DEV "/dev/urandom"
+
        /*
-        * Assume it's at least worth trying /dev/random on UN*X.
+        * Assume it's at least worth trying /dev/urandom on UN*X.
         * If it doesn't exist, fall back on time().
         *
-        * XXX - does Windows have a system source of entropy?
+        * XXX - Use CryptGenRandom on Windows?
         */
-       fd = open("/dev/random", O_RDONLY);
+       fd = open(RANDOM_DEV, O_RDONLY);
        if (fd == -1) {
                if (errno != ENOENT) {
                        fprintf(stderr,
-                           "randpkt: Could not open /dev/random for reading: %s\n",
+                           "randpkt: Could not open " RANDOM_DEV " for reading: %s\n",
                            strerror(errno));
                        exit(2);
                }
@@ -708,13 +710,13 @@ seed(void)
        ret = read(fd, &randomness, sizeof randomness);
        if (ret == -1) {
                fprintf(stderr,
-                   "randpkt: Could not read from /dev/random: %s\n",
+                   "randpkt: Could not read from " RANDOM_DEV ": %s\n",
                    strerror(errno));
                exit(2);
        }
        if ((size_t)ret != sizeof randomness) {
                fprintf(stderr,
-                   "randpkt: Tried to read %lu bytes from /dev/random, got %ld\n",
+                   "randpkt: Tried to read %lu bytes from " RANDOM_DEV ", got %ld\n",
                    (unsigned long)sizeof randomness, (long)ret);
                exit(2);
        }