]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/magic.c
support micro$oft DNS options;
[ppp.git] / pppd / magic.c
index 18c00bb2f9b8bbed21f3d387405a2b357c6bd4d0..4797f0b19fd636f09c357b786b3378c002519ebd 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: magic.c,v 1.2 1994/09/01 00:25:19 paulus Exp $";
+static char rcsid[] = "$Id: magic.c,v 1.5 1995/06/06 01:52:25 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -28,43 +28,63 @@ static char rcsid[] = "$Id: magic.c,v 1.2 1994/09/01 00:25:19 paulus Exp $";
 #include "pppd.h"
 #include "magic.h"
 
-static uint32 next;            /* Next value to return */
+static u_int32_t next;         /* Next value to return */
 
-extern uint32 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;
+    long seed;
+    struct timeval t;
 
-    next = gethostid();
-    if (gettimeofday(&tv, NULL)) {
-       perror("gettimeofday");
-       exit(1);
-    }
-    next ^= (uint32) tv.tv_sec ^ (uint32) 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.
  */
-uint32 magic()
+u_int32_t
+magic()
 {
-    uint32 m;
+    return (u_int32_t) mrand48();
+}
+
+#ifdef NO_DRAND48
+/*
+ * Substitute procedures for those systems which don't have
+ * drand48 et al.
+ */
 
-    m = next;
-    next = (uint32) random();
-    return (m);
+double
+drand48()
+{
+    return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
 }
+
+long
+mrand48()
+{
+    return random();
+}
+
+void
+srand48(seedval)
+long seedval;
+{
+    srandom((int)seedval);
+}
+
+#endif