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