]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/conv.c
Added prerelease of ORTE-0.2 (Real Time Publisher Subscriber communication protocol...
[orte.git] / orte / liborte / conv.c
1 /*
2  *  $Id: conv.c,v 0.0.0.1               2003/09/10
3  *
4  *  DEBUG:  section 7                 ordering conversion
5  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
6  *
7  *  ORTE - OCERA Real-Time Ethernet     http://www.ocera.org/
8  *  --------------------------------------------------------------------
9  *
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.
14  *
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.
19  *
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.
24  *
25  */
26
27 #include "orte.h"
28
29 /**********************************************************************************/
30 void conv_u16(u_int16_t *x,char ef) {
31   #if WORDS_BIGENDIAN
32      if(ef) *x=bswap_16(*x);
33   #else
34      if(!ef) *x=bswap_16(*x);
35   #endif
36 }
37
38 /**********************************************************************************/
39 void conv_u32(u_int32_t *x,char ef) {
40   #if WORDS_BIGENDIAN
41      if(ef) *x=bswap_32(*x);
42   #else
43      if(!ef) *x=bswap_32(*x);
44   #endif
45 }
46
47 /**********************************************************************************/
48 void conv_sn(SequenceNumber *sn,char ef) {
49   #if WORDS_BIGENDIAN
50      if(ef) {
51        sn->high=bswap_32(sn->high);
52        sn->low=bswap_32(sn->low);
53      }  
54   #else
55      if(!ef) {
56        sn->high=bswap_32(sn->high);
57        sn->low=bswap_32(sn->low);
58      }  
59   #endif
60 }
61
62 /**********************************************************************************/
63 void conv_ntp(NtpTime *ntp,char ef) {
64   #if WORDS_BIGENDIAN
65      if(ef) {
66        ntp->seconds=bswap_32(ntp->seconds);
67        ntp->fraction=bswap_32(ntp->fraction);
68      }  
69   #else
70      if(!ef) {
71        ntp->seconds=bswap_32(ntp->seconds);
72        ntp->fraction=bswap_32(ntp->fraction);
73      }  
74   #endif
75 }
76
77 /**********************************************************************************/
78 char* 
79 IPAddressToString(IPAddress ipAddress) {
80   struct in_addr addr;
81   static char result[MAX_STRING_IPADDRESS_LENGTH];
82   
83   addr.s_addr=htonl(ipAddress);
84   sprintf(result,"%s",inet_ntoa(addr));
85   return result;
86 }
87
88 /**********************************************************************************/
89 IPAddress 
90 StringToIPAddress(const char *string) {
91   return ntohl(inet_addr((char *)string));
92 }