From eb9a2c07c3cc3d9e555dbf8a0ab807c50324d071 Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Mon, 5 Jan 2015 10:42:09 -0800 Subject: [PATCH] Unbreak master builds on CentOS 5. The problem is that the new byte-ordering macros adopted on master don't support CentOS 5 because they assumed that any Linux system had endian(3) support. CentOS 6 (and presumably newer) do, but CentOS 5 doesn't. So instead we only do glibc endian(3) support if we're on a system with glibc 2.9 or higher (which is when this functionality was introduced). For any other platform that we don't detect (which now includes older glibc such as CentOS 5), bring back our homebrewed htonll and ntohll implementation from iperf 3.0.x. Fixes #224. --- src/portable_endian.h | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/portable_endian.h b/src/portable_endian.h index c7cb852..05f8861 100644 --- a/src/portable_endian.h +++ b/src/portable_endian.h @@ -10,7 +10,15 @@ #endif -#if defined(__linux__) || defined(__CYGWIN__) +// GLIBC / Linux with endian(3) support, which was added in glibc 2.9. +// Intended to support CentOS 6 and newer. +#if defined(__linux__) && \ + ((__GLIBC__ > 3) || \ + (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9)) + +# include + +#elif defined(__CYGWIN__) # include @@ -117,8 +125,38 @@ #else +// Unsupported platforms. +// Intended to support CentOS 5 but hopefully not too far from +// the truth because we use the homebrew htonll, et al. implementations +// that were originally the sole implementation of this functionality +// in iperf 3.0. # warning platform not supported -# include +# include +#if BYTE_ORDER == BIG_ENDIAN +#define HTONLL(n) (n) +#define NTOHLL(n) (n) +#else +#define HTONLL(n) ((((unsigned long long)(n) & 0xFF) << 56) | \ + (((unsigned long long)(n) & 0xFF00) << 40) | \ + (((unsigned long long)(n) & 0xFF0000) << 24) | \ + (((unsigned long long)(n) & 0xFF000000) << 8) | \ + (((unsigned long long)(n) & 0xFF00000000) >> 8) | \ + (((unsigned long long)(n) & 0xFF0000000000) >> 24) | \ + (((unsigned long long)(n) & 0xFF000000000000) >> 40) | \ + (((unsigned long long)(n) & 0xFF00000000000000) >> 56)) + +#define NTOHLL(n) ((((unsigned long long)(n) & 0xFF) << 56) | \ + (((unsigned long long)(n) & 0xFF00) << 40) | \ + (((unsigned long long)(n) & 0xFF0000) << 24) | \ + (((unsigned long long)(n) & 0xFF000000) << 8) | \ + (((unsigned long long)(n) & 0xFF00000000) >> 8) | \ + (((unsigned long long)(n) & 0xFF0000000000) >> 24) | \ + (((unsigned long long)(n) & 0xFF000000000000) >> 40) | \ + (((unsigned long long)(n) & 0xFF00000000000000) >> 56)) +#endif + +#define htobe64(n) HTONLL(n) +#define be64toh(n) NTOHLL(n) #endif