diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-11-09 15:01:49 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-11-09 15:01:49 -0500 |
commit | bf4f55a13da783083b0c76decd6ebf475a63ebd0 (patch) | |
tree | 15ebd3463fc900d52cd3065b6c83cf83a364e3e7 /src/lib/net | |
parent | 5d73f87cedaf58fd6e7a53a230b311f5e8b51b73 (diff) | |
parent | 60d10812368458cb88aa9f9d628c49766d4bb490 (diff) | |
download | tor-bf4f55a13da783083b0c76decd6ebf475a63ebd0.tar.gz tor-bf4f55a13da783083b0c76decd6ebf475a63ebd0.zip |
Merge branch 'subsystems'
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/.may_include | 1 | ||||
-rw-r--r-- | src/lib/net/include.am | 2 | ||||
-rw-r--r-- | src/lib/net/network_sys.c | 44 | ||||
-rw-r--r-- | src/lib/net/network_sys.h | 14 |
4 files changed, 61 insertions, 0 deletions
diff --git a/src/lib/net/.may_include b/src/lib/net/.may_include index 13b209bbed..f93f0e1552 100644 --- a/src/lib/net/.may_include +++ b/src/lib/net/.may_include @@ -11,5 +11,6 @@ lib/lock/*.h lib/log/*.h lib/net/*.h lib/string/*.h +lib/subsys/*.h lib/testsupport/*.h lib/malloc/*.h
\ No newline at end of file diff --git a/src/lib/net/include.am b/src/lib/net/include.am index ff0967e786..8a88f0f2ae 100644 --- a/src/lib/net/include.am +++ b/src/lib/net/include.am @@ -11,6 +11,7 @@ src_lib_libtor_net_a_SOURCES = \ src/lib/net/buffers_net.c \ src/lib/net/gethostname.c \ src/lib/net/inaddr.c \ + src/lib/net/network_sys.c \ src/lib/net/resolve.c \ src/lib/net/socket.c \ src/lib/net/socketpair.c @@ -28,6 +29,7 @@ noinst_HEADERS += \ src/lib/net/inaddr.h \ src/lib/net/inaddr_st.h \ src/lib/net/nettypes.h \ + src/lib/net/network_sys.h \ src/lib/net/resolve.h \ src/lib/net/socket.h \ src/lib/net/socketpair.h \ diff --git a/src/lib/net/network_sys.c b/src/lib/net/network_sys.c new file mode 100644 index 0000000000..ac49288ee6 --- /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 +subsys_network_initialize(void) +{ + if (network_init() < 0) + return -1; + + return 0; +} + +static void +subsys_network_shutdown(void) +{ +#ifdef _WIN32 + WSACleanup(); +#endif + tor_free_getaddrinfo_cache(); +} + +const subsys_fns_t sys_network = { + .name = "network", + .level = -90, + .supported = true, + .initialize = subsys_network_initialize, + .shutdown = subsys_network_shutdown, +}; diff --git a/src/lib/net/network_sys.h b/src/lib/net/network_sys.h new file mode 100644 index 0000000000..62b778bb66 --- /dev/null +++ b/src/lib/net/network_sys.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file log_network.h + * \brief Declare subsystem object for the network module. + **/ + +#ifndef TOR_NETWORK_SYS_H +#define TOR_NETWORK_SYS_H + +extern const struct subsys_fns_t sys_network; + +#endif /* !defined(TOR_NETWORK_SYS_H) */ |