]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: use runtime byteorder
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 30 Oct 2022 17:57:30 +0000 (18:57 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 25 Nov 2022 18:20:32 +0000 (19:20 +0100)
misc-utils/lsfd-sock-xinfo.c

index 5a14c5b59273c30b48871d9712f2b8148ffaead5..ca6b8ee48cf8673ecbaba3d1c64d1c27d4f0a85a 100644 (file)
@@ -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;