From b9f4314ef9e7dc8b2852430f6923cbedda46ae38 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 8 Dec 2023 01:31:37 +1100 Subject: util: Drop explicit setting to INADDR_ANY/in6addr_any in sock_l4() The original commit message says: --- Currently we initialise the address field of the sockaddrs we construct to the any/unspecified address, but not in a very clear way: we use explicit 0 values, which is only interpretable if you know the order of fields in the sockaddr structures. Use explicit field names, and explicit initialiser macros for the address. Because we initialise to this default value, we don't need to explicitly set the any/unspecified address later on if the caller didn't pass an overriding bind address. --- and the original patch modified the initialisation of addr4 and addr6: - instead of { 0 }, { 0 } for sin_addr and sin_zero, .sin_addr = IN4ADDR_ANY_INIT - instead of 0, IN6ADDR_ANY_INIT, 0: .sin6_addr = IN6ADDR_ANY_INIT but I dropped those hunks: they break gcc versions 7 to 9 as reported in eed6933e6c29 ("udp: Explicitly initialise sin6_scope_id and sin_zero in sockaddr_in{,6}"). I applied the rest of the changes. Signed-off-by: David Gibson [sbrivio: Dropped first two hunks] Signed-off-by: Stefano Brivio --- util.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util.c b/util.c index d465e48..43547c3 100644 --- a/util.c +++ b/util.c @@ -162,8 +162,6 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, if (af == AF_INET) { if (bind_addr) addr4.sin_addr.s_addr = *(in_addr_t *)bind_addr; - else - addr4.sin_addr.s_addr = htonl(INADDR_ANY); sa = (const struct sockaddr *)&addr4; sl = sizeof(addr4); @@ -174,8 +172,6 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, if (!memcmp(bind_addr, &c->ip6.addr_ll, sizeof(c->ip6.addr_ll))) addr6.sin6_scope_id = c->ifi6; - } else { - addr6.sin6_addr = in6addr_any; } sa = (const struct sockaddr *)&addr6; -- cgit v1.2.3