]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/magic.c
allow chars 0x20 - 0x3f to be escaped
[ppp.git] / pppd / magic.c
index 71647633d024a586dae624b4bfc59633693e2804..db48ee8c3f4081875b0aa291f042e4a73a787dd4 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: magic.c,v 1.3 1994/09/21 06:47:37 paulus Exp $";
+static char rcsid[] = "$Id: magic.c,v 1.7 1998/03/25 03:07:49 paulus Exp $";
 #endif
 
 #include <stdio.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/time.h>
 
 #include "pppd.h"
 #include "magic.h"
 
-static u_int32_t next;         /* Next value to return */
-
-extern u_int32_t gethostid __P((void));
-extern long random __P((void));
-extern void srandom __P((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;
-
-    next = gethostid();
-    if (gettimeofday(&tv, NULL)) {
-       perror("gettimeofday");
-       exit(1);
-    }
-    next ^= (u_int32_t) tv.tv_sec ^ (u_int32_t) tv.tv_usec;
+    long seed;
+    struct timeval t;
 
-    srandom((int) next);
+    gettimeofday(&t, NULL);
+    seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
+    srand48(seed);
 }
 
-
 /*
  * magic - Returns the next magic number.
  */
-u_int32_t magic()
+u_int32_t
+magic()
 {
-    u_int32_t m;
+    return (u_int32_t) mrand48();
+}
 
-    m = next;
-    next = (u_int32_t) random();
-    return (m);
+#ifdef NO_DRAND48
+/*
+ * Substitute procedures for those systems which don't have
+ * drand48 et al.
+ */
+
+double
+drand48()
+{
+    return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
 }
+
+long
+mrand48()
+{
+    return random();
+}
+
+void
+srand48(seedval)
+long seedval;
+{
+    srandom((int)seedval);
+}
+
+#endif