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 void conv_u16(u_int16_t *x,char ef) {
32 if(ef) *x=bswap_16(*x);
34 if(!ef) *x=bswap_16(*x);
38 /**********************************************************************************/
39 void conv_u32(u_int32_t *x,char ef) {
41 if(ef) *x=bswap_32(*x);
43 if(!ef) *x=bswap_32(*x);
47 /**********************************************************************************/
48 void conv_sn(SequenceNumber *sn,char ef) {
51 sn->high=bswap_32(sn->high);
52 sn->low=bswap_32(sn->low);
56 sn->high=bswap_32(sn->high);
57 sn->low=bswap_32(sn->low);
62 /**********************************************************************************/
63 void conv_ntp(NtpTime *ntp,char ef) {
66 ntp->seconds=bswap_32(ntp->seconds);
67 ntp->fraction=bswap_32(ntp->fraction);
71 ntp->seconds=bswap_32(ntp->seconds);
72 ntp->fraction=bswap_32(ntp->fraction);
77 /**********************************************************************************/
79 IPAddressToString(IPAddress ipAddress,char *buff) {
82 addr.s_addr=htonl(ipAddress);
83 sprintf(buff,"%s",inet_ntoa(addr));
87 /**********************************************************************************/
89 StringToIPAddress(const char *string) {
90 return ntohl(inet_addr(string));
93 /**********************************************************************************/
95 NtpTimeToStringMs(NtpTime time,char *buff) {
98 NtpTimeDisAssembToMs(s, msec, time);
99 sprintf(buff,"%d.%03d",s,msec);
103 /**********************************************************************************/
105 NtpTimeToStringUs(NtpTime time,char *buff) {
108 NtpTimeDisAssembToUs(s, usec, time);
109 sprintf(buff,"%d.%06d",s,usec);