diff --git a/include/ircd/util/bswap.h b/include/ircd/util/bswap.h index 28db8f357..1b0afbcbe 100644 --- a/include/ircd/util/bswap.h +++ b/include/ircd/util/bswap.h @@ -17,6 +17,8 @@ namespace ircd::util template T bswap(T); // Host <-> network endian + template T &hton(T *const &); + template T &ntoh(T *const &); template T hton(T); template T ntoh(T); @@ -85,21 +87,37 @@ template T ircd::util::hton(T a) { - #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - return bswap(&a); - #else - return a; - #endif + return hton(&a); } template T ircd::util::ntoh(T a) +{ + return ntoh(&a); +} + +template +T & +ircd::util::hton(T *const &a) { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - return bswap(&a); + return bswap(a); #else - return a; + assert(a); + return *a; + #endif +} + +template +T & +ircd::util::ntoh(T *const &a) +{ + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return bswap(a); + #else + assert(a); + return *a; #endif }