mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
address: Simplify tor_addr_is_valid()
And rewrite the function comment. Part of 33679.
This commit is contained in:
parent
cbd3f88831
commit
1720a2191d
@ -817,9 +817,12 @@ tor_addr_is_loopback(const tor_addr_t *addr)
|
|||||||
|
|
||||||
/* Is addr valid?
|
/* Is addr valid?
|
||||||
* Checks that addr is non-NULL and not tor_addr_is_null().
|
* Checks that addr is non-NULL and not tor_addr_is_null().
|
||||||
* If for_listening is true, addr is allowed in either case if
|
* If for_listening is true, all IPv4 and IPv6 addresses are valid, including
|
||||||
* addr is 0.0.0.0 (for IPv4) or :: (for IPv6).
|
* 0.0.0.0 (for IPv4) and :: (for IPv6). When listening, these addresses mean
|
||||||
* It means "bind to all addresses on the local machine". */
|
* "bind to all addresses on the local machine".
|
||||||
|
* Otherwise, 0.0.0.0 and :: are invalid, because they are null addresses.
|
||||||
|
* All unspecified and unix addresses are invalid, regardless of for_listening.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
tor_addr_is_valid(const tor_addr_t *addr, int for_listening)
|
tor_addr_is_valid(const tor_addr_t *addr, int for_listening)
|
||||||
{
|
{
|
||||||
@ -828,14 +831,11 @@ tor_addr_is_valid(const tor_addr_t *addr, int for_listening)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only allow IPv4 0.0.0.0 for_listening. */
|
/* Allow all IPv4 and IPv6 addresses, when for_listening is true */
|
||||||
if (for_listening && addr->family == AF_INET
|
if (for_listening) {
|
||||||
&& tor_addr_to_ipv4h(addr) == 0) {
|
if (addr->family == AF_INET || addr->family == AF_INET6) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (for_listening && addr->family == AF_INET6) {
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Otherwise, the address is valid if it's not tor_addr_is_null() */
|
/* Otherwise, the address is valid if it's not tor_addr_is_null() */
|
||||||
|
Loading…
Reference in New Issue
Block a user