From 3a59e8310a6d9dee232ad74da8379be64b71d515 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 19 Aug 2010 03:26:18 +0000 Subject: [PATCH] * If there are multiple IP addresses available for a host, sock_connect() now tries all of them. This includes IPv6/IPv4. --- citadel/clientsocket.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index c5d948565..0d2da5a5a 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -95,18 +95,22 @@ int sock_connect(char *host, char *service) return(-1); } - rc = connect(sock, res->ai_addr, res->ai_addrlen); - if (rc < 0) { - /* - * Note: the res is a linked list of addresses found for server. - * If the connect() fails to the first one, subsequent addresses - * (if any) in the list could be tried if desired. - */ - CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno)); - return(-1); + /* + * Try all available addresses until we connect to one or until we run out. + */ + struct addrinfo *ai; + for (ai = res; ai != NULL; ai = ai->ai_next) { + /* FIXME display the address to which we are trying to connect */ + rc = connect(sock, res->ai_addr, res->ai_addrlen); + if (rc >= 0) { + return(sock); + } + else { + CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno)); + } } - return (sock); + return(-1); } -- 2.39.2