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

﹥>﹥吖頭↗ 提交于 2019-12-08 05:45:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!