resolve.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * \file resolve.h
  7. * \brief Header for resolve.c
  8. **/
  9. #ifndef TOR_RESOLVE_H
  10. #define TOR_RESOLVE_H
  11. #include "orconfig.h"
  12. #include "lib/cc/torint.h"
  13. #include "lib/testsupport/testsupport.h"
  14. #ifdef _WIN32
  15. #include <winsock2.h>
  16. #endif
  17. #if defined(HAVE_SECCOMP_H) && defined(__linux__)
  18. #define USE_SANDBOX_GETADDRINFO
  19. #endif
  20. struct tor_addr_t;
  21. /*
  22. * Primary lookup functions.
  23. */
  24. MOCK_DECL(int, tor_lookup_hostname,(const char *name, uint32_t *addr));
  25. MOCK_DECL(int, tor_addr_lookup,(const char *name, uint16_t family,
  26. struct tor_addr_t *addr_out));
  27. int tor_addr_port_lookup(const char *s, struct tor_addr_t *addr_out,
  28. uint16_t *port_out);
  29. /*
  30. * Sandbox helpers
  31. */
  32. struct addrinfo;
  33. #ifdef USE_SANDBOX_GETADDRINFO
  34. /** Pre-calls getaddrinfo in order to pre-record result. */
  35. int tor_add_addrinfo(const char *addr);
  36. struct addrinfo;
  37. /** Replacement for getaddrinfo(), using pre-recorded results. */
  38. int tor_getaddrinfo(const char *name, const char *servname,
  39. const struct addrinfo *hints,
  40. struct addrinfo **res);
  41. void tor_freeaddrinfo(struct addrinfo *addrinfo);
  42. void tor_free_getaddrinfo_cache(void);
  43. #else /* !defined(USE_SANDBOX_GETADDRINFO) */
  44. #define tor_getaddrinfo(name, servname, hints, res) \
  45. getaddrinfo((name),(servname), (hints),(res))
  46. #define tor_add_addrinfo(name) \
  47. ((void)(name))
  48. #define tor_freeaddrinfo(addrinfo) \
  49. freeaddrinfo((addrinfo))
  50. #define tor_free_getaddrinfo_cache()
  51. #endif /* defined(USE_SANDBOX_GETADDRINFO) */
  52. void sandbox_disable_getaddrinfo_cache(void);
  53. void tor_make_getaddrinfo_cache_active(void);
  54. /*
  55. * Internal resolver wrapper; exposed for mocking.
  56. */
  57. #ifdef RESOLVE_PRIVATE
  58. MOCK_DECL(STATIC int, tor_addr_lookup_host_impl, (const char *name,
  59. uint16_t family,
  60. struct tor_addr_t *addr));
  61. #endif
  62. #endif /* !defined(TOR_RESOLVE_H) */