From 65ef313cc4601b5ad84d1da1800ff38bf8f046a9 Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Tue, 17 Nov 2009 02:40:36 +0530 Subject: Pass address family when binding to outgoing socket --- src/sock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sock.c b/src/sock.c index bf32c78..f7ddd74 100644 --- a/src/sock.c +++ b/src/sock.c @@ -39,7 +39,8 @@ * returned if the bind succeeded. Otherwise, -1 is returned * to indicate an error. */ -static int bind_socket (int sockfd, const char *addr) +static int +bind_socket (int sockfd, const char *addr, int family) { struct addrinfo hints, *res, *ressave; @@ -47,7 +48,7 @@ static int bind_socket (int sockfd, const char *addr) assert (addr != NULL && strlen (addr) != 0); memset (&hints, 0, sizeof (struct addrinfo)); - hints.ai_family = AF_UNSPEC; + hints.ai_family = family; hints.ai_socktype = SOCK_STREAM; /* The local port it not important */ @@ -105,12 +106,14 @@ int opensock (const char *host, int port, const char *bind_to) /* Bind to the specified address */ if (bind_to) { - if (bind_socket (sockfd, bind_to) < 0) { + if (bind_socket (sockfd, bind_to, + res->ai_family) < 0) { close (sockfd); continue; /* can't bind, so try again */ } } else if (config.bind_address) { - if (bind_socket (sockfd, config.bind_address) < 0) { + if (bind_socket (sockfd, config.bind_address, + res->ai_family) < 0) { close (sockfd); continue; /* can't bind, so try again */ } -- cgit v1.2.3