libpcap 数据包头结构有 2 个长度字段:
typedef struct pcaprec_hdr_s {
guint32 ts_sec; /* timestamp seconds */
guint32 ts_usec; /* timestamp microseconds */
guint32 incl_len; /* number of octets of packet saved in file */
guint32 orig_len; /* actual length of packet */
} pcaprec_hdr_t;
incl_len:实际捕获并保存在文件中的数据包数据的字节数。该值永远不应大于 orig_len 或全局 header 的 snaplen 值。
orig_len:捕获数据包时出现在网络上的长度。如果 incl_len 和 orig_len 不同,则实际保存的数据包大小受到 snaplen 的限制。
谁能告诉我这两个长度字段有什么区别?我们将数据包完全保存在其中,那么两者有何不同?
最佳答案
阅读 Wireshark wiki ( http://wiki.wireshark.org/Development/LibpcapFileFormat ) 上的文档并研究示例 pcap 文件,看起来 incl_len 和 orig_len 通常是相同的数量。它们唯一不同的情况是数据包的长度超过了 snaplen 的大小,该大小在文件的全局 header 中指定。
我只是在这里猜测,但我想 snaplen 指定了用于捕获的静态缓冲区的大小。如果数据包对于捕获缓冲区来说太大,则这是该格式用于表明这一事实的方法。 snaplen 被记录为“通常”是 65535,这对于大多数数据包来说已经足够大了。但文档规定大小可能会受到用户的限制。
关于c - libpcap 格式 - 数据包 header - incl_len/orig_len,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9611929/