mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge remote-tracking branch 'tor-github/pr/1393' into maint-0.4.2
This commit is contained in:
+13
-16
@@ -8,6 +8,7 @@
|
||||
* \brief Use the libc DNS resolver to convert hostnames into addresses.
|
||||
**/
|
||||
|
||||
#define RESOLVE_PRIVATE
|
||||
#include "lib/net/resolve.h"
|
||||
|
||||
#include "lib/net/address.h"
|
||||
@@ -70,10 +71,10 @@ 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)
|
||||
MOCK_IMPL(STATIC int,
|
||||
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 +121,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)
|
||||
MOCK_IMPL(STATIC int,
|
||||
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
|
||||
@@ -170,7 +173,6 @@ tor_addr_lookup_host_gethostbyname(const char *name,
|
||||
return (err == TRY_AGAIN) ? 1 : -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* defined(HAVE_GETADDRINFO) */
|
||||
|
||||
/** Similar behavior to Unix gethostbyname: resolve <b>name</b>, and set
|
||||
@@ -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);
|
||||
result = tor_addr_lookup_host_impl(name, family, addr);
|
||||
goto done;
|
||||
#else /* !(defined(HAVE_GETADDRINFO)) */
|
||||
result = tor_addr_lookup_host_gethostbyname(name, addr);
|
||||
goto done;
|
||||
#endif /* defined(HAVE_GETADDRINFO) */
|
||||
}
|
||||
|
||||
/* If we weren't successful, and haven't already set the result,
|
||||
|
||||
@@ -24,12 +24,18 @@
|
||||
|
||||
struct tor_addr_t;
|
||||
|
||||
/*
|
||||
* Primary lookup functions.
|
||||
*/
|
||||
MOCK_DECL(int, tor_lookup_hostname,(const char *name, uint32_t *addr));
|
||||
MOCK_DECL(int, tor_addr_lookup,(const char *name, uint16_t family,
|
||||
struct tor_addr_t *addr_out));
|
||||
int tor_addr_port_lookup(const char *s, struct tor_addr_t *addr_out,
|
||||
uint16_t *port_out);
|
||||
|
||||
/*
|
||||
* Sandbox helpers
|
||||
*/
|
||||
struct addrinfo;
|
||||
#ifdef USE_SANDBOX_GETADDRINFO
|
||||
/** Pre-calls getaddrinfo in order to pre-record result. */
|
||||
@@ -55,4 +61,13 @@ void tor_free_getaddrinfo_cache(void);
|
||||
void sandbox_disable_getaddrinfo_cache(void);
|
||||
void tor_make_getaddrinfo_cache_active(void);
|
||||
|
||||
/*
|
||||
* Internal resolver wrapper; exposed for mocking.
|
||||
*/
|
||||
#ifdef RESOLVE_PRIVATE
|
||||
MOCK_DECL(STATIC int, tor_addr_lookup_host_impl, (const char *name,
|
||||
uint16_t family,
|
||||
struct tor_addr_t *addr));
|
||||
#endif
|
||||
|
||||
#endif /* !defined(TOR_RESOLVE_H) */
|
||||
|
||||
Reference in New Issue
Block a user