[or-cvs] move network_init to compat.c from main.c

Roger Dingledine arma at seul.org
Fri Feb 4 07:16:13 UTC 2005


Update of /home2/or/cvsroot/tor/src/common
In directory moria.mit.edu:/home2/arma/work/onion/0091/tor/src/common

Modified Files:
      Tag: tor-0_0_9-patches
	compat.c compat.h 
Log Message:
move network_init to compat.c from main.c
so we can call it from tor-resolve.c


Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.22.2.7
retrieving revision 1.22.2.8
diff -u -d -r1.22.2.7 -r1.22.2.8
--- compat.c	4 Feb 2005 01:00:12 -0000	1.22.2.7
+++ compat.c	4 Feb 2005 07:16:10 -0000	1.22.2.8
@@ -732,3 +732,23 @@
   return strerror(e);
 }
 #endif
+
+/** 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 MS_WINDOWS
+  /* This silly exercise is necessary before windows will allow gethostbyname to work.
+   */
+  WSADATA WSAData;
+  int r;
+  r = WSAStartup(0x101,&WSAData);
+  if (r) {
+    log_fn(LOG_WARN,"Error initializing windows network layer: code was %d",r);
+    return -1;
+  }
+#endif
+  return 0;
+}
+

Index: compat.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.13.2.6
retrieving revision 1.13.2.7
diff -u -d -r1.13.2.6 -r1.13.2.7
--- compat.h	4 Feb 2005 01:00:12 -0000	1.13.2.6
+++ compat.h	4 Feb 2005 07:16:10 -0000	1.13.2.7
@@ -194,6 +194,8 @@
 void tor_mutex_release(tor_mutex_t *m);
 void tor_mutex_free(tor_mutex_t *m);
 
+int network_init(void);
+
 #ifdef MS_WINDOWS
 #define TOR_IS_MULTITHREADED 1
 #else



More information about the tor-commits mailing list