[tor-commits] [tor/master] Under Windows, call WSAStartup before using the network
nickm at torproject.org
nickm at torproject.org
Tue Aug 30 19:58:36 UTC 2011
commit 2002d4acdfac823c03cca3ed92de7f60b3272d86
Author: Steven Murdoch <Steven.Murdoch at cl.cam.ac.uk>
Date: Thu Jul 21 14:14:57 2011 +0100
Under Windows, call WSAStartup before using the network
---
src/tools/tor-fw-helper/tor-fw-helper.c | 33 ++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/src/tools/tor-fw-helper/tor-fw-helper.c b/src/tools/tor-fw-helper/tor-fw-helper.c
index 20d60d7..926fa61 100644
--- a/src/tools/tor-fw-helper/tor-fw-helper.c
+++ b/src/tools/tor-fw-helper/tor-fw-helper.c
@@ -13,6 +13,7 @@
* later date.
*/
+#include "orconfig.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -20,7 +21,10 @@
#include <time.h>
#include <string.h>
-#include "orconfig.h"
+#ifdef MS_WINDOWS
+#include <winsock2.h>
+#endif
+
#include "tor-fw-helper.h"
#ifdef NAT_PMP
#include "tor-fw-helper-natpmp.h"
@@ -219,6 +223,29 @@ tor_fw_add_dir_port(tor_fw_options_t *tor_fw_options,
}
}
+/** Called before we make any calls to network-related functions.
+ * (Some operating systems require their network libraries to be
+ * initialized.) (from common/compat.c) */
+static int
+network_init(void)
+{
+#ifdef MS_WINDOWS
+ /* This silly exercise is necessary before windows will allow
+ * gethostbyname to work. */
+ WSADATA WSAData;
+ int r;
+ r = WSAStartup(0x101, &WSAData);
+ if (r) {
+ fprintf(stderr, "E: Error initializing Windows network layer - code was %d", r);
+ return -1;
+ }
+ /* 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
+ return 0;
+}
+
int
main(int argc, char **argv)
{
@@ -329,6 +356,10 @@ main(int argc, char **argv)
tor_fw_options.public_dir_port);
}
+ // Initialize networking
+ if (network_init())
+ exit(1);
+
// Initalize the various fw-helper backend helpers
r = init_backends(&tor_fw_options, &backend_state);
if (r)
More information about the tor-commits
mailing list