libpcap 数据包大小

发布于 2024-08-27 15:51:56 字数 304 浏览 9 评论 0原文

I'm working with libpcap in C on linux (centos) and I'm following this guide I want to simply print out the entire packet in ascii and i'v managed to get it working by casting it a u_char* in the "my_callback" function. But I can't figure out how to get the length of the data. strstr didn't work. the header has a len member that you can access to get the size but I can't find anything similar for the *packet being passed. Any help is appreciated.

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

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

发布评论

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

评论(2

等待我真够勒 2024-09-03 15:51:57

在回调中,pkthdr 变量的 caplen 成员(请参阅 struct pcap_pkthdr)包含捕获的数据包的大小。

例如,假设捕获了一个数据包。帧的总长度为1024字节。但是,捕获驱动程序仅捕获帧的前 128 个字节并使其可供回调使用。

在这种情况下,您应该期望 pkthdr->caplen 为 128,而 header->len 为 1024。

In your callback the caplen member of the pkthdr variable (see struct pcap_pkthdr) contains the size of the captured packet.

For example assume a packet is captured. The total length of the frame is 1024 bytes. However the capture driver only captured the first 128 bytes of the frame and made it available to your callback.

In this case you should expect pkthdr->caplen to be 128 and header->len to be 1024.

ヅ她的身影、若隐若现 2024-09-03 15:51:57

总数据包大小位于 ip 标头的“总长度”字段中 (http://en. wikipedia.org/wiki/IPv4_header#Total_Length)。

如何使用 libpcap 获取该值可以在此示例中找到:http://www.tcpdump.org/sniffex.c

您只需从以下位置获取引用“总长度”(名为 ip_len)的字段值:这个变量:

const struct sniff_ip *ip;              /* The IP header */

The total packet size is at the "total length" field at the ip header (http://en.wikipedia.org/wiki/IPv4_header#Total_Length).

How to get that value with libpcap can be found at this example: http://www.tcpdump.org/sniffex.c

You just have to get the value of the field that references to the "total length" (named ip_len) from this variable:

const struct sniff_ip *ip;              /* The IP header */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文