]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: make htonll/ntohll compile time and readable
authorStephen Worley <sworley@nvidia.com>
Sat, 10 Dec 2022 00:27:20 +0000 (19:27 -0500)
committerStephen Worley <sworley@nvidia.com>
Mon, 13 Feb 2023 23:12:05 +0000 (18:12 -0500)
Make the htonll/ntohll functions compile time determined
since we have MACROS to determine endianess and bonus
points it makes it more readable.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
lib/zebra.h

index 455db9c64e680b39a912b530b39f054b08d30443..a87398a23798670e7c760111ca6a9060dc0619ed 100644 (file)
@@ -338,14 +338,13 @@ struct in_pktinfo {
 
 #define strmatch(a,b) (!strcmp((a), (b)))
 
-#define htonll(x)                                                              \
-       ((1 == htonl(1))                                                       \
-                ? (x)                                                         \
-                : ((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
-#define ntohll(x)                                                              \
-       ((1 == ntohl(1))                                                       \
-                ? (x)                                                         \
-                : ((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
+#define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+#else
+#define htonll(x) (x)
+#define ntohll(x) (x)
+#endif
 
 #ifndef INADDR_LOOPBACK
 #define        INADDR_LOOPBACK 0x7f000001      /* Internet address 127.0.0.1.  */