carp: add carp_group_demote_adj()
[dragonfly.git] / usr.sbin / pppd / magic.c
CommitLineData
984263bc
MD
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.
1de703da
MD
18 *
19 * $FreeBSD: src/usr.sbin/pppd/magic.c,v 1.8 1999/08/28 01:19:05 peter Exp $
21da1569 20 * $DragonFly: src/usr.sbin/pppd/magic.c,v 1.4 2005/11/24 23:42:54 swildner Exp $
984263bc
MD
21 */
22
984263bc
MD
23#include <stdio.h>
24#include <unistd.h>
25#include <sys/types.h>
26#include <sys/time.h>
27
28#include "pppd.h"
29#include "magic.h"
30
2d8a3be7
EN
31extern long mrand48(void);
32extern void srand48(long);
984263bc
MD
33
34/*
35 * magic_init - Initialize the magic number generator.
36 *
37 * Attempts to compute a random number seed which will not repeat.
38 * The current method uses the current hostid, current process ID
39 * and current time, currently.
40 */
41void
21da1569 42magic_init(void)
984263bc
MD
43{
44 long seed;
45 struct timeval t;
46
47 gettimeofday(&t, NULL);
48 seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
49 srand48(seed);
50}
51
52/*
53 * magic - Returns the next magic number.
54 */
55u_int32_t
21da1569 56magic(void)
984263bc
MD
57{
58 return (u_int32_t) mrand48();
59}
60
61#ifdef NO_DRAND48
62/*
63 * Substitute procedures for those systems which don't have
64 * drand48 et al.
65 */
66
67double
21da1569 68drand48(void)
984263bc
MD
69{
70 return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
71}
72
73long
21da1569 74mrand48(void)
984263bc
MD
75{
76 return random();
77}
78
79void
21da1569 80srand48(long seedval)
984263bc
MD
81{
82 srandom((int)seedval);
83}
84
85#endif