IP头和TCP头数据结构(C#版)
转自[DotNet笔记]
IP头和TCP头数据结构(C#版)
IP头和TCP头数据结构(C#版)
1
public struct ip_hdr //IP头
2
{
3
public byte h_lenver; //4位首部长度+4位IP版本号
4
public byte tos; //8位服务类型TOS
5
public ushort total_len; //16位总长度(字节)
6
public ushort ident; //16位标识
7
public ushort frag_and_flags; //3位标志位+13报片偏移
8
public byte ttl; //8位生存时间 TTL
9
public byte proto; //8位协议 (TCP, UDP 或其他)
10
public ushort checksum; //16位IP首部校验和
11
public uint sourceIP; //32位源IP地址
12
public uint destIP; //32位目的IP地址
13
}
14
public struct tcp_hdr //TCP头
15
{
16
public ushort th_sport; //16位源端口
17
public ushort th_dport; //16位目的端口
18
public uint th_seq; //32位序列号
19
public uint th_ack; //32位确认号
20
public byte th_lenres; //4位首部长度/6位保留字
21
public byte th_flag; //6位标志位
22
public ushort th_win; //16位窗口大小
23
public ushort th_sum; //16位校验和
24
public ushort th_urp; //16位紧急数据偏移量
25
}
26

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26
