aboutsummaryrefslogtreecommitdiff
path: root/src/lib/net
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-28 11:59:16 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-28 11:59:16 -0400
commit042df08693521a7cba990489fa03547a6e3fec4c (patch)
tree14f10cd22e674fde4ef4c0ee55fe6054483afb89 /src/lib/net
parentdb1a420c4eab3fbb6dc02e9653bf21664b9bdf33 (diff)
downloadtor-042df08693521a7cba990489fa03547a6e3fec4c.tar.gz
tor-042df08693521a7cba990489fa03547a6e3fec4c.zip
Move network_init to lib/net
Diffstat (limited to 'src/lib/net')
-rw-r--r--src/lib/net/socket.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/net/socket.c b/src/lib/net/socket.c
index ae384bcd47..dc3d1531ff 100644
--- a/src/lib/net/socket.c
+++ b/src/lib/net/socket.c
@@ -25,6 +25,34 @@
#include <stddef.h>
#include <string.h>
+/** Called before we make any calls to network-related functions.
+ * (Some operating systems require their network libraries to be
+ * initialized.) */
+int
+network_init(void)
+{
+#ifdef _WIN32
+ /* This silly exercise is necessary before windows will allow
+ * gethostbyname to work. */
+ WSADATA WSAData;
+ int r;
+ r = WSAStartup(0x101,&WSAData);
+ if (r) {
+ log_warn(LD_NET,"Error initializing windows network layer: code was %d",r);
+ return -1;
+ }
+ if (sizeof(SOCKET) != sizeof(tor_socket_t)) {
+ log_warn(LD_BUG,"The tor_socket_t type does not match SOCKET in size; Tor "
+ "might not work. (Sizes are %d and %d respectively.)",
+ (int)sizeof(tor_socket_t), (int)sizeof(SOCKET));
+ }
+ /* WSAData.iMaxSockets might show the max sockets we're allowed to use.
+ * We might use it to complain if we're trying to be a server but have
+ * too few sockets available. */
+#endif /* defined(_WIN32) */
+ return 0;
+}
+
/* When set_max_file_sockets() is called, update this with the max file
* descriptor value so we can use it to check the limit when opening a new
* socket. Default value is what Debian sets as the default hard limit. */