WinPcap根据pcap_if name获取网卡的易记名称

 pcap_findalldevs可以获取到电脑可用的pcap设备,pcap设备定义如下

struct pcap_if {
	struct pcap_if *next;
	char *name;		/* name to hand to "pcap_open_live()" */
	char *description;	/* textual description of interface, or NULL */
	struct pcap_addr *addresses;
	bpf_u_int32 flags;	/* PCAP_IF_ interface flags */
};

得到的name类似于:rpcap://\Device\NPF_{1EB04710-FE1E-4E5A-99F7-BBB26A63D057}

可能没有:rpcap:// 这个前缀

得到的description类似于:Network adapter 'Microsoft' on local host

这些都很难看出是电脑上的哪个设备

微软提供了ConvertInterfaceGuidToLuid函数,根据{1EB04710-FE1E-4E5A-99F7-BBB26A63D057}来获取NET_LUID

提供了ConvertInterfaceLuidToAlias根据NET_LUID获取它的易记名称

IPHLPAPI_DLL_LINKAGE _NETIOAPI_SUCCESS_ NETIOAPI_API ConvertInterfaceGuidToLuid(
  [in]  const GUID *InterfaceGuid,
  [out] PNET_LUID  InterfaceLuid
);

Parameters

[in] InterfaceGuid

A pointer to a GUID for a network interface.

[out] InterfaceLuid

A pointer to the NET_LUID for this interface.

Return value

On success, ConvertInterfaceGuidToLuid returns NO_ERROR. Any nonzero return value indicates failure and a NULL is returned in the InterfaceLuid parameter.

IPHLPAPI_DLL_LINKAGE _NETIOAPI_SUCCESS_ NETIOAPI_API ConvertInterfaceLuidToAlias(
  [in]  const NET_LUID *InterfaceLuid,
  [out] PWSTR          InterfaceAlias,
  [in]  SIZE_T         Length
);

Parameters

[in] InterfaceLuid

A pointer to a NET_LUID for a network interface.

[out] InterfaceAlias

A pointer to a buffer to hold the NULL-terminated Unicode string containing the alias name of the network interface when the function returns successfully.

[in] Length

The length, in characters, of the buffer pointed to by the InterfaceAlias parameter. This value must be large enough to accommodate the alias name of the network interface and the terminating NULL character. The maximum required length is NDIS_IF_MAX_STRING_SIZE + 1.

Return value

On success, ConvertInterfaceLuidToAlias returns NO_ERROR. Any nonzero return value indicates failure.

  • 22
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值