pcap 为什么总是 8 字节的数据包...为什么?
我正在使用 pcap 库,但我不知道为什么我总是得到这个输出:
new packet with size: 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) */);
这正常吗输出?
我认为不是因为我的程序有时能工作有时不能..
I'm using the pcap library but I don't know why I get always this output:
new packet with size: udata= 8 hdr=8 pkt=8
This is the code:
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
}
and in another file I use:
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) */);
Is it normal that output?
I think not because sometimes my program works sometimes doesn't..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在打印指针的大小,而不是查看 pcap_pkthdr* hdr 来查看数据包的大小。
通过查看hdr->caplen和hdr->len可以找到捕获数据的大小和整个数据包的大小。
You are printing the size of the pointers instead of looking into the pcap_pkthdr* hdr to see the size of the packet.
You can find the size of the captured data and the size of the entire packet by looking at hdr->caplen and hdr->len.
嗯。您正在获取(各种)指针的大小。
例如,
sizeof(udata)
获取u_char *
的大小。这就是为什么这些数字看起来很可疑。如果您想要数据包的大小,它们位于
hdr->caplen
和hdr->len
中(前者是捕获的长度,后者是数据包长度)。Um. You are getting the size of (the various) pointers.
e.g.
sizeof(udata)
gets the size of au_char *
. That's why the numbers look suspect.If you want the sizes of the packets, they are in
hdr->caplen
andhdr->len
(the former is the captured length, the latter is the packet length).