]> git.ipfire.org Git - location/libloc.git/commitdiff
address: Fix endianess problem when fetching octets in IPv4 addresses
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Mar 2025 15:13:07 +0000 (15:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Mar 2025 15:13:07 +0000 (15:13 +0000)
Fixes: #13828
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libloc/address.h

index ff6e9434f44eb8db9254ebd38032f18e05d5e4fb..e85d7618aaa9828c608566627e5f1ce4bd55de16 100644 (file)
@@ -324,7 +324,11 @@ static inline int loc_address_get_octet(const struct in6_addr* address, const un
                if (i >= 4)
                        return -ERANGE;
 
-               return (address->s6_addr32[3] >> (i * 8)) & 0xff;
+               // Format the IPv4 in host-byte order
+               unsigned int a4 = be32toh(address->s6_addr32[3]);
+
+               // Return the nth byte from the left
+               return a4 >> ((3 - i) * 8) & 0xff;
 
        } else {
                if (i >= 32)