[PATCH] ws2_32: Also check the FQDN when injecting the local IP.

Stefan Dösinger stefan at codeweavers.com
Tue Aug 15 04:44:20 CDT 2017


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>

---

World of Tanks is affected by this. It refuses to connect to the game
servers when it cannot resolve the full local hostname. The
misconfiguration of having a nonresolvable hostname is more common on
OSX, but it can also be triggered on Linux.
---
 dlls/ws2_32/socket.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 06f1c26d7d..7761f1f0d4 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -6555,6 +6555,22 @@ static char *get_hostname(void)
     return ret;
 }
 
+static char *get_fqdn(void)
+{
+    char *ret;
+    DWORD size = 0;
+
+    GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, NULL, &size );
+    if (GetLastError() != ERROR_MORE_DATA) return NULL;
+    if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
+    if (!GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, ret, &size ))
+    {
+        HeapFree( GetProcessHeap(), 0, ret );
+        return NULL;
+    }
+    return ret;
+}
+
 /***********************************************************************
  *		getaddrinfo		(WS2_32.@)
  */
@@ -6564,7 +6580,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     struct addrinfo *unixaires = NULL;
     int   result;
     struct addrinfo unixhints, *punixhints = NULL;
-    char *hostname, *nodeV6 = NULL;
+    char *hostname, *nodeV6 = NULL, *fqdn;
     const char *node;
 
     *res = NULL;
@@ -6576,6 +6592,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
 
     hostname = get_hostname();
     if (!hostname) return WSA_NOT_ENOUGH_MEMORY;
+    fqdn = get_fqdn();
+    if (!fqdn) return WSA_NOT_ENOUGH_MEMORY;
 
     if (!nodename)
         node = NULL;
@@ -6648,7 +6666,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     /* getaddrinfo(3) is thread safe, no need to wrap in CS */
     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(hostname, node) || !strcmp(fqdn, node)))
     {
         /* 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
@@ -6659,6 +6678,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result);
     HeapFree(GetProcessHeap(), 0, hostname);
     HeapFree(GetProcessHeap(), 0, nodeV6);
+    HeapFree(GetProcessHeap(), 0, fqdn);
 
     if (!result) {
         struct addrinfo *xuai = unixaires;
-- 
2.13.0




More information about the wine-patches mailing list