Update copyrights to 2021, using "make update-copyright"
[tor.git] / src / lib / net / resolve.h
blob4eeda230ca5866fddee086cf67fff98d5caf0ee3
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 */
6 /**
7 * \file resolve.h
8 * \brief Header for resolve.c
9 **/
11 #ifndef TOR_RESOLVE_H
12 #define TOR_RESOLVE_H
14 #include "orconfig.h"
15 #include "lib/cc/torint.h"
16 #include "lib/testsupport/testsupport.h"
17 #ifdef _WIN32
18 #include <winsock2.h>
19 #endif
21 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
22 #define USE_SANDBOX_GETADDRINFO
23 #endif
25 struct tor_addr_t;
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,
34 uint16_t *port_out);
37 * Sandbox helpers
39 struct addrinfo;
40 #ifdef USE_SANDBOX_GETADDRINFO
41 /** Pre-calls getaddrinfo in order to pre-record result. */
42 int tor_add_addrinfo(const char *addr);
44 struct addrinfo;
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) \
55 ((void)(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,
69 uint16_t family,
70 struct tor_addr_t *addr));
71 #endif
73 #endif /* !defined(TOR_RESOLVE_H) */