4 /* COM32 will be running on an i386 platform */
7 #include <klibc/compiler.h>
8 #include <klibc/extern.h>
10 #define __htons_macro(v) ((uint16_t) \
11 (((uint16_t)(v) << 8) | \
12 ((uint16_t)(v) >> 8)))
14 static inline __constfunc
uint16_t __htons(uint16_t v
)
16 return __htons_macro(v
);
19 #define htons(x) (__builtin_constant_p(x) ? __htons_macro(x) : __htons(x))
20 #define ntohs(x) htons(x)
22 #define __htonl_macro(v) ((uint32_t) \
23 ((((uint32_t)(v) & 0x000000ff) << 24) | \
24 (((uint32_t)(v) & 0x0000ff00) << 8) | \
25 (((uint32_t)(v) & 0x00ff0000) >> 8) | \
26 (((uint32_t)(v) & 0xff000000) >> 24)))
28 static inline __constfunc
uint32_t __htonl(uint32_t v
)
30 asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
35 #define htonl(x) (__builtin_constant_p(x) ? __htonl_macro(x) : __htonl(x))
36 #define ntohl(x) htonl(x)
38 #define __htonq_macro(v) ((uint64_t) \
39 (((uint64_t)__htonl_macro((uint32_t)(v)) << 32) | \
40 (__htonl_macro((uint32_t)((uint64_t)(v) >> 32)))))
42 static inline __constfunc
uint64_t __htonq(uint64_t v
)
44 return ((uint64_t)__htonl(v
) << 32) | __htonl(v
>> 32);
47 #define htonq(x) (__builtin_constant_p(x) ? __htonq_macro(x) : __htonq(x))
48 #define ntohq(x) htonq(x)
50 typedef uint32_t in_addr_t
;
51 typedef uint16_t in_port_t
;
57 __extern
char *inet_ntoa(struct in_addr
);
59 #endif /* _NETINET_IN_H */