Skip to content

Commit

Permalink
Unbreak master builds on CentOS 5.
Browse files Browse the repository at this point in the history
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 esnet#224.
  • Loading branch information
bmah888 committed Jan 5, 2015
1 parent 59e1c29 commit eb9a2c0
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/portable_endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <endian.h>

#elif defined(__CYGWIN__)

# include <endian.h>

Expand Down Expand Up @@ -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 <sys/endian.h>
# include <endian.h>
#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

Expand Down

0 comments on commit eb9a2c0

Please sign in to comment.