diff options
author | peter <peter@FreeBSD.org> | 1995-10-31 21:21:51 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1995-10-31 21:21:51 +0000 |
commit | 9fba2426b57d3eedd0717a9ebbbfcd4377a3fae5 (patch) | |
tree | 4d3d1e7e23ca53f41a20a9c41f78068854a5325f /usr.sbin/pppd/magic.c | |
parent | 583ff5b6cdf30f69dbefba600748f3d4c9d15de4 (diff) | |
download | FreeBSD-src-9fba2426b57d3eedd0717a9ebbbfcd4377a3fae5.zip FreeBSD-src-9fba2426b57d3eedd0717a9ebbbfcd4377a3fae5.tar.gz |
Bring pppd from ppp-2.2 onto the mainline..
(more work needs to be done here, I'm trying to beat the supscan)
Diffstat (limited to 'usr.sbin/pppd/magic.c')
-rw-r--r-- | usr.sbin/pppd/magic.c | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/usr.sbin/pppd/magic.c b/usr.sbin/pppd/magic.c index 20dfd6f..4797f0b 100644 --- a/usr.sbin/pppd/magic.c +++ b/usr.sbin/pppd/magic.c @@ -18,53 +18,73 @@ */ #ifndef lint -static char rcsid[] = "$Id: magic.c,v 1.1 1993/11/11 03:54:25 paulus Exp $"; +static char rcsid[] = "$Id: magic.c,v 1.5 1995/06/06 01:52:25 paulus Exp $"; #endif #include <stdio.h> #include <sys/types.h> #include <sys/time.h> +#include "pppd.h" #include "magic.h" +static u_int32_t next; /* Next value to return */ -static u_long next; /* Next value to return */ - -extern u_long gethostid __ARGS((void)); -extern long random __ARGS((void)); -extern void srandom __ARGS((int)); +extern int gethostid __P((void)); +extern long mrand48 __P((void)); +extern void srand48 __P((long)); /* * magic_init - Initialize the magic number generator. * - * Computes first magic number and seed for random number generator. * Attempts to compute a random number seed which will not repeat. - * The current method uses the current hostid and current time. + * The current method uses the current hostid, current process ID + * and current time, currently. */ -void magic_init() +void +magic_init() { - struct timeval tv; - - next = gethostid(); - if (gettimeofday(&tv, NULL)) { - perror("gettimeofday"); - exit(1); - } - next ^= (u_long) tv.tv_sec ^ (u_long) tv.tv_usec; + long seed; + struct timeval t; - srandom((int) next); + gettimeofday(&t, NULL); + seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid(); + srand48(seed); } - /* * magic - Returns the next magic number. */ -u_long magic() +u_int32_t +magic() +{ + return (u_int32_t) mrand48(); +} + +#ifdef NO_DRAND48 +/* + * Substitute procedures for those systems which don't have + * drand48 et al. + */ + +double +drand48() +{ + return (double)random() / (double)0x7fffffffL; /* 2**31-1 */ +} + +long +mrand48() { - u_long m; + return random(); +} - m = next; - next = (u_long) random(); - return (m); +void +srand48(seedval) +long seedval; +{ + srandom((int)seedval); } + +#endif |