通过“pcap_open” 函数打开网卡设备:
pcap_t* device = pcap_open(
pcap->name, // name of the device
65536, // portion of the packet to capture
// 65536 guarantees that the whole packet
// will be captured on all the link layers
PCAP_OPENFLAG_PROMISCUOUS | // promiscuous mode
PCAP_OPENFLAG_NOCAPTURE_LOCAL | PCAP_OPENFLAG_MAX_RESPONSIVENESS,
100, // read timeout
NULL,
errbuf); // error buffer
通过“pcap_open_live” 函数打开网卡设备:
pcap_t* device = pcap_open_live(
pcap->name, // name of the device
65536, // portion of the packet to capture
// 65536 guarantees that the whole packet
// will be captured on all the link layers
PCAP_OPENFLAG_PROMISCUOUS | // promiscuous mode
PCAP_OPENFLAG_NOCAPTURE_LOCAL | PCAP_OPENFLAG_MAX_RESPONSIVENESS,
1000, // read timeout
errbuf); // error buffer
两者区别:
“pcap_open_live” 函数打开的网卡设备可以读/写来自环路的以太网报文,“pcap_open” 函数打开的网卡设备只能向物理承载网络读写环路的以太网报文。
两者效率:
“pcap_open” 收发效率更高一点,但两者之间效率非常细微基本没有什么太大的区别。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/163297.html