2010-05-09 3 views
2

Extrait de code de here:À quoi sert pcap_pkthdr?

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 
    .... 

Qu'est-ce que est const struct pcap_pkthdr *header pour (definition), quand avons-nous besoin, comment est-elle peuplée (car il n'y a pas d'information dans le paquet lui-même comme ci-dessous)?

alt text http://www.dcs.gla.ac.uk/~lewis/networkpages/m04s03EthernetFrame_files/image002.gif

Répondre

3

Si vous avez gardé le commentaire, il aurait été un peu plus facile. Il dit:

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

Here il dit à propos typedef void(*) pcap_handler(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data):

pkt_header est l'en-tête associé par le pilote de capture au paquet. Ce n'est PAS un en-tête de protocole.