gpt4 book ai didi

c - 修改捕获的pcap并写回

转载 作者:行者123 更新时间:2023-11-30 15:47:12 25 4
gpt4 key购买 nike

我需要读取捕获的 pcap 文件,该文件包含由 FPGA 在文件开头紧接 MAC 头之后附加的一些专有描述符,向描述符添加额外的 2 个字节并写回。

我正在尝试在 Linux 上使用 libpcap 库在 C 中实现这一点。我是否正确,我需要调用 pcap_dump_open() 和 pcap_dump() 来写入缓冲区?另外,在使用 pcap_dump 写入缓冲区之前,我是否需要相应地从 pcap_pkthdr 中增加 caplen 和 'len'(添加 2)?

提前致谢!

最佳答案

I need to read captured pcap file, that contains some proprietary descriptor appended by FPGA at the start of file right after MAC header

所以数据包格式按顺序为:

  • MAC header
  • 专有描述符
  • 有效负载

add extra 2 bytes to the descriptor and write back.

那么专有描述符将变得长 2 个字节,从而将有效负载向下移动两个字节?

I'm trying to implement this in C using libpcap library on linux. Am I right that I will need to call pcap_dump_open() and pcap_dump() to write buffer?

这可能是最简单的方法。

Also, is is true that I'll need to increment caplen and and 'len' from pcap_pkthdr accordingly (add 2) prior writing the buffer with pcap_dump?

如果您要向数据包添加 2 个字节,是的,您需要同时增加 caplenlen pcap_pkthdr 的字段在写出数据包之前按 2 进行结构。

除非您确定 caplen足够大以包含 MAC header 和专有描述符中的所有数据,直到您添加相关的 2 个字节为止,您还应该检查以确保它是,如果不是,不要修改有问题的数据包,只修改 len ,不是caplen ,对于该特定数据包。

关于c - 修改捕获的pcap并写回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17624450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com