If arc4random is present it will be used over the srand/rand interface.
This fixes some warnings in OpenBSD-current.
# Optional functions
AC_CHECK_FUNCS_ONCE([ \
- gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
- snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r waitpid])
+ arc4random gai_strerror getaddrinfo getnameinfo inet_aton sigaction \
+ sigprocmask snprintf vsnprintf strdup strndup strlcpy strlcat strtok_r \
+ waitpid])
# -- Configuration options --
/* "Short" connection, enforce "ConnectRetry"
* but randomize it a little bit: 15 seconds. */
Conf_Server[i].lasttry =
+#ifdef HAVE_ARC4RANDOM
+ t + (arc4random() % 15);
+#else
t + rand() / (RAND_MAX / 15);
+#endif
}
}
}
#ifndef STRICT_RFC
if (Conf_AuthPing) {
+#ifdef HAVE_ARC4RANDOM
+ Conn_SetAuthPing(Client_Conn(Client), arc4random());
+#else
Conn_SetAuthPing(Client_Conn(Client), rand());
+#endif
IRC_WriteStrClient(Client, "PING :%ld",
Conn_GetAuthPing(Client_Conn(Client)));
LogDebug("Connection %d: sent AUTH PING %ld ...",
#endif
+#ifdef HAVE_ARC4RANDOM
+static void
+Random_Init(void)
+{
+
+}
+#else
static bool
Random_Init_Kern(const char *file)
{
return;
srand(rand() ^ (unsigned)getpid() ^ (unsigned)time(NULL));
}
+#endif
/**
Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short), int timeout)
{
pid_t pid;
+#ifndef HAVE_ARC4RANDOM
unsigned int seed;
+#endif
assert(proc != NULL);
assert(pipefds != NULL);
return -1;
}
+#ifndef HAVE_ARC4RANDOM
seed = (unsigned int)rand();
+#endif
pid = fork();
switch (pid) {
case -1:
return -1;
case 0:
/* New child process: */
+#ifndef HAVE_ARC4RANDOM
srand(seed ^ (unsigned int)time(NULL) ^ getpid());
+#endif
Signals_Exit();
signal(SIGTERM, Proc_GenericSignalHandler);
signal(SIGALRM, Proc_GenericSignalHandler);
assert(String != NULL);
gettimeofday(&t, NULL);
+#ifndef HAVE_ARC4RANDOM
srand((unsigned)(t.tv_usec * t.tv_sec));
for (i = 0; i < len; ++i) {
String[i] = chars[rand() % (sizeof(chars) - 1)];
}
+#else
+ for (i = 0; i < len; ++i)
+ String[i] = chars[arc4random() % (sizeof(chars) - 1)];
+#endif
String[len] = '\0';
return String;