2 * $Id: conv.c,v 0.0.0.1 2003/09/10
4 * DEBUG: section 7 ordering conversion
6 * -------------------------------------------------------------------
8 * Open Real-Time Ethernet
10 * Copyright (C) 2001-2006
11 * Department of Control Engineering FEE CTU Prague, Czech Republic
12 * http://dce.felk.cvut.cz
13 * http://www.ocera.org
15 * Author: Petr Smolik petr.smolik@wo.cz
17 * Project Responsible: Zdenek Hanzalek
18 * --------------------------------------------------------------------
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * This module maintains a hash table of key/value pairs.
31 * Keys can be strings of any size, or numbers up to size
32 * unsigned long (HASHKEYTYPE).
33 * Values should be a pointer to some data you wish to store.
39 /**********************************************************************************/
40 //get part of string, div. by semi.
42 getStringPart(char *string,char divChar,int *iterator,char *buff) {
46 if (!string || !buff) return -1;
48 if (len<(*iterator)) return -2;
49 cp=string+(*iterator);
50 if (cp[0]!=0) { //till is length>0
52 dcp=strchr(cp,divChar);
53 if (!dcp) dcp=cp+strlen(cp);
54 tcp=*dcp; //save ending value
55 *dcp=0; //temporary end of string
56 strcpy((char *)buff,cp);
57 *dcp=tcp; //restore value
58 if (dcp[0]!=0) (*iterator)+=dcp-cp+1;//next value
65 /**********************************************************************************/
67 IPAddressToString(IPAddress ipAddress,char *buff) {
70 addr.s_addr=htonl(ipAddress);
71 sprintf(buff,"%s",inet_ntoa(addr));
75 /**********************************************************************************/
77 StringToIPAddress(const char *string) {
78 IPAddress ipAddress=IPADDRESS_INVALID;
79 #ifdef CONFIG_ORTE_MINGW
80 unsigned long inetAddress = inet_addr(string);
82 in_addr_t inetAddress = inet_addr(string);
85 if(inetAddress!=INADDR_NONE) {
86 ipAddress=ntohl(inetAddress);
88 #if defined HAVE_GETHOSTBYNAME
90 struct hostent *hostname;
91 if (ipAddress==IPADDRESS_INVALID) {
92 if ((hostname=gethostbyname(string))) {
93 ipAddress=ntohl(*((long*)(hostname->h_addr_list[0])));
101 /**********************************************************************************/
103 NtpTimeToStringMs(NtpTime time,char *buff) {
106 NtpTimeDisAssembToMs(s, msec, time);
107 sprintf(buff,"%d.%03d",s,msec);
111 /**********************************************************************************/
113 NtpTimeToStringUs(NtpTime time,char *buff) {
116 NtpTimeDisAssembToUs(s, usec, time);
117 sprintf(buff,"%d.%06d",s,usec);