svn commit: r286834 - head/sbin/ping6

Xin LI delphij at FreeBSD.org
Sun Aug 16 23:24:00 UTC 2015


Author: delphij
Date: Sun Aug 16 23:23:58 2015
New Revision: 286834
URL: https://svnweb.freebsd.org/changeset/base/286834

Log:
  Use arc4random_buf().  While there, unifdef the code for HAVE_ARC4RANDOM.
  
  MFC after:	2 weeks

Modified:
  head/sbin/ping6/Makefile
  head/sbin/ping6/ping6.c

Modified: head/sbin/ping6/Makefile
==============================================================================
--- head/sbin/ping6/Makefile	Sun Aug 16 20:13:58 2015	(r286833)
+++ head/sbin/ping6/Makefile	Sun Aug 16 23:23:58 2015	(r286834)
@@ -3,8 +3,7 @@
 PROG=	ping6
 MAN=	ping6.8
 
-CFLAGS+=-DIPSEC -DKAME_SCOPEID -DUSE_RFC2292BIS \
-	-DHAVE_ARC4RANDOM
+CFLAGS+=-DIPSEC -DKAME_SCOPEID -DUSE_RFC2292BIS
 WARNS?=	3
 
 BINOWN=	root

Modified: head/sbin/ping6/ping6.c
==============================================================================
--- head/sbin/ping6/ping6.c	Sun Aug 16 20:13:58 2015	(r286833)
+++ head/sbin/ping6/ping6.c	Sun Aug 16 23:23:58 2015	(r286834)
@@ -288,9 +288,6 @@ main(int argc, char *argv[])
 {
 	struct timeval last, intvl;
 	struct sockaddr_in6 from, *sin6;
-#ifndef HAVE_ARC4RANDOM
-	struct timeval seed;
-#endif
 	struct addrinfo hints, *res;
 	struct sigaction si_sa;
 	int cc, i;
@@ -751,17 +748,7 @@ main(int argc, char *argv[])
 			*datap++ = i;
 
 	ident = getpid() & 0xFFFF;
-#ifndef HAVE_ARC4RANDOM
-	gettimeofday(&seed, NULL);
-	srand((unsigned int)(seed.tv_sec ^ seed.tv_usec ^ (long)ident));
-	memset(nonce, 0, sizeof(nonce));
-	for (i = 0; i < sizeof(nonce); i += sizeof(int))
-		*((int *)&nonce[i]) = rand();
-#else
-	memset(nonce, 0, sizeof(nonce));
-	for (i = 0; i < (int)sizeof(nonce); i += sizeof(u_int32_t))
-		*((u_int32_t *)&nonce[i]) = arc4random();
-#endif
+	arc4random_buf(nonce, sizeof(nonce));
 	optval = 1;
 	if (options & F_DONTFRAG)
 		if (setsockopt(s, IPPROTO_IPV6, IPV6_DONTFRAG,


More information about the svn-src-all mailing list