X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fconnect.c;h=28ce204347ab552f052f7bd01732ba8499d7c84d;hp=175db605121680096a549a5d1f9cf4e3c5c458b3;hb=1396b300550d9b5ca3b4b3e4e3776a1456024f73;hpb=2fbb4936a0f1bb4c79eb0a896115e1d8f495aad5 diff --git a/src/connect.c b/src/connect.c index 175db605..28ce2043 100644 --- a/src/connect.c +++ b/src/connect.c @@ -87,6 +87,14 @@ make_connection (int *sock, char *hostname, unsigned short port) if ((*sock = socket (AF_INET, SOCK_STREAM, 0)) == -1) return CONSOCKERR; + if (opt.bind_address != NULL) + { + /* Bind the client side to the requested address. */ + if (bind (*sock, (struct sockaddr *) opt.bind_address, + sizeof (*opt.bind_address))) + return CONSOCKERR; + } + /* Connect the socket to the remote host. */ if (connect (*sock, (struct sockaddr *) &sock_name, sizeof (sock_name))) { @@ -118,8 +126,15 @@ bindport (unsigned short *port) if (setsockopt (msock, SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof (optval)) < 0) return CONSOCKERR; - srv.sin_family = AF_INET; - srv.sin_addr.s_addr = htonl (INADDR_ANY); + + if (opt.bind_address == NULL) + { + srv.sin_family = AF_INET; + srv.sin_addr.s_addr = htonl (INADDR_ANY); + } + else + srv = *opt.bind_address; + srv.sin_port = htons (*port); if (bind (msock, addr, sizeof (struct sockaddr_in)) < 0) {