帮助使用 pcap 库嗅探数据包

发布于 2024-08-26 09:39:55 字数 309 浏览 5 评论 0原文

我正在使用 pcap 示例代码来创建我自己的嗅探器。我下载了他们的示例嗅探器,它可以在 Windows 上运行,但不能在 Linux 上运行。我在两台机器上都使用 gcc 编译器,并且只包含 pcap.h。
错误是:取消引用指向不完整类型的指针。
网络掩码导致错误。网络掩码是接口第一个地址的掩码。

u_int netmask=netmask((struct sockaddr_in*)d->addresses->netmask))->sin_addr.S_un.S_addr;  

有什么解决办法吗?

i am using pcap sample codes to create my own sniffer. i downloaded their sample sniffer and its working on windows but not on linux. i am using gcc compiler on both machines, and i have only pcap.h included.
the error is : dereferencing pointer to incomplete type.
the netmask is causing the error. the netmask is the mask of the first address of the interface.

u_int netmask=netmask((struct sockaddr_in*)d->addresses->netmask))->sin_addr.S_un.S_addr;  

any solutions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撑一把青伞 2024-09-02 09:39:55

编译器表明它的作用域中没有 struct sockaddr_in 的定义,因此它无法查看这样的结构内部。在 Linux 上,该结构体在此标头中定义,您需要包含该标头:

#include <netinet/in.h>

The compiler indicating that it doesn't have the definition of struct sockaddr_in in scope, so it can't look inside such a structure. On Linux that struct is defined in this header, which you will need to include:

#include <netinet/in.h>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文