Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/iphlpapi/iphlpapi.spec | 1 +
dlls/iphlpapi/iphlpapi_main.c | 92 ++++++++++++++--------------------
dlls/iphlpapi/tests/iphlpapi.c | 61 +++++++---------------
include/netioapi.h | 2 +
4 files changed, 58 insertions(+), 98 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec
index 604852a754d..4299af36660 100644
--- a/dlls/iphlpapi/iphlpapi.spec
+++ b/dlls/iphlpapi/iphlpapi.spec
@@ -89,6 +89,7 @@
@ stub GetIcmpStatsFromStack
@ stdcall GetIfEntry( ptr )
@ stdcall GetIfEntry2( ptr )
+@ stdcall GetIfEntry2Ex( long ptr )
@ stub GetIfEntryFromStack
#@ stub GetIfStackTable
@ stdcall GetIfTable( ptr ptr long )
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index dd2b9d7035c..b869570bac0 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1778,61 +1778,6 @@ DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
return ret;
}
-/******************************************************************
- * GetIfEntry2 (IPHLPAPI.@)
- */
-DWORD WINAPI GetIfEntry2( MIB_IF_ROW2 *row2 )
-{
- DWORD ret;
- char buf[MAX_ADAPTER_NAME], *name;
- MIB_IFROW row;
-
- TRACE("%p\n", row2);
-
- if (!row2 || (!(name = getInterfaceNameByIndex( row2->InterfaceIndex, buf )) &&
- !(name = getInterfaceNameByIndex( row2->InterfaceLuid.Info.NetLuidIndex, buf ))))
- {
- return ERROR_INVALID_PARAMETER;
- }
- if ((ret = getInterfaceEntryByName( name, &row ))) return ret;
- if ((ret = getInterfaceStatsByName( name, &row ))) return ret;
-
- memset( row2, 0, sizeof(*row2) );
- row2->InterfaceIndex = row.dwIndex;
- ConvertInterfaceIndexToLuid( row2->InterfaceIndex, &row2->InterfaceLuid );
- ConvertInterfaceLuidToGuid( &row2->InterfaceLuid, &row2->InterfaceGuid );
- row2->Type = row.dwType;
- row2->Mtu = row.dwMtu;
- MultiByteToWideChar( CP_UNIXCP, 0, (const char *)row.bDescr, -1, row2->Description, ARRAY_SIZE(row2->Description) );
- MultiByteToWideChar( CP_UNIXCP, 0, (const char *)row.bDescr, -1, row2->Alias, ARRAY_SIZE(row2->Alias) );
- row2->PhysicalAddressLength = row.dwPhysAddrLen;
- memcpy( &row2->PhysicalAddress, &row.bPhysAddr, row.dwPhysAddrLen );
- memcpy( &row2->PermanentPhysicalAddress, &row.bPhysAddr, row.dwPhysAddrLen );
- row2->OperStatus = row.dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL ? IfOperStatusUp : IfOperStatusDown;
- row2->AdminStatus = NET_IF_ADMIN_STATUS_UP;
- row2->MediaConnectState = MediaConnectStateConnected;
- row2->ConnectionType = NET_IF_CONNECTION_DEDICATED;
- row2->TransmitLinkSpeed = row2->ReceiveLinkSpeed = row.dwSpeed;
- row2->AccessType = (row2->Type == MIB_IF_TYPE_LOOPBACK) ? NET_IF_ACCESS_LOOPBACK : NET_IF_ACCESS_BROADCAST;
- row2->InterfaceAndOperStatusFlags.ConnectorPresent = row2->Type != MIB_IF_TYPE_LOOPBACK;
- row2->InterfaceAndOperStatusFlags.HardwareInterface = row2->Type != MIB_IF_TYPE_LOOPBACK;
-
- /* stats */
- row2->InOctets = row.dwInOctets;
- row2->InUcastPkts = row.dwInUcastPkts;
- row2->InNUcastPkts = row.dwInNUcastPkts;
- row2->InDiscards = row.dwInDiscards;
- row2->InErrors = row.dwInErrors;
- row2->InUnknownProtos = row.dwInUnknownProtos;
- row2->OutOctets = row.dwOutOctets;
- row2->OutUcastPkts = row.dwOutUcastPkts;
- row2->OutNUcastPkts = row.dwOutNUcastPkts;
- row2->OutDiscards = row.dwOutDiscards;
- row2->OutErrors = row.dwOutErrors;
-
- return NO_ERROR;
-}
-
static int IfTableSorter(const void *a, const void *b)
{
int ret;
@@ -1982,6 +1927,43 @@ static void if_row2_fill( MIB_IF_ROW2 *row, struct nsi_ndis_ifinfo_rw *rw, struc
row->OutQLen = 0; /* fixme */
}
+/******************************************************************
+ * GetIfEntry2Ex (IPHLPAPI.@)
+ */
+DWORD WINAPI GetIfEntry2Ex( MIB_IF_TABLE_LEVEL level, MIB_IF_ROW2 *row )
+{
+ DWORD err;
+ struct nsi_ndis_ifinfo_rw rw;
+ struct nsi_ndis_ifinfo_dynamic dyn;
+ struct nsi_ndis_ifinfo_static stat;
+
+ TRACE( "(%d, %p)\n", level, row );
+
+ if (level != MibIfTableNormal) FIXME( "level %u not fully supported\n", level );
+ if (!row) return ERROR_INVALID_PARAMETER;
+
+ if (!row->InterfaceLuid.Value)
+ {
+ if (!row->InterfaceIndex) return ERROR_INVALID_PARAMETER;
+ err = ConvertInterfaceIndexToLuid( row->InterfaceIndex, &row->InterfaceLuid );
+ if (err) return err;
+ }
+
+ err = NsiGetAllParameters( 1, &NPI_MS_NDIS_MODULEID, NSI_NDIS_IFINFO_TABLE,
+ &row->InterfaceLuid, sizeof(row->InterfaceLuid),
+ &rw, sizeof(rw), &dyn, sizeof(dyn), &stat, sizeof(stat) );
+ if (!err) if_row2_fill( row, &rw, &dyn, &stat );
+ return err;
+}
+
+/******************************************************************
+ * GetIfEntry2 (IPHLPAPI.@)
+ */
+DWORD WINAPI GetIfEntry2( MIB_IF_ROW2 *row )
+{
+ return GetIfEntry2Ex( MibIfTableNormal, row );
+}
+
/******************************************************************
* GetIfTable2Ex (IPHLPAPI.@)
*/
diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c
index 54c820e522c..87aeb99d6d9 100644
--- a/dlls/iphlpapi/tests/iphlpapi.c
+++ b/dlls/iphlpapi/tests/iphlpapi.c
@@ -53,9 +53,6 @@
static HMODULE hLibrary = NULL;
static DWORD (WINAPI *pAllocateAndGetTcpExTableFromStack)(void**,BOOL,HANDLE,DWORD,DWORD);
-static DWORD (WINAPI *pGetIfEntry2)(PMIB_IF_ROW2);
-static DWORD (WINAPI *pGetIfTable2)(PMIB_IF_TABLE2*);
-static DWORD (WINAPI *pGetIfTable2Ex)(MIB_IF_TABLE_LEVEL,PMIB_IF_TABLE2*);
static DWORD (WINAPI *pGetTcp6Table)(PMIB_TCP6TABLE,PDWORD,BOOL);
static DWORD (WINAPI *pGetUdp6Table)(PMIB_UDP6TABLE,PDWORD,BOOL);
static DWORD (WINAPI *pGetUnicastIpAddressEntry)(MIB_UNICASTIPADDRESS_ROW*);
@@ -64,7 +61,6 @@ static DWORD (WINAPI *pGetExtendedTcpTable)(PVOID,PDWORD,BOOL,ULONG,TCP_TABLE_CL
static DWORD (WINAPI *pGetExtendedUdpTable)(PVOID,PDWORD,BOOL,ULONG,UDP_TABLE_CLASS,ULONG);
static DWORD (WINAPI *pCreateSortedAddressPairs)(const PSOCKADDR_IN6,ULONG,const PSOCKADDR_IN6,ULONG,ULONG,
PSOCKADDR_IN6_PAIR*,ULONG*);
-static void (WINAPI *pFreeMibTable)(void*);
static DWORD (WINAPI *pConvertLengthToIpv4Mask)(ULONG,ULONG*);
static DWORD (WINAPI *pParseNetworkString)(const WCHAR*,DWORD,NET_ADDRESS_INFO*,USHORT*,BYTE*);
static DWORD (WINAPI *pNotifyUnicastIpAddressChange)(ADDRESS_FAMILY, PUNICAST_IPADDRESS_CHANGE_CALLBACK,
@@ -76,9 +72,6 @@ static void loadIPHlpApi(void)
hLibrary = LoadLibraryA("iphlpapi.dll");
if (hLibrary) {
pAllocateAndGetTcpExTableFromStack = (void *)GetProcAddress(hLibrary, "AllocateAndGetTcpExTableFromStack");
- pGetIfEntry2 = (void *)GetProcAddress(hLibrary, "GetIfEntry2");
- pGetIfTable2 = (void *)GetProcAddress(hLibrary, "GetIfTable2");
- pGetIfTable2Ex = (void *)GetProcAddress(hLibrary, "GetIfTable2Ex");
pGetTcp6Table = (void *)GetProcAddress(hLibrary, "GetTcp6Table");
pGetUdp6Table = (void *)GetProcAddress(hLibrary, "GetUdp6Table");
pGetUnicastIpAddressEntry = (void *)GetProcAddress(hLibrary, "GetUnicastIpAddressEntry");
@@ -86,7 +79,6 @@ static void loadIPHlpApi(void)
pGetExtendedTcpTable = (void *)GetProcAddress(hLibrary, "GetExtendedTcpTable");
pGetExtendedUdpTable = (void *)GetProcAddress(hLibrary, "GetExtendedUdpTable");
pCreateSortedAddressPairs = (void *)GetProcAddress(hLibrary, "CreateSortedAddressPairs");
- pFreeMibTable = (void *)GetProcAddress(hLibrary, "FreeMibTable");
pConvertLengthToIpv4Mask = (void *)GetProcAddress(hLibrary, "ConvertLengthToIpv4Mask");
pParseNetworkString = (void *)GetProcAddress(hLibrary, "ParseNetworkString");
pNotifyUnicastIpAddressChange = (void *)GetProcAddress(hLibrary, "NotifyUnicastIpAddressChange");
@@ -1576,7 +1568,7 @@ static void test_CreateSortedAddressPairs(void)
ok( pair_count >= 1, "got %u\n", pair_count );
ok( pair[0].SourceAddress != NULL, "src address not set\n" );
ok( pair[0].DestinationAddress != NULL, "dst address not set\n" );
- pFreeMibTable( pair );
+ FreeMibTable( pair );
dst[1].sin6_family = AF_INET6;
dst[1].sin6_addr.u.Word[5] = 0xffff;
@@ -1593,7 +1585,7 @@ static void test_CreateSortedAddressPairs(void)
ok( pair[0].DestinationAddress != NULL, "dst address not set\n" );
ok( pair[1].SourceAddress != NULL, "src address not set\n" );
ok( pair[1].DestinationAddress != NULL, "dst address not set\n" );
- pFreeMibTable( pair );
+ FreeMibTable( pair );
}
static DWORD get_interface_index(void)
@@ -1862,27 +1854,22 @@ static void test_GetIfEntry2(void)
MIB_IF_ROW2 row;
NET_IFINDEX index;
- if (!pGetIfEntry2)
- {
- win_skip( "GetIfEntry2 not available\n" );
- return;
- }
if (!(index = get_interface_index()))
{
skip( "no suitable interface found\n" );
return;
}
- ret = pGetIfEntry2( NULL );
+ ret = GetIfEntry2( NULL );
ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
memset( &row, 0, sizeof(row) );
- ret = pGetIfEntry2( &row );
+ ret = GetIfEntry2( &row );
ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
memset( &row, 0, sizeof(row) );
row.InterfaceIndex = index;
- ret = pGetIfEntry2( &row );
+ ret = GetIfEntry2( &row );
ok( ret == NO_ERROR, "got %u\n", ret );
ok( row.InterfaceIndex == index, "got %u\n", index );
}
@@ -1892,17 +1879,11 @@ static void test_GetIfTable2(void)
DWORD ret;
MIB_IF_TABLE2 *table;
- if (!pGetIfTable2)
- {
- win_skip( "GetIfTable2 not available\n" );
- return;
- }
-
table = NULL;
- ret = pGetIfTable2( &table );
+ ret = GetIfTable2( &table );
ok( ret == NO_ERROR, "got %u\n", ret );
ok( table != NULL, "table not set\n" );
- pFreeMibTable( table );
+ FreeMibTable( table );
}
static void test_GetIfTable2Ex(void)
@@ -1910,35 +1891,29 @@ static void test_GetIfTable2Ex(void)
DWORD ret;
MIB_IF_TABLE2 *table;
- if (!pGetIfTable2Ex)
- {
- win_skip( "GetIfTable2Ex not available\n" );
- return;
- }
-
table = NULL;
- ret = pGetIfTable2Ex( MibIfTableNormal, &table );
+ ret = GetIfTable2Ex( MibIfTableNormal, &table );
ok( ret == NO_ERROR, "got %u\n", ret );
ok( table != NULL, "table not set\n" );
- pFreeMibTable( table );
+ FreeMibTable( table );
table = NULL;
- ret = pGetIfTable2Ex( MibIfTableRaw, &table );
+ ret = GetIfTable2Ex( MibIfTableRaw, &table );
ok( ret == NO_ERROR, "got %u\n", ret );
ok( table != NULL, "table not set\n" );
- pFreeMibTable( table );
+ FreeMibTable( table );
table = NULL;
- ret = pGetIfTable2Ex( MibIfTableNormalWithoutStatistics, &table );
+ ret = GetIfTable2Ex( MibIfTableNormalWithoutStatistics, &table );
ok( ret == NO_ERROR || broken(ret == ERROR_INVALID_PARAMETER), "got %u\n", ret );
ok( table != NULL || broken(!table), "table not set\n" );
- pFreeMibTable( table );
+ FreeMibTable( table );
table = NULL;
- ret = pGetIfTable2Ex( 3, &table );
+ ret = GetIfTable2Ex( 3, &table );
ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
ok( !table, "table should not be set\n" );
- pFreeMibTable( table );
+ FreeMibTable( table );
}
static void test_GetUnicastIpAddressEntry(void)
@@ -2070,12 +2045,12 @@ static void test_GetUnicastIpAddressTable(void)
ret = pGetUnicastIpAddressTable(AF_INET, &table);
ok( ret == NO_ERROR, "got %u\n", ret );
trace("GetUnicastIpAddressTable(AF_INET): NumEntries %u\n", table->NumEntries);
- pFreeMibTable(table);
+ FreeMibTable( table );
ret = pGetUnicastIpAddressTable(AF_INET6, &table);
ok( ret == NO_ERROR, "got %u\n", ret );
trace("GetUnicastIpAddressTable(AF_INET6): NumEntries %u\n", table->NumEntries);
- pFreeMibTable(table);
+ FreeMibTable( table );
ret = pGetUnicastIpAddressTable(AF_UNSPEC, &table);
ok( ret == NO_ERROR, "got %u\n", ret );
@@ -2099,7 +2074,7 @@ static void test_GetUnicastIpAddressTable(void)
trace("CreationTimeStamp: %08x%08x\n", table->Table[i].CreationTimeStamp.HighPart, table->Table[i].CreationTimeStamp.LowPart);
}
- pFreeMibTable(table);
+ FreeMibTable( table );
}
static void test_ConvertLengthToIpv4Mask(void)
diff --git a/include/netioapi.h b/include/netioapi.h
index 055266d946e..bbd203fc9b3 100644
--- a/include/netioapi.h
+++ b/include/netioapi.h
@@ -251,7 +251,9 @@ DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR*,NET_LUID*);
DWORD WINAPI ConvertLengthToIpv4Mask(ULONG,ULONG*);
void WINAPI FreeMibTable(void*);
DWORD WINAPI GetIfEntry2(MIB_IF_ROW2*);
+DWORD WINAPI GetIfEntry2Ex(MIB_IF_TABLE_LEVEL,MIB_IF_ROW2*);
DWORD WINAPI GetIfTable2(MIB_IF_TABLE2**);
+DWORD WINAPI GetIfTable2Ex(MIB_IF_TABLE_LEVEL,MIB_IF_TABLE2**);
DWORD WINAPI GetIpInterfaceTable(ADDRESS_FAMILY,MIB_IPINTERFACE_TABLE**);
DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW*);
PCHAR WINAPI if_indextoname(NET_IFINDEX,PCHAR);
--
2.23.0