2 The following macro definitions convert to and from the network standard byte
3 order. The macros with their name in lower case guarantee to evaluate their
4 argument exactly once. The function of the macros is encoded in their names;
5 htons means convert a (unsigned) short in host byte order to network byte order.
11 #include <minix/sys_config.h>
16 /* Find out about the byte order. */
18 /* assume <minix/config.h> is included, let's check */
19 #if (_MINIX_CHIP == 0)
20 #include "_MINIX_CHIP macro not set, include <minix/config.h>"
23 #if (_MINIX_CHIP == _CHIP_INTEL)
24 #define LITTLE_ENDIAN 1
27 #if (_MINIX_CHIP == _CHIP_M68000 || _MINIX_CHIP == _CHIP_SPARC)
31 #if (LITTLE_ENDIAN) && (BIG_ENDIAN)
32 #include "both LITTLE_ENDIAN and BIG_ENDIAN are defined"
33 /* LITTLE_ENDIAN and BIG_ENDIAN are both defined */
36 #if !(LITTLE_ENDIAN) && !(BIG_ENDIAN)
37 #include "neither LITTLE_ENDIAN nor BIG_ENDIAN is defined"
38 /* LITTLE_ENDIAN and BIG_ENDIAN are both NOT defined */
42 #define HTONS(x) ( ( (((unsigned short)(x)) >>8) & 0xff) | \
43 ((((unsigned short)(x)) & 0xff)<<8) )
44 #define NTOHS(x) ( ( (((unsigned short)(x)) >>8) & 0xff) | \
45 ((((unsigned short)(x)) & 0xff)<<8) )
46 #define HTONL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
47 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
48 #define NTOHL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
49 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
52 #define htons(x) (_tmp=(x), ((_tmp>>8) & 0xff) | ((_tmp<<8) & 0xff00))
53 #define ntohs(x) (_tmp=(x), ((_tmp>>8) & 0xff) | ((_tmp<<8) & 0xff00))
54 #define htonl(x) (_tmp_l=(x), ((_tmp_l>>24) & 0xffL) | \
55 ((_tmp_l>>8) & 0xff00L) | \
56 ((_tmp_l<<8) & 0xff0000L) | ((_tmp_l<<24) & 0xff000000L))
57 #define ntohl(x) (_tmp_l=(x), ((_tmp_l>>24) & 0xffL) \
58 | ((_tmp_l>>8) & 0xff00L) | \
59 ((_tmp_l<<8) & 0xff0000L) | ((_tmp_l<<24) & 0xff000000L))
61 #else /* _WORD_SIZE == 2 */
62 /* The above macros are too unwieldy for a 16-bit machine. */
67 #endif /* _WORD_SIZE == 2 */
69 #endif /* LITTLE_ENDIAN */
80 #endif /* BIG_ENDIAN */
82 #endif /* _NET__HTON_H */