[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Make windows version correct; initialize windows foolishnes...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Make windows version correct; initialize windows foolishnes...
- From: nickm@seul.org (Nick Mathewson)
- Date: Wed, 10 Mar 2004 01:26:40 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Wed, 10 Mar 2004 01:27:02 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv1624/or
Modified Files:
main.c
Log Message:
Make windows version correct; initialize windows foolishness so that gethostbyname works.
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.195
retrieving revision 1.196
diff -u -d -r1.195 -r1.196
--- main.c 8 Mar 2004 01:19:57 -0000 1.195
+++ main.c 10 Mar 2004 06:26:38 -0000 1.196
@@ -694,12 +694,42 @@
log(severity,"Average bandwidth used: %d bytes/sec",
(int) (stats_n_bytes_read/stats_n_seconds_reading));
}
+
+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;
+ }
+ /* XXXX We should call WSACleanup on exit, I think. */
+#endif
+ return 0;
+}
+
+void exit_function(void)
+{
+#ifdef MS_WINDOWS
+ WSACleanup();
+#endif
+}
int tor_main(int argc, char *argv[]) {
/* give it somewhere to log to initially */
add_stream_log(LOG_INFO, "<stdout>", stdout);
log_fn(LOG_WARN,"Tor v%s. This is experimental software. Do not use it if you need anonymity.",VERSION);
+
+ if (network_init()<0) {
+ log_fn(LOG_ERR,"Error initializing network; exiting.");
+ return 1;
+ }
+ atexit(exit_function);
if (init_from_config(argc,argv) < 0)
return -1;
@@ -707,8 +737,8 @@
#ifndef MS_WINDOWS
if(geteuid()==0)
log_fn(LOG_WARN,"You are running Tor as root. You don't need to, and you probably shouldn't.");
-#endif
-
+#endif
+
if(options.ORPort) { /* only spawn dns handlers if we're a router */
dns_init(); /* initialize the dns resolve tree, and spawn workers */
}