赞
踩
int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
- pcap_t *, //适配器
- struct pcap_pkthdr **, //报文头
- const u_char **;//报文内容
其中,
- struct pcap_pkthdr {
- struct timeval ts; /* time stamp */
- bpf_u_int32 caplen; /* length of portion present */
- bpf_u_int32 len; /* length of this packet (off wire) */
- };
- //捕获数据包
- while ((res = pcap_next_ex(fp, &header, &pkt_data)) >= 0)
- {
- //未捕获到数据,继续捕获
- if (res == 0)
- continue;
- else if (res == -1)
- {
- std::cout << "捕获错误:" << pcap_geterr(fp) << std::endl;
- return -1;
- }
-
- //捕获到数据包,数据为pkt_data
- std::cout << header->ts.tv_sec << " " << header->ts.tv_usec << " " << header->len << std::endl;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。