Actually pick a random port when "auto" is specified

ddc65e2b33 had broken this
This commit is contained in:
Sebastian Hahn
2011-08-16 01:38:15 +02:00
committed by Nick Mathewson
parent 2dc40b9c49
commit 6a06f45b04
2 changed files with 12 additions and 1 deletions
+9
View 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
+3 -1
View 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);