如何从 C 语言的 pcap 获取网络层和传输层协议?
我正在做一项作业,要求我使用 libpcap 库从 C 语言的 pcap 文件中解析信息。我已经成功地弄清楚如何获取数据,例如源/目标 IP 地址、tcp/udp 端口和源/目标以太网地址。列表中的下一个是从所看到的网络和传输层协议获取统计信息以及每个协议有多少个数据包。恐怕我似乎不太清楚如何访问此内容,并希望有人能给我指出正确的方向。由于其他信息是从 /usr/include/netinet.h 等位置的各种数据结构中收集到的,因此这也应该位于其中,但是,我又有点迷失了。
I am working on an assignment that has me parsing information from a pcap file in C using the libpcap library. I have had success in figuring out how to get data such as the source/dest ip addresses, tcp/udp ports, and source/dest ethernet addresses. Next on the list is to get stats from network and transport layer protocols seen and how many packets per protocol. I'm afraid I can't quite seem to figure out how to get access to this and am hoping someone might point me in the right direction. Since the other information has been gleaned from various data structures from within places like /usr/include/netinet.h this should be somewhere in there as well, but, again, I'm a bit lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来你已经有了答案...IP 是一个网络层协议,所以如果你能找到 IP 地址,你就可以计算 IP 数据包。同样,TCP 和 UDP 都是传输层协议。如果您可以在数据包中找到 TCP/UDP 端口,那么您就已经知道有多少数据包正在使用哪些协议。
It seems like you already have the answers...IP is a network layer protocol, so if you can find the IP address you can count IP packets. Similarly, TCP and UDP are transport layer protocols. If you can find the TCP/UDP ports in the packets then you already know how many packets are using which protocols.
在你的回调函数中
In your callback function