Tor  0.4.3.0-alpha-dev
resolve.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file resolve.h
8  * \brief Header for resolve.c
9  **/
10 
11 #ifndef TOR_RESOLVE_H
12 #define TOR_RESOLVE_H
13 
14 #include "orconfig.h"
15 #include "lib/cc/torint.h"
17 #ifdef _WIN32
18 #include <winsock2.h>
19 #endif
20 
21 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
22 #define USE_SANDBOX_GETADDRINFO
23 #endif
24 
25 struct tor_addr_t;
26 
27 /*
28  * Primary lookup functions.
29  */
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);
35 
36 /*
37  * Sandbox helpers
38  */
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);
43 
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) */
60 
61 void sandbox_disable_getaddrinfo_cache(void);
62 void tor_make_getaddrinfo_cache_active(void);
63 
64 /*
65  * Internal resolver wrapper; exposed for mocking.
66  */
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
72 
73 #endif /* !defined(TOR_RESOLVE_H) */
int tor_addr_port_lookup(const char *s, struct tor_addr_t *addr_out, uint16_t *port_out)
Definition: resolve.c:252
const char * name
Definition: config.c:2211
Integer definitions used throughout Tor.
#define STATIC
Definition: testsupport.h:32
int tor_addr_lookup(const char *name, uint16_t family, struct tor_addr_t *addr_out)
Definition: resolve.c:190
int tor_lookup_hostname(const char *name, uint32_t *addr)
Definition: resolve.c:46
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127