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.
|
* Get interface index from its name.
|
||||||
*
|
*
|
||||||
* PARAMS
|
* PARAMS
|
||||||
* AdapterName [In] unicode string with the adapter name
|
* adapter_name [In] unicode string with the adapter name
|
||||||
* IfIndex [Out] returns found interface index
|
* index [Out] returns found interface index
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Success: NO_ERROR
|
* Success: NO_ERROR
|
||||||
* Failure: error code from winerror.h
|
* 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];
|
MIB_IFTABLE *if_table;
|
||||||
unsigned int i;
|
DWORD err, i;
|
||||||
DWORD ret;
|
|
||||||
|
|
||||||
TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
|
TRACE( "name %s, index %p\n", debugstr_w( adapter_name ), index );
|
||||||
/* The adapter name is guaranteed not to have any unicode characters, so
|
|
||||||
* this translation is never lossy */
|
err = AllocateAndGetIfTableFromStack( &if_table, 0, GetProcessHeap(), 0 );
|
||||||
for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
|
if (err) return err;
|
||||||
adapterName[i] = (char)AdapterName[i];
|
|
||||||
adapterName[i] = '\0';
|
err = ERROR_INVALID_PARAMETER;
|
||||||
ret = getInterfaceIndexByName(adapterName, IfIndex);
|
for (i = 0; i < if_table->dwNumEntries; i++)
|
||||||
TRACE("returning %d\n", ret);
|
{
|
||||||
return ret;
|
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",
|
"GetIfTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n\n",
|
||||||
apiReturn);
|
apiReturn);
|
||||||
|
|
||||||
if (apiReturn == NO_ERROR && winetest_debug > 1)
|
if (apiReturn == NO_ERROR)
|
||||||
{
|
{
|
||||||
DWORD i, j;
|
DWORD i, index;
|
||||||
char name[MAX_INTERFACE_NAME_LEN];
|
|
||||||
|
|
||||||
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++)
|
for (i = 0; i < buf->dwNumEntries; i++)
|
||||||
{
|
{
|
||||||
MIB_IFROW *row = &buf->table[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",
|
if (winetest_debug > 1)
|
||||||
row->dwIndex, name, row->dwType, row->dwMtu, row->dwSpeed );
|
{
|
||||||
for (j = 0; j < row->dwPhysAddrLen; j++)
|
trace( "%u: '%s' type %u mtu %u speed %u\n",
|
||||||
printf( " %02x", row->bPhysAddr[j] );
|
row->dwIndex, debugstr_w(row->wszName), row->dwType, row->dwMtu, row->dwSpeed );
|
||||||
printf( "\n" );
|
trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
|
||||||
trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
|
row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
|
||||||
row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
|
row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
|
||||||
row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
|
trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
|
||||||
trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
|
row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
|
||||||
row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
|
row->dwOutDiscards, row->dwOutErrors );
|
||||||
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);
|
HeapFree(GetProcessHeap(), 0, buf);
|
||||||
|
|
Loading…
Reference in New Issue