Change interface of parse_addr_port() to return address in host order, since most users seem to want that.

svn:r2542
This commit is contained in:
Nick Mathewson 2004-10-16 21:53:30 +00:00
parent 8300c4ae6a
commit 47dc024f7e
4 changed files with 8 additions and 6 deletions

View File

@ -2066,7 +2066,7 @@ int tor_lookup_hostname(const char *name, uint32_t *addr)
* <b>address</b> is provided, set *<b>address</b> to a copy of the * <b>address</b> is provided, set *<b>address</b> to a copy of the
* host portion of the string. If <b>addr</b> is provided, try to * host portion of the string. If <b>addr</b> is provided, try to
* resolve the host portion of the string and store it into * resolve the host portion of the string and store it into
* *<b>addr</b> (in network byte order). If <b>port</b> is provided, * *<b>addr</b> (in host byte order). If <b>port</b> is provided,
* store the port number into *<b>port</b>, or 0 if no port is given. * store the port number into *<b>port</b>, or 0 if no port is given.
* Return 0 on success, -1 on failure. * Return 0 on success, -1 on failure.
*/ */
@ -2102,6 +2102,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
ok = 0; ok = 0;
*addr = 0; *addr = 0;
} }
*addr = ntohl(*addr);
} }
if (address && ok) { if (address && ok) {

View File

@ -847,7 +847,6 @@ getconfig(int argc, char **argv, or_options_t *options)
log(LOG_WARN,"HttpProxy failed to parse or resolve. Please fix."); log(LOG_WARN,"HttpProxy failed to parse or resolve. Please fix.");
result = -1; result = -1;
} }
options->HttpProxyAddr = ntohl(options->HttpProxyAddr); /* switch to host-order */
if (options->HttpProxyPort == 0) { /* give it a default */ if (options->HttpProxyPort == 0) { /* give it a default */
options->HttpProxyPort = 80; options->HttpProxyPort = 80;
} }

View File

@ -317,17 +317,19 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
struct sockaddr_in bindaddr; /* where to bind */ struct sockaddr_in bindaddr; /* where to bind */
connection_t *conn; connection_t *conn;
uint16_t usePort; uint16_t usePort;
uint32_t addr;
int s; /* the socket we're going to make */ int s; /* the socket we're going to make */
int one=1; int one=1;
memset(&bindaddr,0,sizeof(struct sockaddr_in)); memset(&bindaddr,0,sizeof(struct sockaddr_in));
if (parse_addr_port(bindaddress, NULL, &(bindaddr.sin_addr.s_addr), if (parse_addr_port(bindaddress, NULL, &addr, &usePort)<0) {
&usePort)<0) {
log_fn(LOG_WARN, "Error parsing/resolving BindAddress %s",bindaddress); log_fn(LOG_WARN, "Error parsing/resolving BindAddress %s",bindaddress);
return -1; return -1;
} }
if (usePort==0) if (usePort==0)
usePort = bindport; usePort = bindport;
binaddrr.sin_addr.s_addr = htonl(addr);
bindaddr.sin_family = AF_INET; bindaddr.sin_family = AF_INET;
bindaddr.sin_port = htons((uint16_t) usePort); bindaddr.sin_port = htons((uint16_t) usePort);

View File

@ -165,13 +165,13 @@ static rend_service_port_config_t *parse_port_config(const char *string)
log_fn(LOG_WARN, "Port out of range"); log_fn(LOG_WARN, "Port out of range");
return NULL; 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 = tor_malloc(sizeof(rend_service_port_config_t));
result->virtual_port = virtport; result->virtual_port = virtport;
result->real_port = realport; result->real_port = realport;
result->real_address = ntohl(addr); result->real_address = addr;
return result; return result;
} }