1. 程式人生 > >IP資料包頭部,TCP頭部,偽TCP頭部結構定義

IP資料包頭部,TCP頭部,偽TCP頭部結構定義

我自己整理出來的彙編版本

;;IP資料包頭部結構定義
ip_head struct
     h_lenver db ? ;4位IP版本號+4位首部長度
     TOS db ? ;8位服務型別
     tcp_len dw ? ;16位TCP資料包總長度
    ident dw ? ;16位標識
    frag_and_flags dw ? ;3位分片標誌+13位分片偏移
    ttl db ? ;8位生存時間
     proto db ? ;8位協議型別
     checksum dw ? ;16位校驗和
    sourceIP dd ? ;32位源IP
     destIP dd ? ;32位目的IP
ip_head ends

;;TCP頭部結構定義
tcp_head struct
    th_sport dw ? ;16位源埠
     th_dport dw ? ;16位目的埠
     th_seq dd ? ;32位序列號
    th_ack dd ? ;32位確認號
    th_lenres db ? ;4位首部長度+6位保留字,注意這個欄位和下面的標誌共16位,因6位保留為0,為了定義方便所以填充時可按8位填充兩個欄位
     th_flag db ? ;6位標誌位
     th_win dw ? ;16位視窗大小
    th_sum dw ? ;16位校驗和
     th_urp dw ? ;16位緊急資料偏移量
tcp_head ends

;;偽TCP頭部結構定義,偽TCP頭部是用來求效驗和的
wtcp_head struct
     saddr dd ? ;32位IP頭部裡的源地址
     daddr dd ? ;32位IP頭部裡的目的地址
     mbz db ? ;8位全0
     ptcl db ? ;8位協議型別,TCP是6
     tcpl dw ? ;16位TCP總長度
wtcp_head ends