Commit cd0c18be authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

wininet: Support IPv6 in GetAddress.

parent 78b81323
...@@ -178,14 +178,23 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort, ...@@ -178,14 +178,23 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
memset( &hints, 0, sizeof(struct addrinfo) ); memset( &hints, 0, sizeof(struct addrinfo) );
/* Prefer IPv4 to IPv6 addresses, since some servers do not listen on
* their IPv6 addresses even though they have IPv6 addresses in the DNS.
*/
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
ret = getaddrinfo( name, NULL, &hints, &res ); ret = getaddrinfo( name, NULL, &hints, &res );
HeapFree( GetProcessHeap(), 0, name ); HeapFree( GetProcessHeap(), 0, name );
if (ret != 0) if (ret != 0)
{ {
TRACE("failed to get address of %s (%s)\n", debugstr_w(lpszServerName), gai_strerror(ret)); TRACE("failed to get IPv4 address of %s (%s), retrying with IPv6\n", debugstr_w(lpszServerName), gai_strerror(ret));
return FALSE; hints.ai_family = AF_INET6;
ret = getaddrinfo( name, NULL, &hints, &res );
if (ret != 0)
{
TRACE("failed to get address of %s (%s)\n", debugstr_w(lpszServerName), gai_strerror(ret));
return FALSE;
}
} }
if (*sa_len < res->ai_addrlen) if (*sa_len < res->ai_addrlen)
{ {
...@@ -201,6 +210,9 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort, ...@@ -201,6 +210,9 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
case AF_INET: case AF_INET:
((struct sockaddr_in *)psa)->sin_port = htons(nServerPort); ((struct sockaddr_in *)psa)->sin_port = htons(nServerPort);
break; break;
case AF_INET6:
((struct sockaddr_in6 *)psa)->sin6_port = htons(nServerPort);
break;
} }
freeaddrinfo( res ); freeaddrinfo( res );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment