source: rtems-libbsd/rtemsbsd/pppd/magic.c @ 70fa95a

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 70fa95a was 70fa95a, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 30, 2014 at 12:46:12 PM

ppp: Import from RTEMS sources

  • Property mode set to 100644
File size: 1.5 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#define RCSID   "$Id$"
21
22#include <stdio.h>
23#include <stdlib.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
31static const char rcsid[] = RCSID;
32
33/*
34 * magic_init - Initialize the magic number generator.
35 *
36 * Attempts to compute a random number seed which will not repeat.
37 * The current method uses the current hostid, current process ID
38 * and current time, currently.
39 */
40void
41magic_init(void)
42{
43    long seed;
44    struct timeval t;
45
46    gettimeofday(&t, NULL);
47    seed = get_host_seed() ^ t.tv_sec ^ t.tv_usec ^ getpid();
48    srand48(seed);
49}
50
51/*
52 * magic - Returns the next magic number.
53 */
54uint32_t
55magic(void)
56{
57    return (uint32_t) mrand48();
58}
Note: See TracBrowser for help on using the repository browser.