Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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);
like image 866
user3210586 Avatar asked Dec 28 '25 15:12

user3210586


1 Answers

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.

like image 120
icktoofay Avatar answered Dec 30 '25 04:12

icktoofay