Use arc4random_buf(). While there, unifdef the code for HAVE_ARC4RANDOM.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2015-08-16 23:23:58 +00:00
parent 7c669ab6cc
commit 1ae1bd497f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286834
2 changed files with 2 additions and 16 deletions

View File

@ -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

View File

@ -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,