resolve.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. MOCK_DECL(int, tor_lookup_hostname,(const char *name, uint32_t *addr));
  22. MOCK_DECL(int, tor_addr_lookup,(const char *name, uint16_t family,
  23. struct tor_addr_t *addr_out));
  24. int tor_addr_port_lookup(const char *s, struct tor_addr_t *addr_out,
  25. uint16_t *port_out);
  26. struct addrinfo;
  27. #ifdef USE_SANDBOX_GETADDRINFO
  28. /** Pre-calls getaddrinfo in order to pre-record result. */
  29. int tor_add_addrinfo(const char *addr);
  30. struct addrinfo;
  31. /** Replacement for getaddrinfo(), using pre-recorded results. */
  32. int tor_getaddrinfo(const char *name, const char *servname,
  33. const struct addrinfo *hints,
  34. struct addrinfo **res);
  35. void tor_freeaddrinfo(struct addrinfo *addrinfo);
  36. void tor_free_getaddrinfo_cache(void);
  37. void tor_make_getaddrinfo_cache_active(void);
  38. #else /* !(defined(USE_SANDBOX_GETADDRINFO)) */
  39. #define tor_getaddrinfo(name, servname, hints, res) \
  40. getaddrinfo((name),(servname), (hints),(res))
  41. #define tor_add_addrinfo(name) \
  42. ((void)(name))
  43. #define tor_freeaddrinfo(addrinfo) \
  44. freeaddrinfo((addrinfo))
  45. #define tor_free_getaddrinfo_cache()
  46. #endif /* defined(USE_SANDBOX_GETADDRINFO) */
  47. void sandbox_disable_getaddrinfo_cache(void);
  48. #endif