Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / cmd-inet / usr.bin / pppd / magic.c
blob0fa15f207307ff237cdc986e34292e123c310394
1 /*
2 * magic.c - PPP Magic Number routines.
4 * Copyright (c) 1989 Carnegie Mellon University.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <sys/types.h>
24 #include <sys/time.h>
26 #include "pppd.h"
27 #include "magic.h"
29 #ifdef NO_DRAND48
30 long mrand48 __P((void));
31 void srand48 __P((long));
32 #endif
35 * magic_init - Initialize the magic number generator.
37 * Attempts to compute a random number seed which will not repeat.
38 * The current method uses the current hostid, current process ID
39 * and current time, currently.
41 void
42 magic_init()
44 long seed;
45 struct timeval t;
47 (void) gettimeofday(&t, NULL);
48 seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
49 srand48(seed);
53 * magic - Returns the next magic number.
55 u_int32_t
56 magic()
58 return (u_int32_t) mrand48();
61 #ifdef NO_DRAND48
63 * Substitute procedures for those systems which don't have
64 * drand48 et al.
67 double
68 drand48()
70 return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
73 long
74 mrand48()
76 return random();
79 void
80 srand48(seedval)
81 long seedval;
83 srandom((int)seedval);
86 #endif