gpt4 book ai didi

c - pcap 为什么总是 8 字节的数据包...为什么?

转载 作者:太空宇宙 更新时间:2023-11-04 05:21:35 25 4
gpt4 key购买 nike

我正在使用 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
}

在我使用的另一个文件中:

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) */);

输出正常吗?

我认为不是,因为有时我的程序可以运行,有时却不能运行..

最佳答案

您正在打印指针的大小,而不是查看 pcap_pkthdr* hdr 来查看数据包的大小。

您可以通过查看hdr->caplenhdr->len 来找到捕获数据的大小和整个数据包的大小。

关于c - pcap 为什么总是 8 字节的数据包...为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4472756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com