wininet: Use GetAddrInfoW in GetAddress.
This commit is contained in:
parent
11d09f1fe7
commit
100bd11ae5
|
@ -125,20 +125,12 @@ time_t ConvertTimeString(LPCWSTR asctime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
BOOL GetAddress(const WCHAR *name, INTERNET_PORT port, struct sockaddr *psa, socklen_t *sa_len)
|
||||||
struct sockaddr *psa, socklen_t *sa_len)
|
|
||||||
{
|
{
|
||||||
struct addrinfo *res, hints;
|
ADDRINFOW *res, hints;
|
||||||
char *name;
|
|
||||||
int sz;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
TRACE("%s\n", debugstr_w(lpszServerName));
|
TRACE("%s\n", debugstr_w(name));
|
||||||
|
|
||||||
sz = WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, -1, NULL, 0, NULL, NULL );
|
|
||||||
if (!(name = heap_alloc(sz + 1))) return FALSE;
|
|
||||||
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, -1, name, sz, NULL, NULL );
|
|
||||||
name[sz] = 0;
|
|
||||||
|
|
||||||
memset( &hints, 0, sizeof(hints) );
|
memset( &hints, 0, sizeof(hints) );
|
||||||
/* Prefer IPv4 to IPv6 addresses, since some servers do not listen on
|
/* Prefer IPv4 to IPv6 addresses, since some servers do not listen on
|
||||||
|
@ -146,23 +138,22 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
||||||
*/
|
*/
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
|
|
||||||
ret = getaddrinfo( name, NULL, &hints, &res );
|
ret = GetAddrInfoW(name, NULL, &hints, &res);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
TRACE("failed to get IPv4 address of %s, retrying with IPv6\n", debugstr_w(lpszServerName));
|
TRACE("failed to get IPv4 address of %s, retrying with IPv6\n", debugstr_w(name));
|
||||||
hints.ai_family = AF_INET6;
|
hints.ai_family = AF_INET6;
|
||||||
ret = getaddrinfo( name, NULL, &hints, &res );
|
ret = GetAddrInfoW(name, NULL, &hints, &res);
|
||||||
}
|
}
|
||||||
heap_free( name );
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
TRACE("failed to get address of %s\n", debugstr_w(lpszServerName));
|
TRACE("failed to get address of %s\n", debugstr_w(name));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (*sa_len < res->ai_addrlen)
|
if (*sa_len < res->ai_addrlen)
|
||||||
{
|
{
|
||||||
WARN("address too small\n");
|
WARN("address too small\n");
|
||||||
freeaddrinfo( res );
|
FreeAddrInfoW(res);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
*sa_len = res->ai_addrlen;
|
*sa_len = res->ai_addrlen;
|
||||||
|
@ -171,14 +162,14 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
||||||
switch (res->ai_family)
|
switch (res->ai_family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
((struct sockaddr_in *)psa)->sin_port = htons(nServerPort);
|
((struct sockaddr_in *)psa)->sin_port = htons(port);
|
||||||
break;
|
break;
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
((struct sockaddr_in6 *)psa)->sin6_port = htons(nServerPort);
|
((struct sockaddr_in6 *)psa)->sin6_port = htons(port);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo( res );
|
FreeAddrInfoW(res);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue