代码片段来自here https://www.winpcap.org/docs/docs_40_2/html/group__wpcap__tut6.html:
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(定义 https://www.winpcap.org/docs/docs_40_2/html/structpcap__pkthdr.html),我们什么时候需要它,它是如何填充的(因为数据包本身没有这样的信息,如下所示)?
(source: lewis at www.dcs.gla.ac.uk http://www.dcs.gla.ac.uk/~lewis/networkpages/m04s03EthernetFrame_files/image002.gif)
如果您保留评论,事情会容易一些。它说:
/* Callback function invoked by libpcap for every incoming packet */
Here http://www.winpcap.org/docs/docs_40_2/html/group__wpcapfunc.html它说的是typedef void(*) pcap_handler(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data)
:
pkt_header
是关联的标题
由捕获驱动程序发送到数据包。
它不是协议头。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)