From ac8f6d51f4200b27adc0da9fc1eeb44b89c8ebab Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 2 Oct 2019 21:22:53 -0400 Subject: 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. --- src/lib/net/resolve.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/lib/net') 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, -- cgit v1.2.3-54-g00ecf