]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Consistently use endian.h swapping API
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 8 Feb 2026 14:43:31 +0000 (14:43 +0000)
committerLucas De Marchi <demarchi@kernel.org>
Thu, 12 Feb 2026 16:49:58 +0000 (10:49 -0600)
A handful of places are still using the old "networking" API. Swap that
with the usual (no longer GNU/glibc specific) ntobe*/be*toh.

Be that to stay consistent, to improve clarity or to celebrate that the
later is part of POSIX (2024) - take your pick.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <demarchi@kernel.org>
Link: https://github.com/kmod-project/kmod/pull/421
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
libkmod/libkmod-index.c
tools/depmod.c

index cd5cf0ebb8a090c279cf8ecdd778755e78ca4baa..e64fe1eb683dd6bd3235b41eca6dfad3aa491cd4 100644 (file)
@@ -5,8 +5,8 @@
 
 #include <sys/param.h>
 
-#include <arpa/inet.h>
 #include <assert.h>
+#include <endian.h>
 #include <errno.h>
 #include <fnmatch.h>
 #include <inttypes.h>
@@ -225,7 +225,7 @@ static bool read_u32s(FILE *in, uint32_t *l, size_t n)
                return false;
        }
        for (i = 0; i < n; i++)
-               l[i] = ntohl(l[i]);
+               l[i] = be32toh(l[i]);
        return true;
 }
 
@@ -662,7 +662,7 @@ static inline uint32_t read_u32_mm(const void **p)
        v = get_unaligned((const uint32_t *)addr);
 
        *p = addr + sizeof(uint32_t);
-       return ntohl(v);
+       return be32toh(v);
 }
 
 static inline uint8_t read_char_mm(const void **p)
index 355483ad89d255fed35e8f3934f341b79c18eedf..c3d876404a8bc0081d28fc0b11a11011747a57c2 100644 (file)
@@ -4,10 +4,10 @@
  * Copyright (C) 2011-2013  ProFUSION embedded systems
  */
 
-#include <arpa/inet.h>
 #include <assert.h>
 #include <ctype.h>
 #include <dirent.h>
+#include <endian.h>
 #include <errno.h>
 #include <getopt.h>
 #include <limits.h>
@@ -402,7 +402,7 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
                        } else {
                                uint32_t mask = index_get_mask(child);
                                child_offs[i] =
-                                       htonl((offset + node->size + sizes) | mask);
+                                       htobe32((offset + node->size + sizes) | mask);
                                sizes += child->total;
                        }
                }
@@ -428,11 +428,11 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
                value_count = 0;
                for (v = node->values; v != NULL; v = v->next)
                        value_count++;
-               u = htonl(value_count);
+               u = htobe32(value_count);
                fwrite(&u, sizeof(u), 1, out);
 
                for (v = node->values; v != NULL; v = v->next) {
-                       u = htonl(v->priority);
+                       u = htobe32(v->priority);
                        fwrite(&u, sizeof(u), 1, out);
                        fputs(v->value, out);
                        fputc('\0', out);
@@ -462,13 +462,13 @@ static void index_write(struct index_node *node, FILE *out)
 
        index_calculate_size(node);
 
-       u = htonl(INDEX_MAGIC);
+       u = htobe32(INDEX_MAGIC);
        fwrite(&u, sizeof(u), 1, out);
-       u = htonl(INDEX_VERSION);
+       u = htobe32(INDEX_VERSION);
        fwrite(&u, sizeof(u), 1, out);
 
        /* Write offset of first node */
-       u = htonl(first_off | index_get_mask(node));
+       u = htobe32(first_off | index_get_mask(node));
        fwrite(&u, sizeof(u), 1, out);
 
        /* Dump trie */