only bind the socket on connect when a local address has been provided; reported by Ajejo Sanchez

svn:r946
This commit is contained in:
Niels Provos 2008-11-15 05:27:23 +00:00
parent 31cfe52662
commit 50202d757d
2 changed files with 15 additions and 6 deletions

View File

@ -126,6 +126,7 @@ Changes in current version:
o Add new utility functions to correctly observe and log winsock errors. o Add new utility functions to correctly observe and log winsock errors.
o Do not remove Accept-Encoding header o Do not remove Accept-Encoding header
o Clear the timer cache on entering the event loop; reported by Victor Chang 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: Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.

20
http.c
View File

@ -2846,8 +2846,8 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
*pport = mm_strdup(strport); *pport = mm_strdup(strport);
} }
/* Either connect or bind */ /* Create a non-blocking socket and bind it */
/* todo: rename this function */
static evutil_socket_t static evutil_socket_t
bind_socket_ai(struct addrinfo *ai, int reuse) bind_socket_ai(struct addrinfo *ai, int reuse)
{ {
@ -2879,9 +2879,11 @@ bind_socket_ai(struct addrinfo *ai, int reuse)
(void *)&on, sizeof(on)); (void *)&on, sizeof(on));
} }
r = bind(fd, ai->ai_addr, ai->ai_addrlen); if (ai != NULL) {
if (r == -1) r = bind(fd, ai->ai_addr, ai->ai_addrlen);
goto out; if (r == -1)
goto out;
}
return (fd); return (fd);
@ -2934,7 +2936,13 @@ static evutil_socket_t
bind_socket(const char *address, ev_uint16_t port, int reuse) bind_socket(const char *address, ev_uint16_t port, int reuse)
{ {
evutil_socket_t fd; 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) if (aitop == NULL)
return (-1); return (-1);