struct pcap_pkthdr len 总是 == 0
在不复制此处所有源代码的情况下,我从 pcap_dispatch
调用了 pcap_callback
函数。 caplen
似乎显示了正确的长度(因为它始终是某物),但 len 始终等于 0。该字段是否不再填充?这可能是我没有捕获的错误情况吗?
这是一个片段...
void myCallback ( const struct pcap_pkthdr *header, const u_char *packet, void* buffer )
{
if ( (uint16_t)(header->len) != (uint16_t)(header->caplen) )
/* Some Error */
streamObj << "Caplen (" << (uint16_t)(header->caplen) << " != "
<< ") Packet Len (" << (uint16_t)(header->len) << ")";
...
}
header->len
值始终返回为零。如果需要更多信息,请告诉我。
这是在运行 libpcap.so.0.9.8 和 2.6.32 内核的 SUSE Linux 11SP1 服务器上发现的。该问题仅在使用 libpcap.so.0.9.3 从 SUSE Linux 10SP3 升级后才会出现。
编辑: 这似乎只是 libpcap.so.0.9.8 的问题。我重新指向 /usr/lib/ 中的链接以使用 libpcap.so.0.9.3,问题消失了。
Without copying all of the source in here, I am hitting a pcap_callback
function from pcap_dispatch
. The caplen
seems to show the correct length (being that it is always something) but the len always equals 0. Is this field no longer populated? Is this maybe an error condition I am not capturing?
Here is a snippet...
void myCallback ( const struct pcap_pkthdr *header, const u_char *packet, void* buffer )
{
if ( (uint16_t)(header->len) != (uint16_t)(header->caplen) )
/* Some Error */
streamObj << "Caplen (" << (uint16_t)(header->caplen) << " != "
<< ") Packet Len (" << (uint16_t)(header->len) << ")";
...
}
The header->len
value always comes back as zero. If more info is needed, just let me know.
This was found on a SUSE Linux 11SP1 server running libpcap.so.0.9.8 with a 2.6.32 kernel. The issue is only present after upgrading from SUSE Linux 10SP3 with libpcap.so.0.9.3.
EDIT:
This appears to only be an issue with libpcap.so.0.9.8. I repointed the link in /usr/lib/ to use libpcap.so.0.9.3 and the problem disappeared.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pcap_dispatch()
回调函数的三个参数按顺序依次为:pcap_dispatch()
的“用户数据”指针;因此,myCallback 不是有效的回调函数,并且不能传递给 pcap_dispatch(),因为它期望第一个参数是指向 struct pcap_pkthdr 的指针。除非您有另一个函数是真正的回调,然后使用适当的参数调用 myCallback,否则相关代码将无法工作,并且至少应该收到来自 C 或 C++ 编译器的警告。
The three arguments to a callback function for
pcap_dispatch()
are, in order:pcap_dispatch()
;struct pcap_pkthdr
;Therefore,
myCallback
is not a valid callback function, and can't be passed to pcap_dispatch(), as it's expecting the first argument to be the pointer to thestruct pcap_pkthdr
. Unless you have another function that's the real callback, which then callsmyCallback
with the appropriate arguments, the code in question won't work, and should get at least a warning from a C or C++ compiler.