0
我正在使用pcap創建數據包嗅探器。
我有這個TCP結構:嗅探數據包的打印序列號
typedef struct TSP_header{
unsigned short int sport;
unsigned short int dport;
unsigned int seqnum;
unsigned int acknum;
unsigned char reserved:4, offset:4;
unsigned int
tcp_res1:4, //little-endian
tcph_hlen:4, //length of tcp header in 32-bit words
tcph_fin:1, //Finish flag "fin"
tcph_syn:1, //Synchronize sequence numbers to start a connection
tcph_rst:1, //Reset flag
tcph_psh:1, //Push, sends data to the application
tcph_ack:1, //acknowledge
tcph_urg:1, //urgent pointer
tcph_res2:2;
unsigned short int tcph_win;
unsigned short int tcph_chksum;
unsigned short int tcph_urgptr;
}TSP_header;
我怎樣才能打印序列號?
我應該使用htons(sequence_number)?因爲它不是這樣工作的!
我的另一個問題是變量聲明後的數字是什麼?
tcph_hlen中的4是什麼意思:4
我不認爲ntohl()的作品,因爲它給我負序和確認數字。 – scatman 2010-03-21 07:51:36
ntohl將一個* unsigned *整數作爲參數,併產生一個* unsigned *整數作爲結果。所以,除非你把ntohl的結果放入* signed * int這個大錯誤,否則負數不會發生。顯示你的代碼。 – bortzmeyer 2010-03-22 08:06:57
我給你一個有用的建議:閱讀文檔。 'man 3 printf'會告訴你「d,i int參數被轉換爲帶符號的十進制符號。」我讓你親自看看未簽名的內容需要什麼。 – bortzmeyer 2010-03-23 20:31:01