]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Actually pick a random port when "auto" is specified
authorSebastian Hahn <sebastian@torproject.org>
Mon, 15 Aug 2011 23:38:15 +0000 (01:38 +0200)
committerNick Mathewson <nickm@torproject.org>
Wed, 17 Aug 2011 14:41:36 +0000 (10:41 -0400)
ddc65e2b3303559ab7b842a176ee6c2eda9e4027 had broken this

src/common/torint.h
src/or/connection.c

index 0b5c29adc009d7382fc2e14a972157e154710543..af975471f1c36e4207e1e9b7b9639ebee0767ce4 100644 (file)
@@ -111,6 +111,15 @@ typedef signed int int32_t;
 typedef unsigned int uint32_t;
 #define HAVE_UINT32_T
 #endif
+#ifndef UINT16_MAX
+#define UINT16_MAX 0xffffu
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX 0x7fff
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-INT16_MAX-1)
+#endif
 #ifndef UINT32_MAX
 #define UINT32_MAX 0xffffffffu
 #endif
index 2087ceda4a1dda66a81b2ef6a5450b8b8ba3f266..452ddc1895941648010466e0402ae8889b72f079 100644 (file)
@@ -1787,6 +1787,8 @@ retry_listener_ports(smartlist_t *old_conns,
     socklen_t listensocklen = 0;
     char *address=NULL;
     connection_t *conn;
+    int real_port = port->port == CFG_AUTO_PORT ? 0 : port->port;
+    tor_assert(real_port <= UINT16_MAX);
 
     if (port->is_unix_addr) {
       listensockaddr = (struct sockaddr *)
@@ -1795,7 +1797,7 @@ retry_listener_ports(smartlist_t *old_conns,
     } else {
       listensockaddr = tor_malloc(sizeof(struct sockaddr_storage));
       listensocklen = tor_addr_to_sockaddr(&port->addr,
-                                           port->port,
+                                           real_port,
                                            listensockaddr,
                                            sizeof(struct sockaddr_storage));
       address = tor_dup_addr(&port->addr);