3 Byte-order invariant definitions
7 /* The following macros allow packing fields of various types
8 into a byte-oriented packet with a running pointer named
9 pktP. The reason we store then memcpy rather than storing
10 through a cast of pktP to the desired type is that the
11 latter approach can result in alignment faults when run
12 on RISC machines which typically require values to be
13 aligned at an even multiple of their length. */
15 #define packShort(x) { \
16 short s = htons((short) (x)); \
17 memcpy(pktP, &s, sizeof(short)); \
18 pktP += sizeof(short); \
21 #define packLong(x) { \
22 long l = htonl((long) (x)); \
23 memcpy(pktP, &l, sizeof(long)); \
24 pktP += sizeof(long); \
27 #define packByte(x) { \
29 memcpy(pktP, &c, sizeof(char)); \
30 pktP += sizeof(char); \
33 #define packBytes(x, n) { \
38 /* These macros unpack fields of various lengths from a
39 byte-packet packet in network byte order pointed to by
40 pktP. Note that the argument of these macros must be
43 #define unpackShort(x) { \
45 memcpy(&s, pktP, sizeof(short)); \
46 pktP += sizeof(short); \
50 #define unpackLong(x) { \
52 memcpy(&l, pktP, sizeof(long)); \
53 pktP += sizeof(long); \
57 #define unpackByte(x) { \
58 *((char *) &x) = (char) *pktP++; \
61 #define unpackBytes(x, n) { \