1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2009 Free Software
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef __NETINET_IP_H
20 #define __NETINET_IP_H 1
23 #include <sys/types.h>
25 #include <netinet/in.h>
33 #if __BYTE_ORDER == __LITTLE_ENDIAN
35 unsigned int overflow
:4;
36 #elif __BYTE_ORDER == __BIG_ENDIAN
37 unsigned int overflow
:4;
40 # error "Please fix <bits/endian.h>"
47 #if __BYTE_ORDER == __LITTLE_ENDIAN
49 unsigned int version
:4;
50 #elif __BYTE_ORDER == __BIG_ENDIAN
51 unsigned int version
:4;
54 # error "Please fix <bits/endian.h>"
65 /*The options start here. */
70 * Copyright (c) 1982, 1986, 1993
71 * The Regents of the University of California. All rights reserved.
73 * Redistribution and use in source and binary forms, with or without
74 * modification, are permitted provided that the following conditions
76 * 1. Redistributions of source code must retain the above copyright
77 * notice, this list of conditions and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 * 4. Neither the name of the University nor the names of its contributors
82 * may be used to endorse or promote products derived from this software
83 * without specific prior written permission.
85 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
86 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
91 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
92 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
93 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
94 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * @(#)ip.h 8.1 (Berkeley) 6/10/93
101 * Definitions for internet protocol version 4.
102 * Per RFC 791, September 1981.
106 * Structure of an internet header, naked of options.
110 #if __BYTE_ORDER == __LITTLE_ENDIAN
111 unsigned int ip_hl
:4; /* header length */
112 unsigned int ip_v
:4; /* version */
114 #if __BYTE_ORDER == __BIG_ENDIAN
115 unsigned int ip_v
:4; /* version */
116 unsigned int ip_hl
:4; /* header length */
118 u_int8_t ip_tos
; /* type of service */
119 u_short ip_len
; /* total length */
120 u_short ip_id
; /* identification */
121 u_short ip_off
; /* fragment offset field */
122 #define IP_RF 0x8000 /* reserved fragment flag */
123 #define IP_DF 0x4000 /* dont fragment flag */
124 #define IP_MF 0x2000 /* more fragments flag */
125 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
126 u_int8_t ip_ttl
; /* time to live */
127 u_int8_t ip_p
; /* protocol */
128 u_short ip_sum
; /* checksum */
129 struct in_addr ip_src
, ip_dst
; /* source and dest address */
133 * Time stamp option structure.
137 u_int8_t ipt_code
; /* IPOPT_TS */
138 u_int8_t ipt_len
; /* size of structure (variable) */
139 u_int8_t ipt_ptr
; /* index of current entry */
140 #if __BYTE_ORDER == __LITTLE_ENDIAN
141 unsigned int ipt_flg
:4; /* flags, see below */
142 unsigned int ipt_oflw
:4; /* overflow counter */
144 #if __BYTE_ORDER == __BIG_ENDIAN
145 unsigned int ipt_oflw
:4; /* overflow counter */
146 unsigned int ipt_flg
:4; /* flags, see below */
150 #endif /* __USE_BSD */
152 #define IPVERSION 4 /* IP version number */
153 #define IP_MAXPACKET 65535 /* maximum packet size */
156 * Definitions for Explicit Congestion Notification (ECN)
158 * Taken from RFC-3168, Section 5.
161 #define IPTOS_ECN_MASK 0x03
162 #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK)
163 #define IPTOS_ECN_NOT_ECT 0x00
164 #define IPTOS_ECN_ECT1 0x01
165 #define IPTOS_ECN_ECT0 0x02
166 #define IPTOS_ECN_CE 0x03
169 * Definitions for IP differentiated services code points (DSCP)
171 * Taken from RFC-2597, Section 6 and RFC-2598, Section 2.3.
174 #define IPTOS_DSCP_MASK 0xfc
175 #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK)
176 #define IPTOS_DSCP_AF11 0x28
177 #define IPTOS_DSCP_AF12 0x30
178 #define IPTOS_DSCP_AF13 0x38
179 #define IPTOS_DSCP_AF21 0x48
180 #define IPTOS_DSCP_AF22 0x50
181 #define IPTOS_DSCP_AF23 0x58
182 #define IPTOS_DSCP_AF31 0x68
183 #define IPTOS_DSCP_AF32 0x70
184 #define IPTOS_DSCP_AF33 0x78
185 #define IPTOS_DSCP_AF41 0x88
186 #define IPTOS_DSCP_AF42 0x90
187 #define IPTOS_DSCP_AF43 0x98
188 #define IPTOS_DSCP_EF 0xb8
191 * Definitions for IP type of service (ip_tos)
193 #define IPTOS_TOS_MASK 0x1E
194 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
195 #define IPTOS_LOWDELAY 0x10
196 #define IPTOS_THROUGHPUT 0x08
197 #define IPTOS_RELIABILITY 0x04
198 #define IPTOS_LOWCOST 0x02
199 #define IPTOS_MINCOST IPTOS_LOWCOST
202 * Definitions for IP precedence (also in ip_tos) (hopefully unused)
204 #define IPTOS_PREC_MASK 0xe0
205 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
206 #define IPTOS_PREC_NETCONTROL 0xe0
207 #define IPTOS_PREC_INTERNETCONTROL 0xc0
208 #define IPTOS_PREC_CRITIC_ECP 0xa0
209 #define IPTOS_PREC_FLASHOVERRIDE 0x80
210 #define IPTOS_PREC_FLASH 0x60
211 #define IPTOS_PREC_IMMEDIATE 0x40
212 #define IPTOS_PREC_PRIORITY 0x20
213 #define IPTOS_PREC_ROUTINE 0x00
216 * Definitions for options.
218 #define IPOPT_COPY 0x80
219 #define IPOPT_CLASS_MASK 0x60
220 #define IPOPT_NUMBER_MASK 0x1f
222 #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
223 #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
224 #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
226 #define IPOPT_CONTROL 0x00
227 #define IPOPT_RESERVED1 0x20
228 #define IPOPT_DEBMEAS 0x40
229 #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
230 #define IPOPT_RESERVED2 0x60
232 #define IPOPT_EOL 0 /* end of option list */
233 #define IPOPT_END IPOPT_EOL
234 #define IPOPT_NOP 1 /* no operation */
235 #define IPOPT_NOOP IPOPT_NOP
237 #define IPOPT_RR 7 /* record packet route */
238 #define IPOPT_TS 68 /* timestamp */
239 #define IPOPT_TIMESTAMP IPOPT_TS
240 #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
241 #define IPOPT_SEC IPOPT_SECURITY
242 #define IPOPT_LSRR 131 /* loose source route */
243 #define IPOPT_SATID 136 /* satnet id */
244 #define IPOPT_SID IPOPT_SATID
245 #define IPOPT_SSRR 137 /* strict source route */
246 #define IPOPT_RA 148 /* router alert */
249 * Offsets to fields in options other than EOL and NOP.
251 #define IPOPT_OPTVAL 0 /* option ID */
252 #define IPOPT_OLEN 1 /* option length */
253 #define IPOPT_OFFSET 2 /* offset within option */
254 #define IPOPT_MINOFF 4 /* min value of above */
256 #define MAX_IPOPTLEN 40
258 /* flag bits for ipt_flg */
259 #define IPOPT_TS_TSONLY 0 /* timestamps only */
260 #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
261 #define IPOPT_TS_PRESPEC 3 /* specified modules only */
263 /* bits for security (not byte swapped) */
264 #define IPOPT_SECUR_UNCLASS 0x0000
265 #define IPOPT_SECUR_CONFID 0xf135
266 #define IPOPT_SECUR_EFTO 0x789a
267 #define IPOPT_SECUR_MMMM 0xbc4d
268 #define IPOPT_SECUR_RESTR 0xaf13
269 #define IPOPT_SECUR_SECRET 0xd788
270 #define IPOPT_SECUR_TOPSECRET 0x6bc5
273 * Internet implementation parameters.
275 #define MAXTTL 255 /* maximum time to live (seconds) */
276 #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
277 #define IPFRAGTTL 60 /* time to live for frags, slowhz */
278 #define IPTTLDEC 1 /* subtracted when forwarding */
280 #define IP_MSS 576 /* default maximum segment size */
284 #endif /* netinet/ip.h */