C++语法 网络相关函数
C++ 函数pcap_findalldevs
2、捕获数据包
2.1、获取本地网络设备列表
在WinPcap中,获取本地网络设备列表是通过函数pcap_findalldevs实现的,函数原型如下所示:
int pcap_findalldevs (pcap_if_t **alldevsp, char *errbuf);
// alldevsp: 存储本地网络设备列表
// errbuf: 存储错误信息
// 返回值:int,如果发生错误将返回-1,执行成功将返回0
具体实例如下所示:
pcap_if_t* alldevs;
char errbuf[PCAP_ERRBUF_SIZE];
// 获取本地机器的设备列表
if( pcap_findalldevs(&alldevs, errbuf) == -1)
{
printf(“>>> Error - Error in pcap_findalldevs: %s\n”, errbuf);
Pcap_open_live
pcap_t* pcap_open_live
( const char * device,
int snaplen,
int promisc,
int to_ms,
char * ebuf
)
从网络打开实时捕获。
tmp_if_info->pcap_handle = pcap_open_live(tmp_if_info->interface.c_str(), BUFSIZ, P