for (;;) {
addr.s_addr = htonl(LINKLOCAL_ADDR |
- (((uint32_t)abs((int)random())
+ (((uint32_t)abs((int)arc4random())
% 0xFD00) + 0x0100));
errno = 0;
if (!arp_claim(iface, addr))
logger (LOG_INFO, "received SIGHUP, releasing lease");
if (!IN_LINKLOCAL(ntohl(lease->addr.s_addr))) {
do_socket(state, SOCKET_OPEN);
- state->xid = (uint32_t)random();
+ state->xid = arc4random();
send_message(state, DHCP_RELEASE, options);
do_socket(state, SOCKET_CLOSED);
}
switch (state->state) {
case STATE_INIT:
- state->xid = (uint32_t) random ();
+ state->xid = arc4random();
do_socket(state, SOCKET_OPEN);
state->timeout = options->timeout;
iface->start_uptime = uptime ();
break;
}
state->state = STATE_RENEWING;
- state->xid = (uint32_t)random();
+ state->xid = arc4random();
/* FALLTHROUGH */
case STATE_RENEWING:
iface->start_uptime = uptime();
lease->addr.s_addr = 0;
do_socket(state, SOCKET_OPEN);
if (state->xid == 0)
- state->xid = (uint32_t)random();
+ state->xid = arc4random();
lease->server.s_addr = 0;
send_message(state, DHCP_REQUEST, options);
state->timeout = lease->leasetime - lease->rebindtime;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <unistd.h>
#include "common.h"
return last;
}
-/* OK, this should be in dhcpcd.c
- * It's here to make dhcpcd more readable */
-#if HAVE_SRANDOMDEV
-#else
-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
-
/* strlcpy is nice, shame glibc does not define it */
#if HAVE_STRLCPY
#else
#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");
}
- /* Seed random */
+#ifdef __GLIBC__
+ /* We need to seed random for our fake arc4random call */
srandomdev();
+#endif
#ifdef __linux__
/* Massage our filters per platform */