#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"
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
#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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef __GLIBC__
-# include <time.h> /* for srandomdev */
-#endif
#include <unistd.h>
#include "config.h"
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)
{
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();