2 * $Id: conv.c,v 0.0.0.1 2003/09/10
4 * DEBUG: section 7 ordering conversion
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * This module maintains a hash table of key/value pairs.
21 * Keys can be strings of any size, or numbers up to size
22 * unsigned long (HASHKEYTYPE).
23 * Values should be a pointer to some data you wish to store.
29 /**********************************************************************************/
30 //get part of string, div. by semi.
32 getStringPart(char *string,char divChar,int *iterator,char *buff) {
36 if (!string || !buff) return -1;
38 if (len<(*iterator)) return -2;
39 cp=string+(*iterator);
40 if (cp[0]!=0) { //till is length>0
42 dcp=strchr(cp,divChar);
43 if (!dcp) dcp=cp+strlen(cp);
44 tcp=*dcp; //save ending value
45 *dcp=0; //temporary end of string
47 *dcp=tcp; //restore value
48 if (dcp[0]!=0) (*iterator)+=dcp-cp+1;//next value
55 /**********************************************************************************/
57 IPAddressToString(IPAddress ipAddress,char *buff) {
60 addr.s_addr=htonl(ipAddress);
61 sprintf(buff,"%s",inet_ntoa(addr));
65 /**********************************************************************************/
67 StringToIPAddress(const char *string) {
68 IPAddress ipAddress=IPADDRESS_INVALID;
70 ipAddress=ntohl(inet_addr(string));
71 #if defined HAVE_GETHOSTBYNAME
73 struct hostent *hostname;
75 if ((hostname=gethostbyname(string))) {
76 ipAddress=ntohl(*((long*)(hostname->h_addr_list[0])));
84 /**********************************************************************************/
86 NtpTimeToStringMs(NtpTime time,char *buff) {
89 NtpTimeDisAssembToMs(s, msec, time);
90 sprintf(buff,"%d.%03d",s,msec);
94 /**********************************************************************************/
96 NtpTimeToStringUs(NtpTime time,char *buff) {
99 NtpTimeDisAssembToUs(s, usec, time);
100 sprintf(buff,"%d.%06d",s,usec);