From: Niels Provos Date: Sat, 15 Nov 2008 05:27:23 +0000 (+0000) Subject: only bind the socket on connect when a local address has been provided; reported... X-Git-Tag: release-2.0.1-alpha~219 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50202d757d719316f5d6d92d1fb6941fcef66b72;p=libevent only bind the socket on connect when a local address has been provided; reported by Ajejo Sanchez svn:r946 --- diff --git a/ChangeLog b/ChangeLog index fbe24670..cbf18157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -126,6 +126,7 @@ Changes in current version: o Add new utility functions to correctly observe and log winsock errors. o Do not remove Accept-Encoding header o Clear the timer cache on entering the event loop; reported by Victor Chang + o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez Changes in 1.4.0: o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. diff --git a/http.c b/http.c index 202d798c..6f1e0b0e 100644 --- a/http.c +++ b/http.c @@ -2846,8 +2846,8 @@ name_from_addr(struct sockaddr *sa, socklen_t salen, *pport = mm_strdup(strport); } -/* Either connect or bind */ - +/* Create a non-blocking socket and bind it */ +/* todo: rename this function */ static evutil_socket_t bind_socket_ai(struct addrinfo *ai, int reuse) { @@ -2879,9 +2879,11 @@ bind_socket_ai(struct addrinfo *ai, int reuse) (void *)&on, sizeof(on)); } - r = bind(fd, ai->ai_addr, ai->ai_addrlen); - if (r == -1) - goto out; + if (ai != NULL) { + r = bind(fd, ai->ai_addr, ai->ai_addrlen); + if (r == -1) + goto out; + } return (fd); @@ -2934,7 +2936,13 @@ static evutil_socket_t bind_socket(const char *address, ev_uint16_t port, int reuse) { evutil_socket_t fd; - struct addrinfo *aitop = make_addrinfo(address, port); + struct addrinfo *aitop = NULL; + + /* just create an unbound socket */ + if (address == NULL && port == 0) + return bind_socket_ai(NULL, 0); + + aitop = make_addrinfo(address, port); if (aitop == NULL) return (-1);