问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/21214148/how-to-read-a-pcap-file-in-c-to-get-the-packet-information