source: tags/greenstone-3_01-distribution/mgpp/lib/netorder.h@ 10896

Last change on this file since 10896 was 10896, checked in by (none), 18 years ago

This commit was manufactured by cvs2svn to create tag
'greenstone-3_01-distribution'.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1#ifndef NETORDER_H
2#define NETORDER_H
3
4#include "sysfuncs.h"
5
6/* [RPAP - Feb 97: WIN32 Port] */
7#ifdef __WIN32__
8#include "win32in.h"
9#else
10# include <netinet/in.h>
11#endif
12
13#ifndef WORDS_BIGENDIAN
14
15/* double */
16#define HTOND(d) \
17 do { \
18 unsigned long tmph, tmpl; \
19 memcpy ((void *) &tmph, (const void *) &d, sizeof(double) >> 1); \
20 memcpy ((void *) &tmpl, (const void *) ((unsigned int) &d + (sizeof(double) >> 1)), sizeof (double) >> 1); \
21 tmph = htonl (tmph); \
22 tmpl = htonl (tmpl); \
23 memcpy ( (void *) &d, (const void *) &tmpl, sizeof (double) >> 1); \
24 memcpy ((void *) ((unsigned int) &d + (sizeof(double) >> 1)), (const void *) &tmph, sizeof (double) >> 1); \
25 }while(0)
26#define NTOHD(d) \
27 do { \
28 unsigned long tmph, tmpl; \
29 memcpy ((void *) &tmph, (const void *) &d, sizeof(double) >> 1); \
30 memcpy ((void *) &tmpl, (const void *) ((int) &d + (sizeof(double) >> 1)), sizeof (double) >> 1); \
31 tmph = ntohl (tmph); \
32 tmpl = ntohl (tmpl); \
33 memcpy((void *) &d, (const void *) &tmpl, sizeof (double) >> 1); \
34 memcpy ((void *) ((int) &d + (sizeof(double) >> 1)), (const void *) &tmph, sizeof (double) >> 1); \
35 }while(0)
36#define HTOND2(hd, nd) \
37 do { \
38 unsigned long tmph, tmpl; \
39 memcpy ((void *) &tmph, (const void *) &hd, sizeof(double) >> 1);\
40 memcpy ((void *) &tmpl, (const void *) ((unsigned int) &hd + (sizeof(double) >> 1)), sizeof (double) >> 1); \
41 tmph = htonl (tmph); \
42 tmpl = htonl (tmpl); \
43 memcpy((void *) &nd, (const void *) &tmpl, sizeof (double) >> 1);\
44 memcpy ((void *) ((unsigned int) &nd + (sizeof(double) >> 1)), (void *) &tmph, sizeof (double) >> 1); \
45 }while(0)
46#define NTOHD2(nd, hd) \
47 do { \
48 unsigned long tmph, tmpl; \
49 memcpy ((void *) &nd, (void *) &tmph, sizeof(double) >> 1); \
50 memcpy ((void *) &tmpl, (const void *) &nd + (sizeof(double) >> 1), sizeof (double) >> 1); \
51 tmph = ntohl (tmph); \
52 tmpl = ntohl (tmpl); \
53 memcpy((void *) &hd, (const void *) &tmpl, sizeof (double) >> 1);\
54 memcpy ((void *) &hd + (sizeof(double) >> 1), (const void *) &tmph, sizeof (double) >> 1); \
55 }while(0)
56
57/* float */
58#define HTONF(f) \
59 do { \
60 unsigned long tmp; \
61 memcpy ((void *) &tmp, (const void *) &(f), sizeof (float)); \
62 HTONUL (tmp); \
63 memcpy ((void *) &(f), (const void *) &tmp, sizeof (float)); \
64 }while(0)
65#define NTOHF(f) \
66 do { \
67 unsigned long tmp; \
68 memcpy ((void *) &tmp, (const void *) &(f), sizeof (float)); \
69 NTOHUL (tmp); \
70 memcpy ((void *) &(f), (const void *) &tmp, sizeof (float)); \
71 }while(0)
72#define HTONF2(hf, nf) \
73 do { \
74 unsigned long tmp; \
75 memcpy ((void *) &tmp, (const void *) &(hf), sizeof (float)); \
76 HTONUL (tmp); \
77 memcpy ((void *) &(nf), (const void *) &tmp, sizeof (float)); \
78 }while(0)
79#define NTOHF2(nf, hf) \
80 do { \
81 unsigned long tmp; \
82 memcpy ((void *) &tmp, (const void *) &(nf), sizeof (float)); \
83 NTOHUL (tmp); \
84 memcpy ((void *) &(hf), (const void *) &tmp, sizeof (float)); \
85 }while(0)
86
87/* pointers */
88#define HTONP(p) ((p) = (void *) htonl ((unsigned long) p))
89#define NTOHP(p) ((p) = (void *) ntohl ((unsigned long) p))
90#define HTONP2(hp, np) ((np) = (void *) htonl ((unsigned long) hp))
91#define NTOHP2(np, hp) ((hp) = (void *) ntohl ((unsigned long) np))
92
93/* unsigned long */
94#define HTONUL(l) ((l) = htonl((l)))
95#define NTOHUL(l) ((l) = ntohl((l)))
96#define HTONUL2(hl, nl) ((nl) = htonl ((hl)))
97#define NTOHUL2(nl, hl) ((hl) = ntohl ((nl)))
98
99/* signed long */
100#define HTONSL(l) ((l) = (long) htonl ((unsigned long) (l)))
101#define NTOHSL(l) ((l) = (long) ntohl ((unsigned long) (l)))
102#define HTONSL2(hl, nl) ((nl) = (long) htonl ((unsigned long) (hl)))
103#define NTOHSL2(nl, hl) ((hl) = (long) ntohl ((unsigned long) (nl)))
104
105/* unsigned int */
106#define HTONUI(i) ((i) = (unsigned int) htonl ((unsigned long) (i)))
107#define NTOHUI(i) ((i) = (unsigned int) ntohl ((unsigned long) (i)))
108#define HTONUI2(hi, ni) ((ni) = (unsigned int) htonl ((unsigned long) (hi)))
109#define NTOHUI2(ni, hi) ((hi) = (unsigned int) ntohl ((unsigned long) (ni)))
110
111/* signed int */
112#define HTONSI(i) ((i) = (int) htonl ((unsigned long) (i)))
113#define NTOHSI(i) ((i) = (int) ntohl ((unsigned long) (i)))
114#define HTONSI2(hi, ni) ((ni) = (int) htonl ((unsigned long) (hi)))
115#define NTOHSI2(ni, hi) ((hi) = (int) ntohl ((unsigned long) (ni)))
116
117/* unsigned short */
118#define HTONUS(s) ((s) = htons((s)))
119#define NTOHUS(s) ((s) = ntohs((s)))
120#define HTONUS2(hs, ns) ((ns) = htons((hs)))
121#define NTOHUS2(ns, hs) ((hs) = ntohs((ns)))
122
123#else /* WORDS_BIGENDIAN */
124
125/* double */
126#define HTOND(d) (d)
127#define NTOHD(d) (d)
128#define HTOND2(hd, nd) ((hd) = (nd))
129#define NTOHD2(nd, hd) ((nd) = (hd))
130
131/* float */
132#define HTONF(f) (f)
133#define NTOHF(f) (f)
134#define HTONF2(hf, nf) ((nf) = (hf))
135#define NTOHF2(nf, hf) ((hf) = (nf))
136
137/* pointers */
138#define HTONP(p) (p)
139#define NTOHP(p) (p)
140#define HTONP2(hp, np) ((np) = (hp))
141#define NTOHP2(np, hp) ((hp) = (np))
142
143/* unsigned long */
144#define HTONUL(l) (l)
145#define NTOHUL(l) (l)
146#define HTONUL2(hl, nl) ((nl) = (hl))
147#define NTOHUL2(nl, hl) ((hl) = (nl))
148
149/* signed long */
150#define HTONSL(l) (l)
151#define NTOHSL(l) (l)
152#define HTONSL2(hl, nl) ((nl) = (hl))
153#define NTOHSL2(nl, hl) ((hl) = (nl))
154
155/* unsigned int */
156#define HTONUI(i) (i)
157#define NTOHUI(i) (i)
158#define HTONUI2(hi, ni) ((ni) = (hi))
159#define NTOHUI2(ni, hi) ((hi) = (ni))
160
161/* signed int */
162#define HTONSI(i) (i)
163#define NTOHSI(i) (i)
164#define HTONSI2(hi, ni) ((ni) = (hi))
165#define NTOHSI2(ni, hi) ((hi) = (ni))
166
167/* unsigned short */
168#define HTONUS(s) (s)
169#define NTOHUS(s) (s)
170#define HTONUS2(hs, ns) ((ns) = (hs))
171#define NTOHUS2(ns, hs) ((hs) = (ns))
172
173
174
175#endif
176
177#endif /* netorder.h */
Note: See TracBrowser for help on using the repository browser.