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 |