2010-10-21 121 views
2

我正在编写使用原始套接字监视FTP流量的程序。现在,我能够确定使用此代码TCP报文数据的起始位置:如何确定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等)

谢谢。

+0

你指的是什么'struct tcphdr'? – Dummy00001 2010-10-21 10:53:31

回答

相关问题