diff --git a/src/common/util.c b/src/common/util.c index 244eb11b4d..39c7311e6b 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2066,7 +2066,7 @@ int tor_lookup_hostname(const char *name, uint32_t *addr) * address is provided, set *address to a copy of the * host portion of the string. If addr is provided, try to * resolve the host portion of the string and store it into - * *addr (in network byte order). If port is provided, + * *addr (in host byte order). If port is provided, * store the port number into *port, or 0 if no port is given. * Return 0 on success, -1 on failure. */ @@ -2102,6 +2102,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr, ok = 0; *addr = 0; } + *addr = ntohl(*addr); } if (address && ok) { diff --git a/src/or/config.c b/src/or/config.c index 41ccd56bd3..dea2b62527 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -847,7 +847,6 @@ getconfig(int argc, char **argv, or_options_t *options) log(LOG_WARN,"HttpProxy failed to parse or resolve. Please fix."); result = -1; } - options->HttpProxyAddr = ntohl(options->HttpProxyAddr); /* switch to host-order */ if (options->HttpProxyPort == 0) { /* give it a default */ options->HttpProxyPort = 80; } diff --git a/src/or/connection.c b/src/or/connection.c index 971ff370a4..87cb3c10d9 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -317,17 +317,19 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport struct sockaddr_in bindaddr; /* where to bind */ connection_t *conn; uint16_t usePort; + uint32_t addr; int s; /* the socket we're going to make */ int one=1; memset(&bindaddr,0,sizeof(struct sockaddr_in)); - if (parse_addr_port(bindaddress, NULL, &(bindaddr.sin_addr.s_addr), - &usePort)<0) { + if (parse_addr_port(bindaddress, NULL, &addr, &usePort)<0) { log_fn(LOG_WARN, "Error parsing/resolving BindAddress %s",bindaddress); return -1; } + if (usePort==0) usePort = bindport; + binaddrr.sin_addr.s_addr = htonl(addr); bindaddr.sin_family = AF_INET; bindaddr.sin_port = htons((uint16_t) usePort); diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 090a3a7cf9..2c86b4385f 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -165,13 +165,13 @@ static rend_service_port_config_t *parse_port_config(const char *string) log_fn(LOG_WARN, "Port out of range"); return NULL; } - addr = htonl(0x7F000001u); /* Default to 127.0.0.1 */ + addr = 0x7F000001u; /* Default to 127.0.0.1 */ } result = tor_malloc(sizeof(rend_service_port_config_t)); result->virtual_port = virtport; result->real_port = realport; - result->real_address = ntohl(addr); + result->real_address = addr; return result; }