]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
connect: avoid skipping an IPv4 address
authorKamil Dudka <kdudka@redhat.com>
Mon, 16 Feb 2015 16:00:05 +0000 (17:00 +0100)
committerKamil Dudka <kdudka@redhat.com>
Mon, 23 Feb 2015 12:31:01 +0000 (13:31 +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

index 32888e653173238124463f2b59eabd39bbe41746..61b180825a20c6276f615eb85f6056d5fabace9e 100644 (file)
@@ -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]);