summaryrefslogtreecommitdiff
path: root/lib/common/Box.h
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-12-21 00:23:10 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-12-21 00:23:10 +0000
commitf732f2a0982c6c14adedcdc5702b1c85add171ac (patch)
tree593d60dd2c1ee36f19011b7b2da46938a0fbc753 /lib/common/Box.h
parent94095739a2339f43ae376a59f560c1f14b8789a6 (diff)
Allow use of native 64 bit endian swapping functions
Diffstat (limited to 'lib/common/Box.h')
-rw-r--r--lib/common/Box.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/common/Box.h b/lib/common/Box.h
index 4a76e74e..326bed38 100644
--- a/lib/common/Box.h
+++ b/lib/common/Box.h
@@ -114,6 +114,10 @@
// extra macros for converting to network byte order
+#ifdef HAVE_NETINET_IN_H
+ #include <netinet/in.h>
+#endif
+
// Always define a swap64 function, as it's useful.
inline uint64_t box_swap64(uint64_t x)
{
@@ -131,12 +135,18 @@ inline uint64_t box_swap64(uint64_t x)
#define box_hton64(x) (x)
#define box_ntoh64(x) (x)
#else
- #define box_hton64(x) box_swap64(x)
- #define box_ntoh64(x) box_swap64(x)
-#endif
-
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
+ #ifdef HAVE_SYS_ENDIAN_H
+ #include <sys/endian.h>
+ #define box_hton64(x) htobe64(x)
+ #define box_ntoh64(x) betoh64(x)
+ #elif HAVE_ASM_BYTEORDER_H
+ #include <asm/byteorder.h>
+ #define box_hton64(x) __cpu_to_be64(x)
+ #define box_ntoh64(x) __be64_to_cpu(x)
+ #else
+ #define box_hton64(x) box_swap64(x)
+ #define box_ntoh64(x) box_swap64(x)
+ #endif
#endif
#endif // BOX__H