通过“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” 收发效率更高一点,但两者之间效率非常细微基本没有什么太大的区别。