简体   繁体   English

在TCP数据包结构中计算有效负载

[英]Calculating payload in a tcp packet structure

When i want to split a tcp packet and print every part (eth/ip/tcp/payload) separately, how do i calculate the end of the payload? 当我想分割一个TCP数据包并分别打印每个部分(eth / ip / tcp / payload)时,如何计算有效载荷的结尾?

PrintData(Buffer, iphdrlen);
PrintData(Buffer + iphdrlen, tcpheader->data_offset*4);
PrintData(Buffer + iphdrlen + tcpheader->data_offset*4, ??? );

I tried 我试过了

PrintData( Buffer + iphdrlen + tcpheader->data_offset*4, ( Size - tcpheader->data_offset*4 - iphdr->ip_header_len*4 ) );

but all the packets was truncated. 但是所有数据包都被截断了。 Which value have i to pass here? 我在这里传递什么值?

Greetings 问候

IP Header contains the length with the size of the IP header and payload. IP标头包含IP标头和有效负载大小的长度。 Also IP header contains IP header size field which equal the number of 32-bit words : IP标头还包含IP标头大小字段,该字段等于32位字的数量

PrintData(Buffer + (iphdrlen * 4) + tcpheader->data_offset * 4, iplen - (iphdrlen * 4 + tcpheader->data_offset * 4));

As I undestand, you forgot to multiply iphdrlen by 4 in offset 不知所措,您忘记将iphdrlen乘以4的偏移量

TCP format gives the meaning of each field in the TCP header, including details like where the packet data starts and the packet data length. TCP格式给出了TCP标头中每个字段的含义,包括诸如数据包数据的起始位置和数据包数据长度之类的详细信息。

Note that items in the TCP packet header use 'network order' for each of the fields 请注意,TCP数据包标题中的项目对每个字段均使用“网络顺序”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM