Skip to contentSkip to conversation

include: replace htobe64

RFC New Stephen Hemminger 1 participant 1 message Aug 13, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 include: replace htobe64

The PDCP code introduced rte_getattr_be64 and that introduced a dependency on htobe64. But iproute2 already hadn htonll macro.

Move the macro into an inline function in libnetlink.h

---
 include/libnetlink.h | 23 ++++++++++++++++++++++-
 include/utils.h      |  3 ---
 2 files changed, 22 insertions(+), 4 deletions(-)
include/libnetlink.h +22 -1
index 30f0c2d2..b0e3be3a 100644
@@ -13,6 +13,27 @@
 #include <linux/netconf.h>
 #include <arpa/inet.h>
 
+static inline uint64_t
+htonll(uint64_t x)
+{
+	if (1 == htonl(1)) /* is this a big endian cpu? */
+		return x;
+	else
+		return ((uint64_t)htonl(x & 0xFFFFFFFF) << 32) |
+			(htonl(x >> 32));
+}
+
+static inline uint64_t
+ntohll(uint64_t x)
+{
+	if (1 == ntohl(1)) /* is this a big endian cpu? */
+		return x;
+	else
+		return ((uint64_t)ntohl(x & 0xFFFFFFFF) << 32) |
+			(ntohl(x >> 32));
+}
+
+
 struct rtnl_handle {
 	int			fd;
 	struct sockaddr_nl	local;
@@ -277,7 +298,7 @@ static inline __u64 rta_getattr_uint(const struct rtattr *rta)
 
 static inline __be64 rta_getattr_be64(const struct rtattr *rta)
 {
-	return htobe64(rta_getattr_u64(rta));
+	return htonll(rta_getattr_u64(rta));
 }
 
 static inline __s32 rta_getattr_s32(const struct rtattr *rta)
include/utils.h +0 -3
index a2a98b9b..59bfd294 100644
@@ -303,9 +303,6 @@ unsigned int print_name_and_link(const char *fmt,
 #define _textify(x)	#x
 #define textify(x)	_textify(x)
 
-#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))
-
 extern int cmdlineno;
 
 char *int_to_str(int val, char *buf);
Signature · 1 line
2.43.0