這裏抄兩個 定義的 TCP 和 IP 結構體 以後用到方便
IP數據報報頭有一個長度爲4位的首部長度,長度爲16位的總長度。
首部長度是指首部長度爲32比特的倍數(即4個字節的整數倍,或者說其單位爲4個字節)。
struct IPHEAD
{
unsigned char h_len:4;//4位首部長度+4位IP版本號
unsigned char ver:4;
unsigned char tos;//8位服務類型TOS
unsigned short total_len;//16位總長度(字節) IP數據報長度 單位 爲字節
unsigned short ident;//16位標識
unsigned short frag_and_flags;//3位標誌位
unsigned char ttl;//8位生存時間 TTL
unsigned char proto;//8位協議 (TCP, UDP 或其他)
unsigned short checksum;//16位IP首部校驗和
unsigned int sourceip;//32位源IP地址
unsigned int destip;//32位目的IP地址
};
struct TCPHEAD //定義TCP首部
{
USHORT th_sport; //16位源端口
USHORT th_dport; //16位目的端口
unsigned int th_seq; //32位序列號
unsigned int th_ack; //32位確認號
unsigned char th_lenres; //4位首部長度/6位保留字
unsigned char th_flag; //6位標誌位
USHORT th_win; //16位窗口大小
USHORT th_sum; //16位校驗和
USHORT th_urp; //16位緊急數據偏移量
};