8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / pppd / magic.c
blob09d5086dfe221ee4d8266ce003267183a79c805f
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 #pragma ident "%Z%%M% %I% %E% SMI"
21 #define RCSID "$Id: magic.c,v 1.9 1999/08/13 06:46:15 paulus Exp $"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/time.h>
29 #include "pppd.h"
30 #include "magic.h"
32 #if !defined(lint) && !defined(_lint)
33 static const char rcsid[] = RCSID;
34 #endif
36 #ifdef NO_DRAND48
37 long mrand48 __P((void));
38 void srand48 __P((long));
39 #endif
42 * magic_init - Initialize the magic number generator.
44 * Attempts to compute a random number seed which will not repeat.
45 * The current method uses the current hostid, current process ID
46 * and current time, currently.
48 void
49 magic_init()
51 long seed;
52 struct timeval t;
54 (void) gettimeofday(&t, NULL);
55 seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
56 srand48(seed);
60 * magic - Returns the next magic number.
62 u_int32_t
63 magic()
65 return (u_int32_t) mrand48();
68 #ifdef NO_DRAND48
70 * Substitute procedures for those systems which don't have
71 * drand48 et al.
74 double
75 drand48()
77 return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
80 long
81 mrand48()
83 return random();
86 void
87 srand48(seedval)
88 long seedval;
90 srandom((int)seedval);
93 #endif