[systemd-devel] [PATCH] networkd DHCPv4 logging endian fix
Paul Martin
paul.martin at codethink.co.uk
Tue Feb 10 10:07:59 PST 2015
On a big-endian host, systemd-networkd prints out IPv4 network
addresses byte reversed:
Feb 10 16:43:32 hostname systemd-networkd[151]: eth0 : DHCPv4 address 158.1.24.10/16 via 1.1.24.10
The address obtained is 10.24.1.158/16 and the route is
10.24.0.0/16 dev eth0 src 10.24.1.187
The macro ADDRESS_FMT_VAL() unpacks a "struct in_addr" in a
little-endian specific manner. This patch makes the macro endian
agnostic using the same trick as is used in the IN6_ARE_ADDR_EQUAL()
macro in <netinet/in.h>.
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
index 449dbc8..3394b61 100644
--- a/src/network/networkd-link.h
+++ b/src/network/networkd-link.h
@@ -153,7 +153,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
#define log_link_struct(link, level, ...) log_struct(level, "INTERFACE=%s", link->ifname, __VA_ARGS__)
#define ADDRESS_FMT_VAL(address) \
- (address).s_addr & 0xFF, \
- ((address).s_addr >> 8) & 0xFF, \
- ((address).s_addr >> 16) & 0xFF, \
- (address).s_addr >> 24
+ ((const uint8_t *) (&address))[0], \
+ ((const uint8_t *) (&address))[1], \
+ ((const uint8_t *) (&address))[2], \
+ ((const uint8_t *) (&address))[3]
--
Paul Martin http://www.codethink.co.uk/
Senior Software Developer, Codethink Ltd
More information about the systemd-devel
mailing list