From 751605f2a011983faa29a5fe3e22a74f9f71f1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?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 5ee8ee933a2..6c7790126b1 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 "procfs.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 procfs_byteorder byteorder, uint32_t v) +{ + if (byteorder == PROCFS_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 procfs_byteorder byteorder = procfs_get_byteorder(NULL); + 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;