X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmagic.c;h=9e95994953812e52dbeecd253f9bc23fbc08f26f;hp=20dfd6fe3a4823ee285fce41f89705ac35f3bddb;hb=289e4c84880ca19342a65ba5703d62b27dc69950;hpb=0b63a24d54ba4708c88e31bdd74b0145956c1478 diff --git a/pppd/magic.c b/pppd/magic.c index 20dfd6f..9e95994 100644 --- a/pppd/magic.c +++ b/pppd/magic.c @@ -18,53 +18,70 @@ */ #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.6 1996/04/04 03:58:41 paulus Exp $"; #endif #include +#include #include #include +#include "pppd.h" #include "magic.h" - -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 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; + long seed; + struct timeval t; - next = gethostid(); - if (gettimeofday(&tv, NULL)) { - perror("gettimeofday"); - exit(1); - } - next ^= (u_long) tv.tv_sec ^ (u_long) tv.tv_usec; - - 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() { - u_long m; + return (double)random() / (double)0x7fffffffL; /* 2**31-1 */ +} - m = next; - next = (u_long) random(); - return (m); +long +mrand48() +{ + return random(); } + +void +srand48(seedval) +long seedval; +{ + srandom((int)seedval); +} + +#endif