diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-07-14 22:56:17 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-07-14 22:56:17 +0000 |
commit | e94f95a7160dcc9a064ce0159c063e8f44095a7d (patch) | |
tree | 936efac60eea87d29f7727f717e784369ccf214f /src | |
parent | c2abcc4f1c8f63549f74b202b9581f631b470152 (diff) | |
download | tor-e94f95a7160dcc9a064ce0159c063e8f44095a7d.tar.gz tor-e94f95a7160dcc9a064ce0159c063e8f44095a7d.zip |
Populate address field of listeners with an actually sane value.
svn:r4564
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 64424d00f4..ec710a6c2d 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -454,6 +454,7 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport, int type) { struct sockaddr_in bindaddr; /* where to bind */ + char *address = NULL; connection_t *conn; uint16_t usePort; uint32_t addr; @@ -463,7 +464,7 @@ connection_create_listener(const char *bindaddress, uint16_t bindport, int type) #endif memset(&bindaddr,0,sizeof(struct sockaddr_in)); - if (parse_addr_port(bindaddress, NULL, &addr, &usePort)<0) { + if (parse_addr_port(bindaddress, &address, &addr, &usePort)<0) { log_fn(LOG_WARN, "Error parsing/resolving BindAddress %s",bindaddress); return -1; } @@ -477,11 +478,11 @@ connection_create_listener(const char *bindaddress, uint16_t bindport, int type) s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); if (s < 0) { log_fn(LOG_WARN,"Socket creation failed."); - return -1; + goto err; } else if (!SOCKET_IS_POLLABLE(s)) { log_fn(LOG_WARN,"Too many connections; can't create pollable listener."); tor_close_socket(s); - return -1; + goto err; } #ifndef MS_WINDOWS @@ -495,26 +496,27 @@ connection_create_listener(const char *bindaddress, uint16_t bindport, int type) if (bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) { log_fn(LOG_WARN,"Could not bind to port %u: %s",usePort, tor_socket_strerror(tor_socket_errno(s))); - return -1; + goto err; } if (listen(s,SOMAXCONN) < 0) { log_fn(LOG_WARN,"Could not listen on port %u: %s",usePort, tor_socket_strerror(tor_socket_errno(s))); - return -1; + goto err; } set_socket_nonblocking(s); conn = connection_new(type); conn->s = s; - conn->address = tor_strdup(bindaddress); + conn->address = address; + address = NULL; conn->port = usePort; if (connection_add(conn) < 0) { /* no space, forget it */ log_fn(LOG_WARN,"connection_add failed. Giving up."); connection_free(conn); - return -1; + goto err; } log_fn(LOG_DEBUG,"%s listening on port %u.",conn_type_to_string(type), usePort); @@ -523,6 +525,10 @@ connection_create_listener(const char *bindaddress, uint16_t bindport, int type) connection_start_reading(conn); return 0; + + err: + tor_free(address); + return -1; } /** Do basic sanity checking on a newly received socket. Return 0 |