From cbd3f88831f4a0f6cd9450621e50d8ba062f76ef Mon Sep 17 00:00:00 2001 From: MrSquanchee Date: Fri, 20 Mar 2020 23:57:40 +0530 Subject: Added tests for tor_addr_is_null/valid() Added tests for tor_addr_is_valid(), and added tests for tor_addr_is_null(), which is not modfied. Ticket 33679 --- src/lib/net/address.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/lib/net') diff --git a/src/lib/net/address.c b/src/lib/net/address.c index e968d8a7f7..7b24e406a4 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -817,7 +817,8 @@ tor_addr_is_loopback(const tor_addr_t *addr) /* Is addr valid? * Checks that addr is non-NULL and not tor_addr_is_null(). - * If for_listening is true, IPv4 addr 0.0.0.0 is allowed. + * If for_listening is true, addr is allowed in either case if + * addr is 0.0.0.0 (for IPv4) or :: (for IPv6). * It means "bind to all addresses on the local machine". */ int tor_addr_is_valid(const tor_addr_t *addr, int for_listening) @@ -833,6 +834,10 @@ tor_addr_is_valid(const tor_addr_t *addr, int for_listening) return 1; } + if (for_listening && addr->family == AF_INET6) { + return 1; + } + /* Otherwise, the address is valid if it's not tor_addr_is_null() */ return !tor_addr_is_null(addr); } -- cgit v1.2.3-54-g00ecf