source: rtems/cpukit/pppd/magic.c @ df49c60

4.104.114.84.9
Last change on this file since df49c60 was d0950ad, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 30, 1999 at 10:12:50 PM

Added port of ppp-2.3.5 from Tomasz Domin <dot@…> of ComArch? SA.
Tomasz only tested this on the mpc823.

The official site for the original source for this PPP implementation is:

ftp://cs.anu.edu.au/pub/software/ppp

NOTE: As of 11/30/1999, the current version of this source is 2.3.10.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * magic.c - PPP Magic Number routines.
3 *
4 * Copyright (c) 1989 Carnegie Mellon University.
5 * All rights reserved.
6 *
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.
18 */
19
20#ifndef lint
21/* static char rcsid[] = "$Id$"; */
22#endif
23
24#include <stdio.h>
25#include <unistd.h>
26#include <stdlib.h>
27#include <sys/types.h>
28#include <sys/time.h>
29
30#include "pppd.h"
31#include "magic.h"
32
33extern long mrand48 __P((void));
34extern void srand48 __P((long));
35
36/*
37 * magic_init - Initialize the magic number generator.
38 *
39 * Attempts to compute a random number seed which will not repeat.
40 * The current method uses the current hostid, current process ID
41 * and current time, currently.
42 */
43void
44magic_init()
45{
46    long seed;
47    struct timeval t;
48
49    gettimeofday(&t, NULL);
50    seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
51    srand48(seed);
52}
53
54/*
55 * magic - Returns the next magic number.
56 */
57u_int32_t
58magic()
59{
60    return (u_int32_t) mrand48();
61}
62
63/*
64 * Substitute procedures for those systems which don't have
65 * drand48 et al.
66 */
67/* #include <stdlib.h> */
68double
69drand48()
70{
71    return (double)rand() / (double)0x7fffffffL; /* 2**31-1 */
72}
73
74long
75mrand48()
76{
77    return rand();
78}
79
80void
81srand48(seedval)
82long seedval;
83{
84    srand((int)seedval);
85}
86
Note: See TracBrowser for help on using the repository browser.