if_nametoindex 函数
if_nametoindex 函数将网络接口的 ANSI 接口名称转换为接口的本地索引。
语法
NET_IFINDEX NETIOAPI_API_ if_nametoindex(
_In_ PCSTR InterfaceName
);
参数
- InterfaceName [in]
指向包含接口名称的以 NULL 结尾的 ANSI 字符串的指针。
返回值
如果函数成功, if_nametoindex 返回本地接口索引。 如果函数失败, if_nametoindex 返回零。
注解
if_nametoindex 函数将接口名称映射到其相应的索引中。 此函数设计为 IPv6 的基本套接字扩展的一部分,如 RFC 2553 中的 IETF 中所述。
if_nametoindex 函数实现是为了在 Unix 环境中移植驱动程序,但 ConvertInterfaceXxx 函数是转换网络接口标识符的首选方法。 可以通过调用 ConvertInterfaceNameToLuidA 函数替换 if_nametoindex 函数,以将 ANSI 接口名称转换为NET_LUID联合,然后调用 ConvertInterfaceLuidToIndex 函数以将NET_LUID转换为本地接口索引。
如果 if_nametoindex 函数失败并返回零,则无法确定错误代码。
要求
目标平台 |
通用 |
版本 |
在 Windows Vista 和更高版本的 Windows 操作系统中可用。 |
标头 |
Netioapi.h (包括 Netioapi.h) |
库 |
Netio.lib |
IRQL |
PASSIVE_LEVEL |