ws2_32: Also check the FQDN when injecting the local IP.
Signed-off-by: Stefan Dösinger <stefan@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
72b9265680
commit
a2053597cc
|
@ -6539,15 +6539,15 @@ static int convert_eai_u2w(int unixret) {
|
||||||
return unixret;
|
return unixret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_hostname(void)
|
static char *get_fqdn(void)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
DWORD size = 0;
|
DWORD size = 0;
|
||||||
|
|
||||||
GetComputerNameExA( ComputerNamePhysicalDnsHostname, NULL, &size );
|
GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, NULL, &size );
|
||||||
if (GetLastError() != ERROR_MORE_DATA) return NULL;
|
if (GetLastError() != ERROR_MORE_DATA) return NULL;
|
||||||
if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
|
if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
|
||||||
if (!GetComputerNameExA( ComputerNamePhysicalDnsHostname, ret, &size ))
|
if (!GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, ret, &size ))
|
||||||
{
|
{
|
||||||
HeapFree( GetProcessHeap(), 0, ret );
|
HeapFree( GetProcessHeap(), 0, ret );
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -6564,8 +6564,9 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
struct addrinfo *unixaires = NULL;
|
struct addrinfo *unixaires = NULL;
|
||||||
int result;
|
int result;
|
||||||
struct addrinfo unixhints, *punixhints = NULL;
|
struct addrinfo unixhints, *punixhints = NULL;
|
||||||
char *hostname, *nodeV6 = NULL;
|
char *dot, *nodeV6 = NULL, *fqdn;
|
||||||
const char *node;
|
const char *node;
|
||||||
|
size_t hostname_len = 0;
|
||||||
|
|
||||||
*res = NULL;
|
*res = NULL;
|
||||||
if (!nodename && !servname)
|
if (!nodename && !servname)
|
||||||
|
@ -6574,13 +6575,16 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
return WSAHOST_NOT_FOUND;
|
return WSAHOST_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname = get_hostname();
|
fqdn = get_fqdn();
|
||||||
if (!hostname) return WSA_NOT_ENOUGH_MEMORY;
|
if (!fqdn) return WSA_NOT_ENOUGH_MEMORY;
|
||||||
|
dot = strchr(fqdn, '.');
|
||||||
|
if (dot)
|
||||||
|
hostname_len = dot - fqdn;
|
||||||
|
|
||||||
if (!nodename)
|
if (!nodename)
|
||||||
node = NULL;
|
node = NULL;
|
||||||
else if (!nodename[0])
|
else if (!nodename[0])
|
||||||
node = hostname;
|
node = fqdn;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node = nodename;
|
node = nodename;
|
||||||
|
@ -6595,7 +6599,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
nodeV6 = HeapAlloc(GetProcessHeap(), 0, close_bracket - node);
|
nodeV6 = HeapAlloc(GetProcessHeap(), 0, close_bracket - node);
|
||||||
if (!nodeV6)
|
if (!nodeV6)
|
||||||
{
|
{
|
||||||
HeapFree(GetProcessHeap(), 0, hostname);
|
HeapFree(GetProcessHeap(), 0, fqdn);
|
||||||
return WSA_NOT_ENOUGH_MEMORY;
|
return WSA_NOT_ENOUGH_MEMORY;
|
||||||
}
|
}
|
||||||
lstrcpynA(nodeV6, node + 1, close_bracket - node);
|
lstrcpynA(nodeV6, node + 1, close_bracket - node);
|
||||||
|
@ -6624,7 +6628,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
if (punixhints->ai_socktype < 0)
|
if (punixhints->ai_socktype < 0)
|
||||||
{
|
{
|
||||||
SetLastError(WSAESOCKTNOSUPPORT);
|
SetLastError(WSAESOCKTNOSUPPORT);
|
||||||
HeapFree(GetProcessHeap(), 0, hostname);
|
HeapFree(GetProcessHeap(), 0, fqdn);
|
||||||
HeapFree(GetProcessHeap(), 0, nodeV6);
|
HeapFree(GetProcessHeap(), 0, nodeV6);
|
||||||
return SOCKET_ERROR;
|
return SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -6648,7 +6652,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
/* getaddrinfo(3) is thread safe, no need to wrap in CS */
|
/* getaddrinfo(3) is thread safe, no need to wrap in CS */
|
||||||
result = getaddrinfo(node, servname, punixhints, &unixaires);
|
result = getaddrinfo(node, servname, punixhints, &unixaires);
|
||||||
|
|
||||||
if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST)) && !strcmp(hostname, node))
|
if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST))
|
||||||
|
&& (!strcmp(fqdn, node) || (!strncmp(fqdn, node, hostname_len) && !node[hostname_len])))
|
||||||
{
|
{
|
||||||
/* If it didn't work it means the host name IP is not in /etc/hosts, try again
|
/* If it didn't work it means the host name IP is not in /etc/hosts, try again
|
||||||
* by sending a NULL host and avoid sending a NULL servname too because that
|
* by sending a NULL host and avoid sending a NULL servname too because that
|
||||||
|
@ -6657,7 +6662,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
|
||||||
result = getaddrinfo(NULL, servname ? servname : "0", punixhints, &unixaires);
|
result = getaddrinfo(NULL, servname ? servname : "0", punixhints, &unixaires);
|
||||||
}
|
}
|
||||||
TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result);
|
TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result);
|
||||||
HeapFree(GetProcessHeap(), 0, hostname);
|
HeapFree(GetProcessHeap(), 0, fqdn);
|
||||||
HeapFree(GetProcessHeap(), 0, nodeV6);
|
HeapFree(GetProcessHeap(), 0, nodeV6);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
Loading…
Reference in New Issue