What's pcap_pkthdr there for?

人走茶凉 提交于 2019-12-22 18:11:54

问题


Code snippet from here:

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) 
{ 
    .... 
    /* retireve the position of the ip header */ 
    ih = (ip_header *) (pkt_data + 
        14); //length of ethernet header 
    .... 

What's const struct pcap_pkthdr *header for(definition), when do we need it, how is it populated (since there is no such info in the packet itself as below)?


(source: lewis at www.dcs.gla.ac.uk)


回答1:


If you would have kept the comment, it would have been a tad easier. It says:

/* Callback function invoked by libpcap for every incoming packet */

Here it says about typedef void(*) pcap_handler(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data) :

pkt_header is the header associated by the capture driver to the packet. It is NOT a protocol header.



来源:https://stackoverflow.com/questions/2797089/whats-pcap-pkthdr-there-for

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