1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
8 * \brief Header for resolve.c
15 #include "lib/cc/torint.h"
16 #include "lib/testsupport/testsupport.h"
21 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
22 #define USE_SANDBOX_GETADDRINFO
28 * Primary lookup functions.
30 MOCK_DECL(int, tor_lookup_hostname
,(const char *name
, uint32_t *addr
));
31 MOCK_DECL(int, tor_addr_lookup
,(const char *name
, uint16_t family
,
32 struct tor_addr_t
*addr_out
));
33 int tor_addr_port_lookup(const char *s
, struct tor_addr_t
*addr_out
,
40 #ifdef USE_SANDBOX_GETADDRINFO
41 /** Pre-calls getaddrinfo in order to pre-record result. */
42 int tor_add_addrinfo(const char *addr
);
45 /** Replacement for getaddrinfo(), using pre-recorded results. */
46 int tor_getaddrinfo(const char *name
, const char *servname
,
47 const struct addrinfo
*hints
,
48 struct addrinfo
**res
);
49 void tor_freeaddrinfo(struct addrinfo
*addrinfo
);
50 void tor_free_getaddrinfo_cache(void);
51 #else /* !defined(USE_SANDBOX_GETADDRINFO) */
52 #define tor_getaddrinfo(name, servname, hints, res) \
53 getaddrinfo((name),(servname), (hints),(res))
54 #define tor_add_addrinfo(name) \
56 #define tor_freeaddrinfo(addrinfo) \
57 freeaddrinfo((addrinfo))
58 #define tor_free_getaddrinfo_cache()
59 #endif /* defined(USE_SANDBOX_GETADDRINFO) */
61 void sandbox_disable_getaddrinfo_cache(void);
62 void tor_make_getaddrinfo_cache_active(void);
65 * Internal resolver wrapper; exposed for mocking.
67 #ifdef RESOLVE_PRIVATE
68 MOCK_DECL(STATIC
int, tor_addr_lookup_host_impl
, (const char *name
,
70 struct tor_addr_t
*addr
));
73 #endif /* !defined(TOR_RESOLVE_H) */