1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * magic.c - PPP Magic Number routines. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University. 5*7c478bd9Sstevel@tonic-gate * All rights reserved. 6*7c478bd9Sstevel@tonic-gate * 7*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 8*7c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 9*7c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 10*7c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 11*7c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 12*7c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the 13*7c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 14*7c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 15*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 16*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 17*7c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 18*7c478bd9Sstevel@tonic-gate */ 19*7c478bd9Sstevel@tonic-gate 20*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 21*7c478bd9Sstevel@tonic-gate #define RCSID "$Id: magic.c,v 1.9 1999/08/13 06:46:15 paulus Exp $" 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate #include <stdio.h> 24*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 25*7c478bd9Sstevel@tonic-gate #include <unistd.h> 26*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 27*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include "pppd.h" 30*7c478bd9Sstevel@tonic-gate #include "magic.h" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #if !defined(lint) && !defined(_lint) 33*7c478bd9Sstevel@tonic-gate static const char rcsid[] = RCSID; 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #ifdef NO_DRAND48 37*7c478bd9Sstevel@tonic-gate long mrand48 __P((void)); 38*7c478bd9Sstevel@tonic-gate void srand48 __P((long)); 39*7c478bd9Sstevel@tonic-gate #endif 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* 42*7c478bd9Sstevel@tonic-gate * magic_init - Initialize the magic number generator. 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * Attempts to compute a random number seed which will not repeat. 45*7c478bd9Sstevel@tonic-gate * The current method uses the current hostid, current process ID 46*7c478bd9Sstevel@tonic-gate * and current time, currently. 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate void 49*7c478bd9Sstevel@tonic-gate magic_init() 50*7c478bd9Sstevel@tonic-gate { 51*7c478bd9Sstevel@tonic-gate long seed; 52*7c478bd9Sstevel@tonic-gate struct timeval t; 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate (void) gettimeofday(&t, NULL); 55*7c478bd9Sstevel@tonic-gate seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid(); 56*7c478bd9Sstevel@tonic-gate srand48(seed); 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate /* 60*7c478bd9Sstevel@tonic-gate * magic - Returns the next magic number. 61*7c478bd9Sstevel@tonic-gate */ 62*7c478bd9Sstevel@tonic-gate u_int32_t 63*7c478bd9Sstevel@tonic-gate magic() 64*7c478bd9Sstevel@tonic-gate { 65*7c478bd9Sstevel@tonic-gate return (u_int32_t) mrand48(); 66*7c478bd9Sstevel@tonic-gate } 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate #ifdef NO_DRAND48 69*7c478bd9Sstevel@tonic-gate /* 70*7c478bd9Sstevel@tonic-gate * Substitute procedures for those systems which don't have 71*7c478bd9Sstevel@tonic-gate * drand48 et al. 72*7c478bd9Sstevel@tonic-gate */ 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate double 75*7c478bd9Sstevel@tonic-gate drand48() 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate return (double)random() / (double)0x7fffffffL; /* 2**31-1 */ 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate long 81*7c478bd9Sstevel@tonic-gate mrand48() 82*7c478bd9Sstevel@tonic-gate { 83*7c478bd9Sstevel@tonic-gate return random(); 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate void 87*7c478bd9Sstevel@tonic-gate srand48(seedval) 88*7c478bd9Sstevel@tonic-gate long seedval; 89*7c478bd9Sstevel@tonic-gate { 90*7c478bd9Sstevel@tonic-gate srandom((int)seedval); 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate #endif 94