Debian Codegraph @

share/libc/netinet/ip.h

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 // This is a non-POSIX file, provided for better compatibility on a
24 // best-effort basis.
25
26 #ifndef __NETINET_IP_H
27 #define __NETINET_IP_H
28 #include "../features.h"
29 __PUSH_FC_STDLIB
30 __BEGIN_DECLS
31 #include "../__fc_inet.h"
32
33 // The definitions below suppose a little endian architecture.
34
35 struct timestamp
36 {
37 uint8_t len;
38 uint8_t ptr;
39 unsigned int flags:4;
40 unsigned int overflow:4;
41 uint32_t data[9];
42 };
43
44 struct iphdr
45 {
46 unsigned int ihl:4;
47 unsigned int version:4;
48 uint8_t tos;
49 uint16_t tot_len;
50 uint16_t id;
51 uint16_t frag_off;
52 uint8_t ttl;
53 uint8_t protocol;
54 uint16_t check;
55 uint32_t saddr;
56 uint32_t daddr;
57 };
58
59 struct ip
60 {
61 unsigned int ip_hl:4;
62 unsigned int ip_v:4;
63 uint8_t ip_tos;
64 unsigned short ip_len;
65 unsigned short ip_id;
66 unsigned short ip_off;
67 uint8_t ip_ttl;
68 uint8_t ip_p;
69 unsigned short ip_sum;
70 struct in_addr ip_src, ip_dst;
71 };
72
73 #define IP_RF 0x8000
74 #define IP_DF 0x4000
75 #define IP_MF 0x2000
76 #define IP_OFFMASK 0x1fff
77
78 struct ip_timestamp
79 {
80 uint8_t ipt_code;
81 uint8_t ipt_len;
82 uint8_t ipt_ptr;
83 unsigned int ipt_flg:4;
84 unsigned int ipt_oflw:4;
85 uint32_t data[9];
86 };
87
88 #define IPVERSION 4
89 #define IP_MAXPACKET 65535
90
91 #define IPTOS_ECN_MASK 0x03
92 #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK)
93 #define IPTOS_ECN_NOT_ECT 0x00
94 #define IPTOS_ECN_ECT1 0x01
95 #define IPTOS_ECN_ECT0 0x02
96 #define IPTOS_ECN_CE 0x03
97
98 #define IPTOS_DSCP_MASK 0xfc
99 #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK)
100 #define IPTOS_DSCP_AF11 0x28
101 #define IPTOS_DSCP_AF12 0x30
102 #define IPTOS_DSCP_AF13 0x38
103 #define IPTOS_DSCP_AF21 0x48
104 #define IPTOS_DSCP_AF22 0x50
105 #define IPTOS_DSCP_AF23 0x58
106 #define IPTOS_DSCP_AF31 0x68
107 #define IPTOS_DSCP_AF32 0x70
108 #define IPTOS_DSCP_AF33 0x78
109 #define IPTOS_DSCP_AF41 0x88
110 #define IPTOS_DSCP_AF42 0x90
111 #define IPTOS_DSCP_AF43 0x98
112 #define IPTOS_DSCP_EF 0xb8
113
114 #define IPTOS_CLASS_MASK 0xe0
115 #define IPTOS_CLASS(class) ((class) & IPTOS_CLASS_MASK)
116 #define IPTOS_CLASS_CS0 0x00
117 #define IPTOS_CLASS_CS1 0x20
118 #define IPTOS_CLASS_CS2 0x40
119 #define IPTOS_CLASS_CS3 0x60
120 #define IPTOS_CLASS_CS4 0x80
121 #define IPTOS_CLASS_CS5 0xa0
122 #define IPTOS_CLASS_CS6 0xc0
123 #define IPTOS_CLASS_CS7 0xe0
124
125 #define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0
126
127 #define IPTOS_TOS_MASK 0x1E
128 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
129 #define IPTOS_LOWDELAY 0x10
130 #define IPTOS_THROUGHPUT 0x08
131 #define IPTOS_RELIABILITY 0x04
132 #define IPTOS_LOWCOST 0x02
133 #define IPTOS_MINCOST IPTOS_LOWCOST
134
135 #define IPTOS_PREC_MASK IPTOS_CLASS_MASK
136 #define IPTOS_PREC(tos) IPTOS_CLASS(tos)
137 #define IPTOS_PREC_NETCONTROL IPTOS_CLASS_CS7
138 #define IPTOS_PREC_INTERNETCONTROL IPTOS_CLASS_CS6
139 #define IPTOS_PREC_CRITIC_ECP IPTOS_CLASS_CS5
140 #define IPTOS_PREC_FLASHOVERRIDE IPTOS_CLASS_CS4
141 #define IPTOS_PREC_FLASH IPTOS_CLASS_CS3
142 #define IPTOS_PREC_IMMEDIATE IPTOS_CLASS_CS2
143 #define IPTOS_PREC_PRIORITY IPTOS_CLASS_CS1
144 #define IPTOS_PREC_ROUTINE IPTOS_CLASS_CS0
145
146 #define IPOPT_COPY 0x80
147 #define IPOPT_CLASS_MASK 0x60
148 #define IPOPT_NUMBER_MASK 0x1f
149
150 #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
151 #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
152 #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
153
154 #define IPOPT_CONTROL 0x00
155 #define IPOPT_RESERVED1 0x20
156 #define IPOPT_DEBMEAS 0x40
157 #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
158 #define IPOPT_RESERVED2 0x60
159
160 #define IPOPT_EOL 0
161 #define IPOPT_END IPOPT_EOL
162 #define IPOPT_NOP 1
163 #define IPOPT_NOOP IPOPT_NOP
164
165 #define IPOPT_RR 7
166 #define IPOPT_TS 68
167 #define IPOPT_TIMESTAMP IPOPT_TS
168 #define IPOPT_SECURITY 130
169 #define IPOPT_SEC IPOPT_SECURITY
170 #define IPOPT_LSRR 131
171 #define IPOPT_SATID 136
172 #define IPOPT_SID IPOPT_SATID
173 #define IPOPT_SSRR 137
174 #define IPOPT_RA 148
175
176 #define IPOPT_OPTVAL 0
177 #define IPOPT_OLEN 1
178 #define IPOPT_OFFSET 2
179 #define IPOPT_MINOFF 4
180
181 #define MAX_IPOPTLEN 40
182
183 #define IPOPT_TS_TSONLY 0
184 #define IPOPT_TS_TSANDADDR 1
185 #define IPOPT_TS_PRESPEC 3
186
187 #define IPOPT_SECUR_UNCLASS 0x0000
188 #define IPOPT_SECUR_CONFID 0xf135
189 #define IPOPT_SECUR_EFTO 0x789a
190 #define IPOPT_SECUR_MMMM 0xbc4d
191 #define IPOPT_SECUR_RESTR 0xaf13
192 #define IPOPT_SECUR_SECRET 0xd788
193 #define IPOPT_SECUR_TOPSECRET 0x6bc5
194
195 #define MAXTTL 255
196 #define IPDEFTTL 64
197 #define IPFRAGTTL 60
198 #define IPTTLDEC 1
199
200 #define IP_MSS 576
201
202 __END_DECLS
203 __POP_FC_STDLIB
204
205 #endif