如何在c ++中读取pcap文件以获取数据包信息? [英] how to read a pcap file in c++ to get the packet information?
问题描述
我想用 C++ 编写一个程序来读取 pcap 文件并获取数据包的信息,例如 len、sourc ip、flags 等.现在我找到了如下代码,我认为它会帮助我获得信息,但我有一些问题:首先我想知道我应该将哪个库添加到我的程序中,然后什么是 pcap_next,以及如何从 pcap 文件中获取句柄?
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?
/* 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);
推荐答案
您需要将您的应用程序与 libpcap<链接/a>.要获得句柄,您应该使用 pcap_open_offline
.pcap_next
从句柄读取下一个数据包.
You'll need to link your application with libpcap. To get a handle, you should use pcap_open_offline
. pcap_next
reads the next packet from the handle.
这篇关于如何在c ++中读取pcap文件以获取数据包信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!