commit 6a06f45b04b8c9336ff150d299732c67bb5cb885 Author: Sebastian Hahn sebastian@torproject.org Date: Tue Aug 16 01:38:15 2011 +0200
Actually pick a random port when "auto" is specified
ddc65e2b3303559ab7b842a176ee6c2eda9e4027 had broken this --- src/common/torint.h | 9 +++++++++ src/or/connection.c | 4 +++- 2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/src/common/torint.h b/src/common/torint.h index 0b5c29a..af97547 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -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 diff --git a/src/or/connection.c b/src/or/connection.c index 2087ced..452ddc1 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -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);
tor-commits@lists.torproject.org