connect: avoid skipping an IPv4 address

... 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
This commit is contained in:
Kamil Dudka 2015-02-16 17:00:05 +01:00
parent 5d87b1f22c
commit 92835ca5d8
1 changed files with 6 additions and 2 deletions

View File

@ -542,6 +542,7 @@ static CURLcode trynextip(struct connectdata *conn,
int sockindex, int sockindex,
int tempindex) int tempindex)
{ {
const int other = tempindex ^ 1;
CURLcode result = CURLE_COULDNT_CONNECT; CURLcode result = CURLE_COULDNT_CONNECT;
/* First clean up after the failed socket. /* First clean up after the failed socket.
@ -572,8 +573,11 @@ static CURLcode trynextip(struct connectdata *conn,
} }
while(ai) { while(ai) {
while(ai && ai->ai_family != family) if(conn->tempaddr[other]) {
ai = ai->ai_next; /* we can safely skip addresses of the other protocol family */
while(ai && ai->ai_family != family)
ai = ai->ai_next;
}
if(ai) { if(ai) {
result = singleipconnect(conn, ai, &conn->tempsock[tempindex]); result = singleipconnect(conn, ai, &conn->tempsock[tempindex]);