-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipv4.h
162 lines (95 loc) · 2.51 KB
/
ipv4.h
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef __IPV4_H__
#define __IPV4_H__
#define u32 unsigned int
#define u16 unsigned short
#define u8 unsigned char
typedef struct
{
/* Header length, in u32:s. */
u8 header_length: 4;
u8 version: 4;
u8 type_of_service;
u16 total_length;
u16 id;
u16 fragment_offset;
u8 time_to_live;
u8 protocol;
/* Two-complement additive checksum. */
u16 checksum;
u32 source_address;
u32 destination_address;
u8 data[0];
} __attribute__ ((packed)) ipv4_header_type;
typedef struct
{
/* Saved first hop address. */
u32 first_hop_address;
u8 optlen;
u8 srr;
u8 rr;
u8 ts;
/* Set by setsockopt? */
u8 is_setbyuser: 1;
/* Options in __data, rather than skb. */
u8 is_data: 1;
/* Strict source route. */
u8 is_strictroute: 1;
/* Packet destination address was our one. */
u8 srr_is_hit: 1;
/* IP checksum more not valid. */
u8 is_changed: 1;
/* Need to record addr of outgoing device. */
u8 rr_needaddr: 1;
/* Need to record timestamp. */
u8 ts_needtime: 1;
/* Need to record addr of outgoing device. */
u8 ts_needaddr: 1;
u8 router_alert;
u8 __pad1;
u8 __pad2;
/* Data start here. */
u8 data[0];
} __attribute__ ((packed)) ipv4_options_type;
typedef struct
{
ipv4_header_type header;
ipv4_options_type options;
/* Data starts here. */
u8 data[0];
} __attribute__ ((packed)) ipv4_packet_type;
typedef struct
{
/* The source port number. */
u16 source_port;
/* The destination port number. */
u16 destination_port;
/* The sequence number of the first data octet. */
u32 sequence_number;
/* If ack is set, contains the value of the next sequence number. */
u32 acknowledgement_number;
u16 reserved : 4;
/* The number of 32 bit words in the TCP header. */
u16 data_offset : 4;
/* No more data from sender. */
u16 finish : 1;
/* Synchronise sequence numbers. */
u16 synchronise : 1;
/* Reset the connection. */
u16 reset : 1;
/* Push function. */
u16 push : 1;
/* Acknowledgement field significant. */
u16 acknowledge : 1;
/* Urgent pointer field signicant. */
u16 urgent : 1;
u16 reserved2 : 2;
/* The number of data octets the sender is willing to accept. */
/* Checksum of header, data and the 'pseudo header (see RFC for more
information). */
u16 checksum;
/* Points to the sequence number of the octet following the urgent
data. */
u16 urgent_pointer;
/* End of header; start of options. */
} __attribute__ ((packed)) tcp_header_type;
#endif