OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [pppd/] [magic.c] - Blame information for rev 296

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: magic.c,v 1.2 2001-09-27 12:01:57 chris Exp $"; */
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
 
33
extern long mrand48 __P((void));
34
extern 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
 */
43
void
44
magic_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
 */
57
u_int32_t
58
magic()
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> */
68
double
69
drand48()
70
{
71
    return (double)rand() / (double)0x7fffffffL; /* 2**31-1 */
72
}
73
 
74
long
75
mrand48()
76
{
77
    return rand();
78
}
79
 
80
void
81
srand48(seedval)
82
long seedval;
83
{
84
    srand((int)seedval);
85
}
86
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.