我正在使用pcap库,但我不知道为什么我总是得到这个输出:
大小的新数据包:udata = 8 hdr = 8 pkt = 8
这是代码:
void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt)
{
DEBUG("DANY new packet with size: udata= %d hdr=%d pkt=%d", (int) sizeof(udata),(int) sizeof(hdr),(int) sizeof(pkt) );
...
stuff
}
Run Code Online (Sandbox Code Playgroud)
在我使用的另一个文件中:
status = pcap_loop (pcap_obj,
-1 /* How many packets it should sniff for before returning (a negative value
means it should sniff until an error occurs (loop forever) ) */,
handle_pcap /* Callback that will be called*/,
NULL /* Arguments to send to the callback (NULL is nothing) */);
Run Code Online (Sandbox Code Playgroud)
输出是正常的吗?
我想并不是因为有时候我的程序有时不起作用.
您正在打印指针的大小,而不是查看pcap_pkthdr*hdr以查看数据包的大小.
您可以通过查看hdr-> caplen和hdr-> len来查找捕获数据的大小和整个数据包的大小.