File: 0001-address-Fix-endianness-problem.patch

package info (click to toggle)
libloc 0.9.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,824 kB
  • sloc: ansic: 7,602; python: 2,893; makefile: 511; sh: 39; perl: 13
file content (29 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Subject: address: Fix endianness problem when fetching octets in IPv4 addresses
Origin: upstream, https://git.ipfire.org/?p=location/libloc.git;a=commit;h=afc5330f56d74b4a9142b800d994d623d7cd29e8
Forwarded: not-needed
Author: Michael Tremer <michael.tremer@ipfire.org>
Last-Update: 2025-03-10
Applied-Upstream: commit:afc5330f56d74b4a9142b800d994d623d7cd29e8

The packaged 0.9.18 fails tests for s390x, as 10.0.0.0/32 becomes
an 10.0.0.0.in-addr.arpa., instead of expected 0.0.0.10.in-addr.arpa.

---

diff --git a/src/libloc/address.h b/src/libloc/address.h
index ff6e943..e85d761 100644
--- libloc-0.9.18.orig/src/libloc/address.h
+++ libloc-0.9.18/src/libloc/address.h
@@ -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)