]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Delay getsockname() call until after connect() is done
authorNick Mathewson <nickm@torproject.org>
Thu, 24 May 2012 20:57:36 +0000 (16:57 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 24 May 2012 20:57:36 +0000 (16:57 -0400)
On Windows, getsockname() on a nonblocking apparently won't work
until the connection is done connecting.  On XP, it seems to fail by
reporting success and declaring that your address is INADDR_ANY.  On the
Win8 preview, though, it fails more loudly and says WSAEINVAL.

Fix for bug 5374; bugfix on 0.1.1.14-alpha.

changes/bug5374 [new file with mode: 0644]
src/or/connection.c

diff --git a/changes/bug5374 b/changes/bug5374
new file mode 100644 (file)
index 0000000..926a074
--- /dev/null
@@ -0,0 +1,7 @@
+  o Minor bugfixes:
+
+    - Don't check for whether the address we're using for outbound
+      connections has changed until after the outbound connection has
+      completed. On Windows, getsockname() doesn't succeed until the
+      connection is finished. Fix for bug 5374; bugfix on
+      0.1.1.14-alpha.
index dc75601ab492e8d636923d29b3ca238f1e6f743a..96f8d458ad9f761f7ecb74921fc35cfb0104c9e6 100644 (file)
@@ -1393,9 +1393,6 @@ connection_connect(connection_t *conn, const char *address,
     }
   }
 
-  if (!server_mode(options))
-    client_check_address_changed(s);
-
   /* it succeeded. we're connected. */
   log_fn(inprogress?LOG_DEBUG:LOG_INFO, LD_NET,
          "Connection to %s:%u %s (sock %d).",
@@ -3434,6 +3431,14 @@ static int
 connection_finished_connecting(connection_t *conn)
 {
   tor_assert(conn);
+
+  if (!server_mode(get_options())) {
+    /* See whether getsockname() says our address changed.  We need to do this
+     * now that the connection has finished, because getsockname() on Windows
+     * won't work until then. */
+    client_check_address_changed(conn->s);
+  }
+
   switch (conn->type)
     {
     case CONN_TYPE_OR: