[英]printing sequence number of a sniffed packet
我正在使用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)嗎? 因為它不是這樣工作的!
我的另一個問題是變量聲明后的數字是多少?
4在tcph_hlen中是什么意思:4
如果編程語言是C,請注意您的結構不正確,因為您沒有指定字段的大小。 例如,序列號是32位,“ int”可以是16位或64位。 對於seqnum,應使用uint32_t。
這就是說,如果您已經從網絡中讀取了TCP數據包,則序列號是按網絡順序(big-endian)排列的,因此,要打印該序列號,您需要調用ntohl(網絡到主機-長)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.