diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | lib/common/Box.h | 22 |
2 files changed, 17 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index ba6636bb..e978f673 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,7 @@ AC_HEADER_DIRENT AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([execinfo.h netinet/in.h regex.h sys/types.h sys/xattr.h]) +AC_CHECK_HEADERS([sys/endian.h asm/byteorder.h]) ### Checks for typedefs, structures, and compiler characteristics. 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 |