cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH 1/2] connect: avoid skipping an IPv4 address

From: Kamil Dudka <kdudka_at_redhat.com>
Date: Mon, 16 Feb 2015 17:52:07 +0100

... in case the protocol versions are mixed in a DNS response
(IPv6 -> IPv4 -> IPv6).

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1187531#c3

---
 lib/connect.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/connect.c b/lib/connect.c
index 32888e6..61b1808 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -542,6 +542,7 @@ static CURLcode trynextip(struct connectdata *conn,
                           int sockindex,
                           int tempindex)
 {
+  const int other = tempindex ^ 1;
   CURLcode result = CURLE_COULDNT_CONNECT;
 
   /* First clean up after the failed socket.
@@ -572,8 +573,11 @@ static CURLcode trynextip(struct connectdata *conn,
     }
 
     while(ai) {
-      while(ai && ai->ai_family != family)
-        ai = ai->ai_next;
+      if(conn->tempaddr[other]) {
+        /* we can safely skip addresses of the other protocol family */
+        while(ai && ai->ai_family != family)
+          ai = ai->ai_next;
+      }
 
       if(ai) {
         result = singleipconnect(conn, ai, &conn->tempsock[tempindex]);
-- 
2.1.0
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-02-16