当前位置: Home > 安全编程 > 网络编程 > 文章
|
|
黑客之旅 -- 原始套接字透析之前言
|
文章来源: 天极开发
文章作者: 宋宝华
发布时间: 2006-11-11
字体:
[大
中
小]
|
|
unsigned char tos; unsigned short total_len; unsigned short ident; unsigned short frag_and_flags; unsigned char ttl; unsigned char proto; unsigned short checksum; unsigned int sourceIP; unsigned int destIP; } IP_HEADER;
|
TCP报头结构为:
源端口(16)
|
目的端口(16)
|
序列号(32)
|
确认号(32)
|
TCP偏移量(4)
|
保留(6)
|
标志(6)
|
窗口(16)
|
校验和(16)
|
紧急(16)
|
选项(0或32)
|
数据(可变)
|
对应数据结构:
typedef struct psd_hdr //定义TCP伪报头 { unsigned long saddr; //源地址 unsigned long daddr; //目的地址 char mbz; char ptcl; //协议类型 unsigned short tcpl; //TCP长度 }PSD_HEADER; typedef struct _tcphdr //定义TCP报头 { unsigned short th_sport; //16位源端口 unsigned short th_dport; //16位目的端口 unsigned int th_seq; //32位序列号 unsigned int th_ack; //32位确认号 unsigned char th_lenres; //4位首部长度/4位保留字 unsigned char th_flag; //6位标志位 unsigned short th_win; //16位窗口大小 unsigned short th_sum; //16位校验和 unsigned short th_urp; //16位紧急数据偏移量 } TCP_HEADER; |
同样地,TCP头的定义也可以将位域拆分:
typedef struct _tcphdr { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; /*little-endian*/ unsigned short tcp_res1: 4, tcp_hlen: 4, tcp_fin: 1, tcp_syn: 1, tcp_rst: 1, tcp_psh: 1, tcp_ack: 1, tcp_urg: 1, tcp_res2: 2; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; } TCP_HEADER; |
共4页: 上一页 [1] [2] 3 [4] 下一页
|
|
↑返回顶部
打印本页
关闭窗口↓
|
|
|
|