aboutsummaryrefslogtreecommitdiffstats
path: root/com32/include/netinet/in.h
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2011-04-09 23:00:14 -0700
committerEric W. Biederman <ebiederm@xmission.com>2011-04-12 14:40:54 -0700
commita8e782f8cefdf0311902ded3e67ab48cec892163 (patch)
treed9edad5adca6a8cffcf40229d4f55fbe7898b026 /com32/include/netinet/in.h
parent3d35705a06f04b3e08f701278cec648336233562 (diff)
downloadsyslinux-a8e782f8cefdf0311902ded3e67ab48cec892163.tar.gz
syslinux-a8e782f8cefdf0311902ded3e67ab48cec892163.tar.xz
syslinux-a8e782f8cefdf0311902ded3e67ab48cec892163.zip
core: factor out byteswap.h from netinet/in.h
This is a logical generalization, follows the precedent set by glibc and it will allow us to avoid problems with lwips definition of the network byte swap functions. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'com32/include/netinet/in.h')
-rw-r--r--com32/include/netinet/in.h48
1 files changed, 8 insertions, 40 deletions
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index ccf04750..70cdc932 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -5,46 +5,14 @@
#include <stdint.h>
#include <klibc/compiler.h>
-
-#define __htons_macro(v) ((uint16_t) \
- (((uint16_t)(v) << 8) | \
- ((uint16_t)(v) >> 8)))
-
-static inline __constfunc uint16_t __htons(uint16_t v)
-{
- return __htons_macro(v);
-}
-
-#define htons(x) (__builtin_constant_p(x) ? __htons_macro(x) : __htons(x))
-#define ntohs(x) htons(x)
-
-#define __htonl_macro(v) ((uint32_t) \
- ((((uint32_t)(v) & 0x000000ff) << 24) | \
- (((uint32_t)(v) & 0x0000ff00) << 8) | \
- (((uint32_t)(v) & 0x00ff0000) >> 8) | \
- (((uint32_t)(v) & 0xff000000) >> 24)))
-
-static inline __constfunc uint32_t __htonl(uint32_t v)
-{
- asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
- : "+q" (v));
- return v;
-}
-
-#define htonl(x) (__builtin_constant_p(x) ? __htonl_macro(x) : __htonl(x))
-#define ntohl(x) htonl(x)
-
-#define __htonq_macro(v) ((uint64_t) \
- (((uint64_t)__htonl_macro((uint32_t)(v)) << 32) | \
- (__htonl_macro((uint32_t)((uint64_t)(v) >> 32)))))
-
-static inline __constfunc uint64_t __htonq(uint64_t v)
-{
- return ((uint64_t)__htonl(v) << 32) | __htonl(v >> 32);
-}
-
-#define htonq(x) (__builtin_constant_p(x) ? __htonq_macro(x) : __htonq(x))
-#define ntohq(x) htonq(x)
+#include <byteswap.h>
+
+#define htons(x) bswap_16(x)
+#define ntohs(x) bswap_16(x)
+#define htonl(x) bswap_32(x)
+#define ntohl(x) bswap_32(x)
+#define htonq(x) bswap_64(x)
+#define ntohq(x) bswap_64(x)
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;