pcap为什么总是包含8字节的数据包。。。为什么?
我正在使用pcap库,但我不知道为什么我总是得到这样的输出: 大小为:udata=8 hdr=8 pkt=8的新数据包 代码如下:pcap为什么总是包含8字节的数据包。。。为什么?,c,pcap,C,Pcap,我正在使用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),
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
}
在我使用的另一个文件中:
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) */);
输出正常吗
我想不是因为我的程序有时能工作有时不能…嗯。您将获得各种指针的大小 e、 g.sizeofudata获取u_字符*的大小。这就是数字看起来可疑的原因
如果您想要数据包的大小,它们在hdr->caplen和hdr->len中。前者是捕获的长度,后者是数据包的长度。您正在打印指针的大小,而不是查看pcap_pkthdr*hdr以查看数据包的大小
通过查看hdr->caplen和hdr->len,您可以找到捕获数据的大小和整个数据包的大小。您需要将答案标记为正确。