【发布时间】:2017-08-25 00:31:45
【问题描述】:
我正在尝试使用 c++ 选择一组 pcap 文件的包。标准是IP。 pcap阅读器的代码:
readPcap()
{
//Filter packages with ip = 192.168.15.40
std::vector<std::string> rmc;
std::string path = "../../imu10000.pcap";
char errbuff[PCAP_ERRBUF_SIZE];
pcap_t *pcap = pcap_open_offline(path.c_str(), errbuff);
struct pcap_pkthdr *header;
const unsigned char *data;
while (int returnValue = pcap_next_ex(pcap, &header, &data) >= 0)
{
if (header->len != header->caplen)
printf("Warning! Capture size different than packet size: %d bytes\n", header->len);
// We also have a function that does this similarly below: PrintData()
for (u_int i=0; (i < header->caplen ) ; i++)
{
// Start printing on the next after every 16 octets
if ( (i % 16) == 0) printf("\n");
// Print each octet as hex (x), make sure there is always two characters (.2).
printf("%.2x ", data[i]);
}
}
}
目前,代码正在以十六进制打印所有包的所有正文,但我在文件中有 10,000 个包,其中一半来自其他 IP。
你知道如何按 IP 过滤,这样我就可以只读取我需要的包了吗?
如果您知道另一种读取 pcap 文件并过滤它们的方法,也将受到欢迎。
谢谢
【问题讨论】: