]> granicus.if.org Git - libevent/commitdiff
only bind the socket on connect when a local address has been provided; reported...
authorNiels Provos <provos@gmail.com>
Sat, 15 Nov 2008 05:27:23 +0000 (05:27 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 15 Nov 2008 05:27:23 +0000 (05:27 +0000)
svn:r946

ChangeLog
http.c

index fbe24670aced737d9a7acea4a8ad6454a1013385..cbf18157cbcfa0490e5b573ff08e4c55b389ff28 100644 (file)
--- 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 202d798cbed90050253faa7dcd81d63110a46ae1..6f1e0b0ea73a02711cb98e865b234634ee27b4c1 100644 (file)
--- 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);