diff --git a/sbin/nvmecontrol/nvmecontrol.h b/sbin/nvmecontrol/nvmecontrol.h --- a/sbin/nvmecontrol/nvmecontrol.h +++ b/sbin/nvmecontrol/nvmecontrol.h @@ -103,10 +103,18 @@ typedef __uint128_t uint128_t; #endif +/* + * Assumes that the source is in little endian order, but we want the return in + * host order. + */ static __inline uint128_t to128(void *p) { +#if _BYTE_ORDER == _LITTLE_ENDIAN return *(uint128_t *)p; +#else + return le64toh(*(uint64_t *)p) | ((uint128_t)le64toh(*((uint64_t *)p + 1)) << 64); +#endif } uint64_t le48dec(const void *pp);