4 /* COM32 will be running on an i386 platform */
7 #include <klibc/compiler.h>
9 #define __htons_macro(v) ((uint16_t) \
10 (((uint16_t)(v) << 8) | \
11 ((uint16_t)(v) >> 8)))
13 static inline __constfunc
uint16_t __htons(uint16_t v
)
15 return __htons_macro(v
);
18 #define htons(x) (__builtin_constant_p(x) ? __htons_macro(x) : __htons(x))
19 #define ntohs(x) htons(x)
21 #define __htonl_macro(v) ((uint32_t) \
22 ((((uint32_t)(v) & 0x000000ff) << 24) | \
23 (((uint32_t)(v) & 0x0000ff00) << 8) | \
24 (((uint32_t)(v) & 0x00ff0000) >> 8) | \
25 (((uint32_t)(v) & 0xff000000) >> 24)))
27 static inline __constfunc
uint32_t __htonl(uint32_t v
)
29 asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
34 #define htonl(x) (__builtin_constant_p(x) ? __htonl_macro(x) : __htonl(x))
35 #define ntohl(x) htonl(x)
37 #define __htonq_macro(v) ((uint64_t) \
38 (((uint64_t)__htonl_macro((uint32_t)(v)) << 32) | \
39 (__htonl_macro((uint32_t)((uint64_t)(v) >> 32)))))
41 static inline __constfunc
uint64_t __htonq(uint64_t v
)
43 return ((uint64_t)__htonl(v
) << 32) | __htonl(v
>> 32);
46 #define htonq(x) (__builtin_constant_p(x) ? __htonq_macro(x) : __htonq(x))
47 #define ntohq(x) htonq(x)
49 typedef uint32_t in_addr_t
;
50 typedef uint16_t in_port_t
;
56 #endif /* _NETINET_IN_H */