我想通过名称获取适配器索引,经过几天的搜索,我找到了GetAdapterIndex()函数:
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#pragma comment(lib, "IPHLPAPI.lib")
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
int main()
{
DWORD res;
DWORD rs;
ULONG IfIndex;
LPWSTR AdapterName;
int i = 0;
res = GetAdapterIndex(L"AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport", &IfIndex);
if(res == NO_ERROR)
printf("Adapter Index: %ld\n", IfIndex);
res = GetNumberOfInterfaces(&rs);
if(res == NO_ERROR)
printf("Number of Adapters: %ld\n", rs);
return 0;
}
首先:它不会返回我选择的特定适配器名称的索引。 第二:它返回我有两个适配器,即使我只有一个。