[systemd-devel] [PATCH] networkd DHCPv4 logging endian fix

Lennart Poettering lennart at poettering.net
Tue Feb 10 11:10:43 PST 2015


On Tue, 10.02.15 18:07, Paul Martin (paul.martin at codethink.co.uk) wrote:

> 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]

Hmm, I think it would be nicer to use be32toh() here instead, since it
ensures the macro is (to a limited degree) typesafe.

Any chance you could rework that?

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list