gpt4 book ai didi

c - 如何确定TCP数据包中数据有效载荷的开始?

转载 作者:可可西里 更新时间:2023-11-01 02:41:52 24 4
gpt4 key购买 nike

我正在编写使用原始套接字监控 FTP 流量的程序。现在,我可以使用以下代码确定 TCP 数据包中数据的开始:

// char * packet;
// struct * iphdr;
// struct * tcphdr;

// ...
// check, whether sniffed ethernet frame contains IP and TCP


char * data;
data = (packet + sizeof (struct ethhdr) + sizeof (struct tcphdr) + (header_ip->ihl * 4) + header_tcp->doff) + 4;

这工作正常,但我必须将“魔法”数字 4 添加到数据指针。如果不添加它,最终的字符串将以几个无意义的字符开头。

是否有任何干净的解决方案来确定传输数据的开始? (不使用任何专门的库,如 libcap 等)

谢谢。

最佳答案

检查 RFC 793 中的 header 规范, RFC 1122 , 和 RFC 3168 .一些标志会影响 header 大小,最明显的是选项最大段大小 字段。

关于c - 如何确定TCP数据包中数据有效载荷的开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3985149/

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