resolve.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_RESOLVE_H
  6. #define TOR_RESOLVE_H
  7. #include "orconfig.h"
  8. #include "lib/cc/torint.h"
  9. #include "lib/testsupport/testsupport.h"
  10. #ifdef _WIN32
  11. #include <winsock2.h>
  12. #endif
  13. #if defined(HAVE_SECCOMP_H) && defined(__linux__)
  14. #define USE_SANDBOX_GETADDRINFO
  15. #endif
  16. MOCK_DECL(int,tor_lookup_hostname,(const char *name, uint32_t *addr));
  17. struct addrinfo;
  18. #ifdef USE_SANDBOX_GETADDRINFO
  19. /** Pre-calls getaddrinfo in order to pre-record result. */
  20. int sandbox_add_addrinfo(const char *addr);
  21. // XXXX rename these. They are named as though they were sandbox-only,
  22. // XXXX but in fact they're the only allowed entry point to getaddrinfo.
  23. // XXXX They don't invoke the sandbox code; they only have an internal cache.
  24. struct addrinfo;
  25. /** Replacement for getaddrinfo(), using pre-recorded results. */
  26. int sandbox_getaddrinfo(const char *name, const char *servname,
  27. const struct addrinfo *hints,
  28. struct addrinfo **res);
  29. void sandbox_freeaddrinfo(struct addrinfo *addrinfo);
  30. void sandbox_free_getaddrinfo_cache(void);
  31. void sandbox_make_getaddrinfo_cache_active(void);
  32. #else /* !(defined(USE_SANDBOX_GETADDRINFO)) */
  33. #define sandbox_getaddrinfo(name, servname, hints, res) \
  34. getaddrinfo((name),(servname), (hints),(res))
  35. #define sandbox_add_addrinfo(name) \
  36. ((void)(name))
  37. #define sandbox_freeaddrinfo(addrinfo) \
  38. freeaddrinfo((addrinfo))
  39. #define sandbox_free_getaddrinfo_cache()
  40. #endif /* defined(USE_SANDBOX_GETADDRINFO) */
  41. void sandbox_disable_getaddrinfo_cache(void);
  42. #endif