2010-10-21 127 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

回答

相關問題