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