From db79a10027b06d064a7ecd6cddf6641da6bb2ae4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 30 Oct 2022 18:57:30 +0100 Subject: [PATCH] lsfd: use runtime byteorder --- misc-utils/lsfd-sock-xinfo.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c index 5a14c5b592..ca6b8ee48c 100644 --- a/misc-utils/lsfd-sock-xinfo.c +++ b/misc-utils/lsfd-sock-xinfo.c @@ -31,6 +31,8 @@ #include "xalloc.h" #include "nls.h" #include "libsmartcols.h" +#include "sysfs.h" +#include "bitops.h" #include "lsfd.h" #include "lsfd-sock.h" @@ -610,6 +612,14 @@ static bool L3_verify_initial_line(const char *line) return (strncmp(line, "sl", 2) == 0); } +static uint32_t kernel32_to_cpu(enum sysfs_byteorder byteorder, uint32_t v) +{ + if (byteorder == SYSFS_BYTEORDER_LITTLE) + return le32_to_cpu(v); + else + return be32_to_cpu(v); +} + #define TCP_LINE_LEN 256 static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_file, struct sock_xinfo_class *class) @@ -627,6 +637,8 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil /* Unexpected line */ goto out; + enum sysfs_byteorder byteorder = sysfs_get_byteorder(); + while (fgets(line, sizeof(line), tcp_fp)) { unsigned long local_addr; unsigned long local_port; @@ -652,9 +664,9 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil sock->class = class; sock->inode = (ino_t)inode; sock->netns_inode = netns_inode; - inet->local_addr = local_addr; + inet->local_addr = kernel32_to_cpu(byteorder, local_addr); tcp->local_port = local_port; - inet->remote_addr = remote_addr; + inet->remote_addr = kernel32_to_cpu(byteorder, remote_addr); tcp->remote_port = remote_port; tcp->st = st; -- 2.47.3