# Check headers.
AC_CHECK_HEADERS([ \
arpa/nameser_compat.h \
+ bsd/stdlib.h \
curses.h \
cursesX.h \
error.h \
__fpending \
fcntl \
])
+AC_SEARCH_LIBS([arc4random_uniform], [bsd],
+ [AC_DEFINE([HAVE_ARC4RANDOM_UNIFORM], [1],
+ [Define to 1 if arc4random_uniform is available.])])
AC_CHECK_FUNC([error], [with_error=no],
[AC_CHECK_FUNCS([verr verrx vwarn vwarnx], [with_error=yes],
#include <sys/select.h>
#include <unistd.h>
+#if defined(HAVE_ARC4RANDOM_UNIFORM) && defined(HAVE_BSD_STDLIB_H)
+#include <bsd/stdlib.h>
+#endif
+
#ifdef HAVE_ERROR_H
#include <error.h>
#else
static int packetsize; /* packet size used by ping */
+static int random_uniform(
+ int upper_bound)
+{
+#ifdef HAVE_ARC4RANDOM_UNIFORM
+ return (int) arc4random_uniform((unsigned int) upper_bound);
+#else
+ return rand() % upper_bound;
+#endif
+}
+
struct nethost {
ip_t addr; /* Latest host to respond */
ip_t addrs[MAX_PATH]; /* For Multi paths/Path Changes: List of all hosts that have responded */
packetsize = MINPACKET;
} else {
packetsize =
- MINPACKET + rand() % (-ctl->cpacketsize - MINPACKET);
+ MINPACKET + random_uniform(-ctl->cpacketsize - MINPACKET);
}
} else {
packetsize = ctl->cpacketsize;
}
if (ctl->bitpattern < 0) {
ctl->bitpattern =
- -(int) (256 + 255 * (rand() / (RAND_MAX + 0.1)));
+ -(256 + random_uniform(256));
}
}