inany_from_af() can be used to initialise a union inany_addr from either an IPv4 or IPv6 address. If we want to set it to the unspecified IPv4 or IPv6 address we can do that, but need to explicitly pass the correct address version. Make this easier by allowing it to interpret a NULL address as the unspecified address of the appropriate family. We only have one trivial use for this at present, but it will have more uses in future. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- inany.h | 10 ++++++++-- tcp.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inany.h b/inany.h index 063545b7..70237821 100644 --- a/inany.h +++ b/inany.h @@ -92,11 +92,17 @@ static inline void inany_from_af(union inany_addr *aa, sa_family_t af, const void *addr) { if (af == AF_INET6) { - aa->a6 = *((struct in6_addr *)addr); + if (addr) + aa->a6 = *((struct in6_addr *)addr); + else + aa->a6 = in6addr_any; } else if (af == AF_INET) { memset(&aa->v4mapped.zero, 0, sizeof(aa->v4mapped.zero)); memset(&aa->v4mapped.one, 0xff, sizeof(aa->v4mapped.one)); - aa->v4mapped.a4 = *((struct in_addr *)addr); + if (addr) + aa->v4mapped.a4 = *((struct in_addr *)addr); + else + aa->v4mapped.a4 = in4addr_any; } else { /* Not valid to call with other address families */ ASSERT(0); diff --git a/tcp.c b/tcp.c index 6c9edbe1..1326584e 100644 --- a/tcp.c +++ b/tcp.c @@ -883,7 +883,7 @@ static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, low_rtt_dst[hole++] = conn->faddr; if (hole == LOW_RTT_TABLE_SIZE) hole = 0; - inany_from_af(low_rtt_dst + hole, AF_INET6, &in6addr_any); + inany_from_af(low_rtt_dst + hole, AF_INET6, NULL); #else (void)conn; (void)tinfo; -- 2.43.0