aboutsummaryrefslogtreecommitdiff
path: root/src/lib/net/network_sys.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-02 11:11:21 -0400
committerNick Mathewson <nickm@torproject.org>2018-11-05 09:22:02 -0500
commitcfe5b35edb38cef6312ef0b4ae44fb0e20342706 (patch)
tree7a4d37f58a5ecd05255efcd138bc34271dc8df9f /src/lib/net/network_sys.c
parent05b54f6a6a24ebdb47de4f7e41cf94f2f6be93bd (diff)
downloadtor-cfe5b35edb38cef6312ef0b4ae44fb0e20342706.tar.gz
tor-cfe5b35edb38cef6312ef0b4ae44fb0e20342706.zip
Move networking startup/cleanup logic into a subsystem.
Diffstat (limited to 'src/lib/net/network_sys.c')
-rw-r--r--src/lib/net/network_sys.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/net/network_sys.c b/src/lib/net/network_sys.c
new file mode 100644
index 0000000000..c9d33a94d3
--- /dev/null
+++ b/src/lib/net/network_sys.c
@@ -0,0 +1,44 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file network_sys.c
+ * \brief Subsystem object for networking setup.
+ **/
+
+#include "orconfig.h"
+#include "lib/subsys/subsys.h"
+#include "lib/net/network_sys.h"
+#include "lib/net/resolve.h"
+#include "lib/net/socket.h"
+
+#ifdef _WIN32
+#include <winsock2.h>
+#include <windows.h>
+#endif
+
+static int
+init_network_sys(void)
+{
+ if (network_init() < 0)
+ return -1;
+
+ return 0;
+}
+
+static void
+shutdown_network_sys(void)
+{
+#ifdef _WIN32
+ WSACleanup();
+#endif
+ tor_free_getaddrinfo_cache();
+}
+
+const subsys_fns_t sys_network = {
+ .name = "network",
+ .level = -90,
+ .supported = true,
+ .initialize = init_network_sys,
+ .shutdown = shutdown_network_sys,
+};