[PATCH 1/6] iphlpapi: Implement GetInterfaceInfo() on top of GetIfTable().
Huw Davies
huw at codeweavers.com
Fri Jul 9 03:09:23 CDT 2021
Eventually this should be implemented using NSI. This is an
intermediate step to keep the interface names in sync.
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/iphlpapi/iphlpapi_main.c | 74 ++++++++++------------------------
dlls/iphlpapi/tests/iphlpapi.c | 12 +++++-
2 files changed, 32 insertions(+), 54 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 5621a4485c4..7c537dc3f27 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -2060,65 +2060,33 @@ DWORD WINAPI GetIfTable2( MIB_IF_TABLE2 **table )
* BUGS
* MSDN states this should return non-loopback interfaces only.
*/
-DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
+DWORD WINAPI GetInterfaceInfo( IP_INTERFACE_INFO *table, ULONG *size )
{
- DWORD ret;
+ MIB_IFTABLE *if_table;
+ DWORD err, needed, i;
- TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
- if (!dwOutBufLen)
- ret = ERROR_INVALID_PARAMETER;
- else {
- DWORD numInterfaces = get_interface_indices( FALSE, NULL );
- ULONG size = sizeof(IP_INTERFACE_INFO);
+ TRACE("table %p, size %p\n", table, size );
+ if (!size) return ERROR_INVALID_PARAMETER;
- if (numInterfaces > 1)
- size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
- if (!pIfTable || *dwOutBufLen < size) {
- *dwOutBufLen = size;
- ret = ERROR_INSUFFICIENT_BUFFER;
- }
- else {
- InterfaceIndexTable *table;
- get_interface_indices( FALSE, &table );
+ err = AllocateAndGetIfTableFromStack( &if_table, 0, GetProcessHeap(), 0 );
+ if (err) return err;
- if (table) {
- size = sizeof(IP_INTERFACE_INFO);
- if (table->numIndexes > 1)
- size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
- if (*dwOutBufLen < size) {
- *dwOutBufLen = size;
- ret = ERROR_INSUFFICIENT_BUFFER;
- }
- else {
- DWORD ndx;
- char nameBuf[MAX_ADAPTER_NAME];
+ needed = FIELD_OFFSET(IP_INTERFACE_INFO, Adapter[if_table->dwNumEntries]);
+ if (!table || *size < needed)
+ {
+ *size = needed;
+ heap_free( if_table );
+ return ERROR_INSUFFICIENT_BUFFER;
+ }
- *dwOutBufLen = size;
- pIfTable->NumAdapters = 0;
- for (ndx = 0; ndx < table->numIndexes; ndx++) {
- const char *walker, *name;
- WCHAR *assigner;
-
- pIfTable->Adapter[ndx].Index = table->indexes[ndx];
- name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
- for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
- walker && *walker &&
- assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
- walker++, assigner++)
- *assigner = *walker;
- *assigner = 0;
- pIfTable->NumAdapters++;
- }
- ret = NO_ERROR;
- }
- HeapFree(GetProcessHeap(), 0, table);
- }
- else
- ret = ERROR_OUTOFMEMORY;
+ table->NumAdapters = if_table->dwNumEntries;
+ for (i = 0; i < if_table->dwNumEntries; i++)
+ {
+ table->Adapter[i].Index = if_table->table[i].dwIndex;
+ strcpyW( table->Adapter[i].Name, if_table->table[i].wszName );
}
- }
- TRACE("returning %d\n", ret);
- return ret;
+ heap_free( if_table );
+ return ERROR_SUCCESS;
}
diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c
index 39aa7123668..61406090839 100644
--- a/dlls/iphlpapi/tests/iphlpapi.c
+++ b/dlls/iphlpapi/tests/iphlpapi.c
@@ -1040,7 +1040,7 @@ static void testWinNT4Functions(void)
static void testGetInterfaceInfo(void)
{
DWORD apiReturn;
- ULONG len = 0;
+ ULONG len = 0, i;
apiReturn = GetInterfaceInfo(NULL, NULL);
if (apiReturn == ERROR_NOT_SUPPORTED) {
@@ -1061,6 +1061,16 @@ static void testGetInterfaceInfo(void)
ok(apiReturn == NO_ERROR,
"GetInterfaceInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
apiReturn);
+
+ for (i = 0; i < buf->NumAdapters; i++)
+ {
+ MIB_IFROW row = { .dwIndex = buf->Adapter[i].Index };
+ GetIfEntry( &row );
+ ok( !wcscmp( buf->Adapter[i].Name, row.wszName ), "got %s vs %s\n",
+ debugstr_w( buf->Adapter[i].Name ), debugstr_w( row.wszName ) );
+todo_wine_if( row.dwType == IF_TYPE_SOFTWARE_LOOPBACK)
+ ok( row.dwType != IF_TYPE_SOFTWARE_LOOPBACK, "got loopback\n" );
+ }
HeapFree(GetProcessHeap(), 0, buf);
}
}
--
2.23.0
More information about the wine-devel
mailing list