network_sys.c 870 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (c) 2018-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file network_sys.c
  5. * \brief Subsystem object for networking setup.
  6. **/
  7. #include "orconfig.h"
  8. #include "lib/subsys/subsys.h"
  9. #include "lib/net/network_sys.h"
  10. #include "lib/net/resolve.h"
  11. #include "lib/net/socket.h"
  12. #ifdef _WIN32
  13. #include <winsock2.h>
  14. #include <windows.h>
  15. #endif
  16. static int
  17. subsys_network_initialize(void)
  18. {
  19. if (network_init() < 0)
  20. return -1;
  21. return 0;
  22. }
  23. static void
  24. subsys_network_shutdown(void)
  25. {
  26. #ifdef _WIN32
  27. WSACleanup();
  28. #endif
  29. tor_free_getaddrinfo_cache();
  30. }
  31. const subsys_fns_t sys_network = {
  32. .name = "network",
  33. /* Network depends on logging, and a lot of other modules depend on network.
  34. */
  35. .level = -80,
  36. .supported = true,
  37. .initialize = subsys_network_initialize,
  38. .shutdown = subsys_network_shutdown,
  39. };