简体   繁体   English

如何在c ++中读取pcap文件以获取数据包信息?

[英]how to read a pcap file in c++ to get the packet information?

I want to write a program in c++ to read a pcap file and get the information of packets , like len,sourc ip, flags and etc. now I found the code like below and I think it will help me to get the information, but I have some questions: at the first I want to know which library should I add to my program and after that what is pcap_next,and how can I get the handle from a pcap file? 我想用C ++编写程序以读取pcap文件并获取数据包的信息,例如len,sourc ip,标志等。现在我发现了如下代码,我认为它将帮助我获取信息,但是我有一些问题:首先,我想知道应该将哪个库添加到程序中,然后是pcap_next,以及如何从pcap文件中获取句柄?

/* Grab a packet */
packet = pcap_next(handle, &header);
if (packet == NULL) {   /* End of file */
    break;
}
printf ("Got a packet with length of [%d] \n",
        header.len);

You'll need to link your application with libpcap . 您需要将应用程序与libpcap链接。 To get a handle, you should use pcap_open_offline . 要获取句柄,应使用pcap_open_offline pcap_next reads the next packet from the handle. pcap_next从句柄读取下一个数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM