00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _NET__HTON_H
00009 #define _NET__HTON_H
00010
00011 #include <minix/sys_config.h>
00012
00013 extern u16_t _tmp;
00014 extern u32_t _tmp_l;
00015
00016
00017
00018
00019 #if (_MINIX_CHIP == 0)
00020 #include "_MINIX_CHIP macro not set, include <minix/config.h>"
00021 #endif
00022
00023 #if (_MINIX_CHIP == _CHIP_INTEL)
00024 #define LITTLE_ENDIAN 1
00025 #endif
00026
00027 #if (_MINIX_CHIP == _CHIP_M68000 || _MINIX_CHIP == _CHIP_SPARC)
00028 #define BIG_ENDIAN 1
00029 #endif
00030
00031 #if (LITTLE_ENDIAN) && (BIG_ENDIAN)
00032 #include "both LITTLE_ENDIAN and BIG_ENDIAN are defined"
00033 /* LITTLE_ENDIAN and BIG_ENDIAN are both defined */
00034 #endif
00035
00036 #if !(LITTLE_ENDIAN) && !(BIG_ENDIAN)
00037 #include "neither LITTLE_ENDIAN nor BIG_ENDIAN is defined"
00038 /* LITTLE_ENDIAN and BIG_ENDIAN are both NOT defined */
00039 #endif
00040
00041 #if LITTLE_ENDIAN
00042 #define HTONS(x) ( ( (((unsigned short)(x)) >>8) & 0xff) | \
00043 ((((unsigned short)(x)) & 0xff)<<8) )
00044 #define NTOHS(x) ( ( (((unsigned short)(x)) >>8) & 0xff) | \
00045 ((((unsigned short)(x)) & 0xff)<<8) )
00046 #define HTONL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
00047 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
00048 #define NTOHL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
00049 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
00050
00051 #if _WORD_SIZE > 2
00052 #define htons(x) (_tmp=(x), ((_tmp>>8) & 0xff) | ((_tmp<<8) & 0xff00))
00053 #define ntohs(x) (_tmp=(x), ((_tmp>>8) & 0xff) | ((_tmp<<8) & 0xff00))
00054 #define htonl(x) (_tmp_l=(x), ((_tmp_l>>24) & 0xffL) | \
00055 ((_tmp_l>>8) & 0xff00L) | \
00056 ((_tmp_l<<8) & 0xff0000L) | ((_tmp_l<<24) & 0xff000000L))
00057 #define ntohl(x) (_tmp_l=(x), ((_tmp_l>>24) & 0xffL) \
00058 | ((_tmp_l>>8) & 0xff00L) | \
00059 ((_tmp_l<<8) & 0xff0000L) | ((_tmp_l<<24) & 0xff000000L))
00060
00061 #else /* _WORD_SIZE == 2 */
00062 /* The above macros are too unwieldy for a 16-bit machine. */
00063 u16_t htons(u16_t x);
00064 u16_t ntohs(u16_t x);
00065 u32_t htonl(u32_t x);
00066 u32_t ntohl(u32_t x);
00067 #endif /* _WORD_SIZE == 2 */
00068
00069 #endif /* LITTLE_ENDIAN */
00070
00071 #if BIG_ENDIAN
00072 #define htons(x) (x)
00073 #define HTONS(x) (x)
00074 #define ntohs(x) (x)
00075 #define NTOHS(x) (x)
00076 #define htonl(x) (x)
00077 #define HTONL(x) (x)
00078 #define ntohl(x) (x)
00079 #define NTOHL(x) (x)
00080 #endif /* BIG_ENDIAN */
00081
00082 #endif /* _NET__HTON_H */