Skip to content

Commit

Permalink
net/byteorder: fix 64 bit ntohq and htonq on big endian machines
Browse files Browse the repository at this point in the history
Uses predefined GNU preprocessor macros to detect endianness. This
seems portable enough for now. htonq calls ntohq since they have
identical implementations.

Message-Id: <[email protected]>
  • Loading branch information
mundaym authored and avikivity committed Sep 6, 2017
1 parent 1012a6c commit 31b925d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion net/byteorder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@
namespace seastar {

inline uint64_t ntohq(uint64_t v) {
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
// big endian, nothing to do
return v;
#else
// little endian, reverse bytes
return __builtin_bswap64(v);
#endif
}
inline uint64_t htonq(uint64_t v) {
return __builtin_bswap64(v);
// htonq and ntohq have identical implementations
return ntohq(v);
}

namespace net {
Expand Down

0 comments on commit 31b925d

Please sign in to comment.