[PATCH] iphlpapi: Implement if_nametoindex (v2).

Stefan Dösinger stefan at codeweavers.com
Wed May 24 12:09:53 CDT 2017


Wargaming Game Center needs this.

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

---

Version 2: Use XXX instead of including another header in
iphlpapi_main.c. Add a test for a weird WGC behavior.
---
 dlls/iphlpapi/iphlpapi.spec    |  2 +-
 dlls/iphlpapi/iphlpapi_main.c  | 14 ++++++++++++++
 dlls/iphlpapi/tests/iphlpapi.c | 23 ++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec
index 4e01926617..4e5970c277 100644
--- a/dlls/iphlpapi/iphlpapi.spec
+++ b/dlls/iphlpapi/iphlpapi.spec
@@ -160,7 +160,7 @@
 @ stdcall IcmpSendEcho2(ptr ptr ptr ptr long ptr long ptr ptr long long)
 @ stdcall IcmpSendEcho(ptr long ptr long ptr ptr long long)
 #@ stub if_indextoname
-#@ stub if_nametoindex
+@ stdcall if_nametoindex(str) IPHLP_if_nametoindex
 #@ stub InitializeIpForwardEntry
 #@ stub InitializeIpInterfaceEntry
 #@ stub InitializeUnicastIpAddressEntry
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 796950e0f9..c592a902ef 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -3208,3 +3208,17 @@ DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR *name, NET_LUID *luid)
     luid->Info.IfType       = row.dwType;
     return NO_ERROR;
 }
+
+/******************************************************************
+ *    if_nametoindex (IPHLPAPI.@)
+ */
+IF_INDEX WINAPI IPHLP_if_nametoindex(const char *name)
+{
+    IF_INDEX idx;
+
+    TRACE("(%s)\n", name);
+    if (getInterfaceIndexByName(name, &idx) == NO_ERROR)
+        return idx;
+
+    return 0;
+}
diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c
index 5fb23fbc16..3369f78f55 100644
--- a/dlls/iphlpapi/tests/iphlpapi.c
+++ b/dlls/iphlpapi/tests/iphlpapi.c
@@ -96,6 +96,8 @@ static DWORD (WINAPI *pConvertInterfaceLuidToNameA)(const NET_LUID*,char*,SIZE_T
 static DWORD (WINAPI *pConvertInterfaceNameToLuidA)(const char*,NET_LUID*);
 static DWORD (WINAPI *pConvertInterfaceNameToLuidW)(const WCHAR*,NET_LUID*);
 
+static NET_IFINDEX (WINAPI *pif_nametoindex)(const char*);
+
 static void loadIPHlpApi(void)
 {
   hLibrary = LoadLibraryA("iphlpapi.dll");
@@ -144,6 +146,7 @@ static void loadIPHlpApi(void)
     pConvertInterfaceLuidToNameW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceLuidToNameW");
     pConvertInterfaceNameToLuidA = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidA");
     pConvertInterfaceNameToLuidW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidW");
+    pif_nametoindex = (void *)GetProcAddress(hLibrary, "if_nametoindex");
   }
 }
 
@@ -1792,7 +1795,7 @@ static void test_interface_identifier_conversion(void)
     SIZE_T len;
     WCHAR nameW[IF_MAX_STRING_SIZE + 1];
     char nameA[IF_MAX_STRING_SIZE + 1];
-    NET_IFINDEX index;
+    NET_IFINDEX index, index2;
 
     if (!pConvertInterfaceIndexToLuid)
     {
@@ -1951,6 +1954,24 @@ static void test_interface_identifier_conversion(void)
     ok( !luid.Info.Reserved, "got %x\n", luid.Info.Reserved );
     ok( luid.Info.NetLuidIndex != 0xdead, "index not set\n" );
     ok( luid.Info.IfType == IF_TYPE_ETHERNET_CSMACD, "got %u\n", luid.Info.IfType );
+
+    /* if_nametoindex */
+    if (pif_nametoindex)
+    {
+        index2 = pif_nametoindex( NULL );
+        ok( !index2, "Got unexpected index %u\n", index2 );
+        index2 = pif_nametoindex( nameA );
+        ok( index2 == index, "Got index %u for %s, expected %u\n", index2, nameA, index );
+        /* Wargaming.net Game Center passes a GUID-like string. */
+        index2 = pif_nametoindex( "{00000001-0000-0000-0000-000000000000}" );
+        ok( !index2, "Got unexpected index %u\n", index2 );
+        index2 = pif_nametoindex( wine_dbgstr_guid( &guid ) );
+        ok( !index2, "Got unexpected index %u for input %s\n", index2, wine_dbgstr_guid( &guid ) );
+    }
+    else
+    {
+        skip("if_nametoindex not supported\n");
+    }
 }
 
 static void test_GetIfEntry2(void)
-- 
2.13.0




More information about the wine-patches mailing list