Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 May 2016 06:06:22 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299845 - head/sbin/routed
Message-ID:  <201605150606.u4F66MLv007498@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sun May 15 06:06:22 2016
New Revision: 299845
URL: https://svnweb.freebsd.org/changeset/base/299845

Log:
  routed(8): Use arc4random_uniform instead of arc4random.
  
  Use arc4random_uniform() when the desired random number upper bound
  is not a power of two.
  
  While here, we don't need srandom() and friends anymore.
  
  Obtained from:	OpenBSD (CVS rev. 1.20)

Modified:
  head/sbin/routed/main.c

Modified: head/sbin/routed/main.c
==============================================================================
--- head/sbin/routed/main.c	Sun May 15 06:00:13 2016	(r299844)
+++ head/sbin/routed/main.c	Sun May 15 06:06:22 2016	(r299845)
@@ -303,11 +303,6 @@ usage:
 	pidfile(0);
 #endif
 	mypid = getpid();
-#ifdef __FreeBSD__
-	srandomdev();
-#else
-	srandom((int)(clk.tv_sec ^ clk.tv_usec ^ mypid));
-#endif
 
 	/* prepare socket connected to the kernel.
 	 */
@@ -826,8 +821,8 @@ intvl_random(struct timeval *tp,	/* put 
 {
 	tp->tv_sec = (time_t)(hi == lo
 			      ? lo
-			      : (lo + arc4random() % ((hi - lo))));
-	tp->tv_usec = arc4random() % 1000000;
+			      : (lo + arc4random_uniform(1 + hi - lo)));
+	tp->tv_usec = arc4random_uniform(1000000);
 }
 
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605150606.u4F66MLv007498>