iphlpapi: Add a private network IP to interfaces without an IP address

Bruno Jesus 00cpxxx at gmail.com
Wed Jan 14 20:25:51 CST 2015


Explanation in a comment inside the patch.

To test this in Linux for example I have eth0 and wlan0, I'm connected
by wifi so eth0 does not have an IP and currently wine returns an
empty IP making Youku Desktop unhappy. More at
https://bugs.winehq.org/show_bug.cgi?id=32205#c13.

Fixes bug https://bugs.winehq.org/show_bug.cgi?id=32205

Bibliography:
http://www.webopedia.com/TERM/A/APIPA.html
http://packetlife.net/blog/2008/sep/24/169-254-0-0-addresses-explained/
http://tools.ietf.org/html/rfc3927 (I didn't read this completely)
-------------- next part --------------
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 59f3593..220ae75 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -604,6 +604,15 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
                   }
                 }
               }
+              /* No IP could be found for the interface, use a fake IP similar to what
+               * Automatic Private IP Addressing (APIPA) suggests. This is required by
+               * Youku Desktop from bug 32205. Ideally arp requests would be needed to
+               * determine if the IP addresses currently exist in the network but this
+               * is enough for now. */
+              if (firstIPAddr) {
+                sprintf(ptr->IpAddressList.IpAddress.String, "169.254.0.%d", ndx + 1);
+                strcpy(ptr->IpAddressList.IpMask.String, "255.255.0.0");
+              }
               /* Find first router through this interface, which we'll assume
                * is the default gateway for this adapter */
               for (i = 0; i < routeTable->dwNumEntries; i++)
diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c
index b2d81c0..14bbc5d 100644
--- a/dlls/iphlpapi/tests/iphlpapi.c
+++ b/dlls/iphlpapi/tests/iphlpapi.c
@@ -1118,12 +1118,20 @@ static void testGetAdaptersInfo(void)
     if (apiReturn == ERROR_NO_DATA)
       ; /* no adapter's, that's okay */
     else if (apiReturn == ERROR_BUFFER_OVERFLOW) {
-      PIP_ADAPTER_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
+      PIP_ADAPTER_INFO ptr, buf = HeapAlloc(GetProcessHeap(), 0, len);
 
       apiReturn = pGetAdaptersInfo(buf, &len);
       ok(apiReturn == NO_ERROR,
        "GetAdaptersInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
        apiReturn);
+      ptr = buf;
+      while (ptr) {
+        ok(ptr->IpAddressList.IpAddress.String[0], "A valid IP must be present\n");
+        ok(ptr->IpAddressList.IpMask.String[0], "A valid mask must be present\n");
+        trace("Adapter '%s', IP %s, Mask %s\n", ptr->AdapterName,
+              ptr->IpAddressList.IpAddress.String, ptr->IpAddressList.IpMask.String);
+        ptr = ptr->Next;
+      }
       HeapFree(GetProcessHeap(), 0, buf);
     }
   }


More information about the wine-patches mailing list