iphlpapi: Implement GetAdapterIndex() on top of GetIfTable().
Eventually this should just parse the Guid in the name. This is an intermediate step to keep the interface names in sync. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
9f16ac9ae1
commit
bdc48738ce
|
@ -628,28 +628,35 @@ void WINAPI FreeMibTable(void *ptr)
|
|||
* Get interface index from its name.
|
||||
*
|
||||
* PARAMS
|
||||
* AdapterName [In] unicode string with the adapter name
|
||||
* IfIndex [Out] returns found interface index
|
||||
* adapter_name [In] unicode string with the adapter name
|
||||
* index [Out] returns found interface index
|
||||
*
|
||||
* RETURNS
|
||||
* Success: NO_ERROR
|
||||
* Failure: error code from winerror.h
|
||||
*/
|
||||
DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
|
||||
DWORD WINAPI GetAdapterIndex( WCHAR *adapter_name, ULONG *index )
|
||||
{
|
||||
char adapterName[MAX_ADAPTER_NAME];
|
||||
unsigned int i;
|
||||
DWORD ret;
|
||||
MIB_IFTABLE *if_table;
|
||||
DWORD err, i;
|
||||
|
||||
TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
|
||||
/* The adapter name is guaranteed not to have any unicode characters, so
|
||||
* this translation is never lossy */
|
||||
for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
|
||||
adapterName[i] = (char)AdapterName[i];
|
||||
adapterName[i] = '\0';
|
||||
ret = getInterfaceIndexByName(adapterName, IfIndex);
|
||||
TRACE("returning %d\n", ret);
|
||||
return ret;
|
||||
TRACE( "name %s, index %p\n", debugstr_w( adapter_name ), index );
|
||||
|
||||
err = AllocateAndGetIfTableFromStack( &if_table, 0, GetProcessHeap(), 0 );
|
||||
if (err) return err;
|
||||
|
||||
err = ERROR_INVALID_PARAMETER;
|
||||
for (i = 0; i < if_table->dwNumEntries; i++)
|
||||
{
|
||||
if (!strcmpW( adapter_name, if_table->table[i].wszName ))
|
||||
{
|
||||
*index = if_table->table[i].dwIndex;
|
||||
err = ERROR_SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
heap_free( if_table );
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -236,27 +236,31 @@ static void testGetIfTable(void)
|
|||
"GetIfTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n\n",
|
||||
apiReturn);
|
||||
|
||||
if (apiReturn == NO_ERROR && winetest_debug > 1)
|
||||
if (apiReturn == NO_ERROR)
|
||||
{
|
||||
DWORD i, j;
|
||||
char name[MAX_INTERFACE_NAME_LEN];
|
||||
DWORD i, index;
|
||||
|
||||
trace( "interface table: %u entries\n", buf->dwNumEntries );
|
||||
if (winetest_debug > 1) trace( "interface table: %u entries\n", buf->dwNumEntries );
|
||||
for (i = 0; i < buf->dwNumEntries; i++)
|
||||
{
|
||||
MIB_IFROW *row = &buf->table[i];
|
||||
WideCharToMultiByte( CP_ACP, 0, row->wszName, -1, name, MAX_INTERFACE_NAME_LEN, NULL, NULL );
|
||||
trace( "%u: '%s' type %u mtu %u speed %u phys",
|
||||
row->dwIndex, name, row->dwType, row->dwMtu, row->dwSpeed );
|
||||
for (j = 0; j < row->dwPhysAddrLen; j++)
|
||||
printf( " %02x", row->bPhysAddr[j] );
|
||||
printf( "\n" );
|
||||
trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
|
||||
row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
|
||||
row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
|
||||
trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
|
||||
row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
|
||||
row->dwOutDiscards, row->dwOutErrors );
|
||||
|
||||
if (winetest_debug > 1)
|
||||
{
|
||||
trace( "%u: '%s' type %u mtu %u speed %u\n",
|
||||
row->dwIndex, debugstr_w(row->wszName), row->dwType, row->dwMtu, row->dwSpeed );
|
||||
trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
|
||||
row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
|
||||
row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
|
||||
trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
|
||||
row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
|
||||
row->dwOutDiscards, row->dwOutErrors );
|
||||
}
|
||||
apiReturn = GetAdapterIndex( row->wszName, &index );
|
||||
ok( !apiReturn, "got %d\n", apiReturn );
|
||||
ok( index == row->dwIndex ||
|
||||
broken( index != row->dwIndex && index ), /* Win8 can have identical guids for two different ifaces */
|
||||
"got %d vs %d\n", index, row->dwIndex );
|
||||
}
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
|
|
Loading…
Reference in New Issue