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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With