Debian Codegraph @

pppd/plugins/radius/util.c

raw
1 /*
2 * Copyright (C) 1995,1996,1997 Lars Fenneberg
3 *
4 * Copyright 1992 Livingston Enterprises, Inc.
5 *
6 * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan
7 * and Merit Network, Inc. All Rights Reserved
8 *
9 * See the file COPYRIGHT for the respective terms and conditions.
10 * If the file is missing contact me at [email protected]
11 * and I'll send you a copy.
12 *
13 */
14
15 #include <includes.h>
16 #include <radiusclient.h>
17
18 /*
19 * Function: rc_str2tm
20 *
21 * Purpose: Turns printable string into correct tm struct entries.
22 *
23 */
24
25 static const char * months[] =
26 {
27 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
28 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
29 };
30
31 void rc_str2tm (char *valstr, struct tm *tm)
32 {
33 int i;
34
35 /* Get the month */
36 for (i = 0; i < 12; i++)
37 {
38 if (strncmp (months[i], valstr, 3) == 0)
39 {
40 tm->tm_mon = i;
41 i = 13;
42 }
43 }
44
45 /* Get the Day */
46 tm->tm_mday = atoi (&valstr[4]);
47
48 /* Now the year */
49 tm->tm_year = atoi (&valstr[7]) - 1900;
50 }
51
52 void rc_mdelay(int msecs)
53 {
54 struct timeval tv;
55
56 tv.tv_sec = (int) msecs / 1000;
57 tv.tv_usec = (msecs % 1000) * 1000;
58
59 select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL, &tv);
60 }
61
62 /*
63 * Function: rc_mksid
64 *
65 * Purpose: generate a quite unique string
66 *
67 * Remarks: not that unique at all...
68 *
69 */
70
71 char *
72 rc_mksid (void)
73 {
74 static char buf[32];
75 static unsigned short int cnt = 0;
76 snprintf(buf, sizeof(buf), "%08lX%04X%02hX",
77 (unsigned long int) time (NULL),
78 (unsigned int) getpid (),
79 (unsigned short) (cnt & 0xFF));
80 cnt++;
81 return buf;
82 }