aboutsummaryrefslogtreecommitdiff
path: root/src/lib/net
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-06-02 18:20:25 +1000
committerNick Mathewson <nickm@torproject.org>2019-06-26 09:55:37 -0400
commit29cf64c8389fd4de1e4419cb8ac30b2ca582ba5e (patch)
treed17f466021767be34d68e6d4c041d51434cda9b8 /src/lib/net
parentcd1de99468aa4d7b48c9f3bcb7c7d4fb5b3bfe9a (diff)
downloadtor-29cf64c8389fd4de1e4419cb8ac30b2ca582ba5e.tar.gz
tor-29cf64c8389fd4de1e4419cb8ac30b2ca582ba5e.zip
resolve: refactor address family logic in tor_addr_lookup()
Cleanup after 30721.
Diffstat (limited to 'src/lib/net')
-rw-r--r--src/lib/net/resolve.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/lib/net/resolve.c b/src/lib/net/resolve.c
index 71c033fe7a..1b68a0b33a 100644
--- a/src/lib/net/resolve.c
+++ b/src/lib/net/resolve.c
@@ -81,30 +81,24 @@ tor_addr_lookup,(const char *name, uint16_t family, tor_addr_t *addr))
tor_assert(addr);
tor_assert(family == AF_INET || family == AF_INET6 || family == AF_UNSPEC);
- /* Clear address before starting, to avoid returning uninitialised data */
- memset(addr, 0, sizeof(tor_addr_t));
-
if (!*name) {
/* Empty address is an error. */
+ memset(addr, 0, sizeof(tor_addr_t));
return -1;
}
/* Is it an IP address? */
parsed_family = tor_addr_parse(addr, name);
- if (parsed_family == AF_INET) {
- /* It's an IPv4 IP. */
- if (family == AF_INET6) {
- memset(addr, 0, sizeof(tor_addr_t));
- return -1;
- }
- return 0;
- } else if (parsed_family == AF_INET6) {
- if (family == AF_INET) {
+ if (parsed_family >= 0) {
+ /* If the IP address family matches, or was unspecified */
+ if (parsed_family == family || family == AF_UNSPEC) {
+ return 0;
+ } else {
+ /* Clear the address before returning an error. */
memset(addr, 0, sizeof(tor_addr_t));
return -1;
}
- return 0;
} else {
/* Clear the address after a failed tor_addr_parse(). */
memset(addr, 0, sizeof(tor_addr_t));