diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-10-02 21:22:53 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-10-03 07:47:25 -0400 |
commit | ac8f6d51f4200b27adc0da9fc1eeb44b89c8ebab (patch) | |
tree | ad358334b7bd52edb77c1fb9700d58c98dcf125e /src/lib/net | |
parent | bca30bcb90a7c01eea453b1fdf2b6ba368500e03 (diff) | |
download | tor-ac8f6d51f4200b27adc0da9fc1eeb44b89c8ebab.tar.gz tor-ac8f6d51f4200b27adc0da9fc1eeb44b89c8ebab.zip |
Unify backend implementations for blocking hostname lookup
We have a getaddrinfo() implementation that we prefer, and a
gethostbyname*() implementation that we fall back on. Give them
both the same interface, and let them be called by the same name.
This is a preparatory step for making them both mockable.
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/resolve.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/lib/net/resolve.c b/src/lib/net/resolve.c index 78e72fba4f..c8fe338e52 100644 --- a/src/lib/net/resolve.c +++ b/src/lib/net/resolve.c @@ -71,9 +71,9 @@ tor_lookup_hostname,(const char *name, uint32_t *addr)) * See tor_addr_lookup() for details. */ static int -tor_addr_lookup_host_getaddrinfo(const char *name, - uint16_t family, - tor_addr_t *addr) +tor_addr_lookup_host_impl(const char *name, + uint16_t family, + tor_addr_t *addr) { int err; struct addrinfo *res=NULL, *res_p; @@ -120,15 +120,17 @@ tor_addr_lookup_host_getaddrinfo(const char *name, #else /* !defined(HAVE_GETADDRINFO) */ -/* Host lookup helper for tor_addr_lookup(), which calls getaddrinfo(). - * Used when gethostbyname() is not available on this system. +/* Host lookup helper for tor_addr_lookup(), which calls gethostbyname(). + * Used when getaddrinfo() is not available on this system. * * See tor_addr_lookup() for details. */ static int -tor_addr_lookup_host_gethostbyname(const char *name, - tor_addr_t *addr) +tor_addr_lookup_host_impl(const char *name, + uint16_t family, + tor_addr_t *addr) { + (void) family; struct hostent *ent; int err; #ifdef HAVE_GETHOSTBYNAME_R_6_ARG @@ -215,13 +217,8 @@ tor_addr_lookup,(const char *name, uint16_t family, tor_addr_t *addr)) } else { /* Clear the address after a failed tor_addr_parse(). */ memset(addr, 0, sizeof(tor_addr_t)); -#ifdef HAVE_GETADDRINFO - result = tor_addr_lookup_host_getaddrinfo(name, family, addr); - goto done; -#else /* !(defined(HAVE_GETADDRINFO)) */ - result = tor_addr_lookup_host_gethostbyname(name, addr); + result = tor_addr_lookup_host_impl(name, family, addr); goto done; -#endif /* defined(HAVE_GETADDRINFO) */ } /* If we weren't successful, and haven't already set the result, |