1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2009 Free Software 2 Foundation, Inc. 3 This file is part of the GNU C Library. 4 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. 9 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. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, write to the Free 17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 02111-1307 USA. */ 19 20 #ifndef __NETINET_IP_H 21 #define __NETINET_IP_H 1 22 23 #include <features.h> 24 #include <sys/types.h> 25 26 #include <netinet/in.h> 27 28 __BEGIN_DECLS 29 30 struct timestamp 31 { 32 u_int8_t len; 33 u_int8_t ptr; 34 #if __BYTE_ORDER == __LITTLE_ENDIAN 35 unsigned int flags:4; 36 unsigned int overflow:4; 37 #elif __BYTE_ORDER == __BIG_ENDIAN 38 unsigned int overflow:4; 39 unsigned int flags:4; 40 #else 41 # error "Please fix <bits/endian.h>" 42 #endif 43 u_int32_t data[9]; 44 }; 45 46 struct iphdr 47 { 48 #if __BYTE_ORDER == __LITTLE_ENDIAN 49 unsigned int ihl:4; 50 unsigned int version:4; 51 #elif __BYTE_ORDER == __BIG_ENDIAN 52 unsigned int version:4; 53 unsigned int ihl:4; 54 #else 55 # error "Please fix <bits/endian.h>" 56 #endif 57 u_int8_t tos; 58 u_int16_t tot_len; 59 u_int16_t id; 60 u_int16_t frag_off; 61 u_int8_t ttl; 62 u_int8_t protocol; 63 u_int16_t check; 64 u_int32_t saddr; 65 u_int32_t daddr; 66 /*The options start here. */ 67 }; 68 69 #ifdef __USE_BSD 70 /* 71 * Copyright (c) 1982, 1986, 1993 72 * The Regents of the University of California. All rights reserved. 73 * 74 * Redistribution and use in source and binary forms, with or without 75 * modification, are permitted provided that the following conditions 76 * are met: 77 * 1. Redistributions of source code must retain the above copyright 78 * notice, this list of conditions and the following disclaimer. 79 * 2. Redistributions in binary form must reproduce the above copyright 80 * notice, this list of conditions and the following disclaimer in the 81 * documentation and/or other materials provided with the distribution. 82 * 4. Neither the name of the University nor the names of its contributors 83 * may be used to endorse or promote products derived from this software 84 * without specific prior written permission. 85 * 86 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 87 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 92 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 96 * SUCH DAMAGE. 97 * 98 * @(#)ip.h 8.1 (Berkeley) 6/10/93 99 */ 100 101 /* 102 * Definitions for internet protocol version 4. 103 * Per RFC 791, September 1981. 104 */ 105 106 /* 107 * Structure of an internet header, naked of options. 108 */ 109 struct ip 110 { 111 #if __BYTE_ORDER == __LITTLE_ENDIAN 112 unsigned int ip_hl:4; /* header length */ 113 unsigned int ip_v:4; /* version */ 114 #endif 115 #if __BYTE_ORDER == __BIG_ENDIAN 116 unsigned int ip_v:4; /* version */ 117 unsigned int ip_hl:4; /* header length */ 118 #endif 119 u_int8_t ip_tos; /* type of service */ 120 u_short ip_len; /* total length */ 121 u_short ip_id; /* identification */ 122 u_short ip_off; /* fragment offset field */ 123 #define IP_RF 0x8000 /* reserved fragment flag */ 124 #define IP_DF 0x4000 /* dont fragment flag */ 125 #define IP_MF 0x2000 /* more fragments flag */ 126 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 127 u_int8_t ip_ttl; /* time to live */ 128 u_int8_t ip_p; /* protocol */ 129 u_short ip_sum; /* checksum */ 130 struct in_addr ip_src, ip_dst; /* source and dest address */ 131 }; 132 133 /* 134 * Time stamp option structure. 135 */ 136 struct ip_timestamp 137 { 138 u_int8_t ipt_code; /* IPOPT_TS */ 139 u_int8_t ipt_len; /* size of structure (variable) */ 140 u_int8_t ipt_ptr; /* index of current entry */ 141 #if __BYTE_ORDER == __LITTLE_ENDIAN 142 unsigned int ipt_flg:4; /* flags, see below */ 143 unsigned int ipt_oflw:4; /* overflow counter */ 144 #endif 145 #if __BYTE_ORDER == __BIG_ENDIAN 146 unsigned int ipt_oflw:4; /* overflow counter */ 147 unsigned int ipt_flg:4; /* flags, see below */ 148 #endif 149 u_int32_t data[9]; 150 }; 151 #endif /* __USE_BSD */ 152 153 #define IPVERSION 4 /* IP version number */ 154 #define IP_MAXPACKET 65535 /* maximum packet size */ 155 156 /* 157 * Definitions for Explicit Congestion Notification (ECN) 158 * 159 * Taken from RFC-3168, Section 5. 160 */ 161 162 #define IPTOS_ECN_MASK 0x03 163 #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) 164 #define IPTOS_ECN_NOT_ECT 0x00 165 #define IPTOS_ECN_ECT1 0x01 166 #define IPTOS_ECN_ECT0 0x02 167 #define IPTOS_ECN_CE 0x03 168 169 /* 170 * Definitions for IP differentiated services code points (DSCP) 171 * 172 * Taken from RFC-2597, Section 6 and RFC-2598, Section 2.3. 173 */ 174 175 #define IPTOS_DSCP_MASK 0xfc 176 #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) 177 #define IPTOS_DSCP_AF11 0x28 178 #define IPTOS_DSCP_AF12 0x30 179 #define IPTOS_DSCP_AF13 0x38 180 #define IPTOS_DSCP_AF21 0x48 181 #define IPTOS_DSCP_AF22 0x50 182 #define IPTOS_DSCP_AF23 0x58 183 #define IPTOS_DSCP_AF31 0x68 184 #define IPTOS_DSCP_AF32 0x70 185 #define IPTOS_DSCP_AF33 0x78 186 #define IPTOS_DSCP_AF41 0x88 187 #define IPTOS_DSCP_AF42 0x90 188 #define IPTOS_DSCP_AF43 0x98 189 #define IPTOS_DSCP_EF 0xb8 190 191 /* 192 * Definitions for IP type of service (ip_tos) 193 */ 194 #define IPTOS_TOS_MASK 0x1E 195 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) 196 #define IPTOS_LOWDELAY 0x10 197 #define IPTOS_THROUGHPUT 0x08 198 #define IPTOS_RELIABILITY 0x04 199 #define IPTOS_LOWCOST 0x02 200 #define IPTOS_MINCOST IPTOS_LOWCOST 201 202 /* 203 * Definitions for IP precedence (also in ip_tos) (hopefully unused) 204 */ 205 #define IPTOS_PREC_MASK 0xe0 206 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) 207 #define IPTOS_PREC_NETCONTROL 0xe0 208 #define IPTOS_PREC_INTERNETCONTROL 0xc0 209 #define IPTOS_PREC_CRITIC_ECP 0xa0 210 #define IPTOS_PREC_FLASHOVERRIDE 0x80 211 #define IPTOS_PREC_FLASH 0x60 212 #define IPTOS_PREC_IMMEDIATE 0x40 213 #define IPTOS_PREC_PRIORITY 0x20 214 #define IPTOS_PREC_ROUTINE 0x00 215 216 /* 217 * Definitions for options. 218 */ 219 #define IPOPT_COPY 0x80 220 #define IPOPT_CLASS_MASK 0x60 221 #define IPOPT_NUMBER_MASK 0x1f 222 223 #define IPOPT_COPIED(o) ((o) & IPOPT_COPY) 224 #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) 225 #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) 226 227 #define IPOPT_CONTROL 0x00 228 #define IPOPT_RESERVED1 0x20 229 #define IPOPT_DEBMEAS 0x40 230 #define IPOPT_MEASUREMENT IPOPT_DEBMEAS 231 #define IPOPT_RESERVED2 0x60 232 233 #define IPOPT_EOL 0 /* end of option list */ 234 #define IPOPT_END IPOPT_EOL 235 #define IPOPT_NOP 1 /* no operation */ 236 #define IPOPT_NOOP IPOPT_NOP 237 238 #define IPOPT_RR 7 /* record packet route */ 239 #define IPOPT_TS 68 /* timestamp */ 240 #define IPOPT_TIMESTAMP IPOPT_TS 241 #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ 242 #define IPOPT_SEC IPOPT_SECURITY 243 #define IPOPT_LSRR 131 /* loose source route */ 244 #define IPOPT_SATID 136 /* satnet id */ 245 #define IPOPT_SID IPOPT_SATID 246 #define IPOPT_SSRR 137 /* strict source route */ 247 #define IPOPT_RA 148 /* router alert */ 248 249 /* 250 * Offsets to fields in options other than EOL and NOP. 251 */ 252 #define IPOPT_OPTVAL 0 /* option ID */ 253 #define IPOPT_OLEN 1 /* option length */ 254 #define IPOPT_OFFSET 2 /* offset within option */ 255 #define IPOPT_MINOFF 4 /* min value of above */ 256 257 #define MAX_IPOPTLEN 40 258 259 /* flag bits for ipt_flg */ 260 #define IPOPT_TS_TSONLY 0 /* timestamps only */ 261 #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ 262 #define IPOPT_TS_PRESPEC 3 /* specified modules only */ 263 264 /* bits for security (not byte swapped) */ 265 #define IPOPT_SECUR_UNCLASS 0x0000 266 #define IPOPT_SECUR_CONFID 0xf135 267 #define IPOPT_SECUR_EFTO 0x789a 268 #define IPOPT_SECUR_MMMM 0xbc4d 269 #define IPOPT_SECUR_RESTR 0xaf13 270 #define IPOPT_SECUR_SECRET 0xd788 271 #define IPOPT_SECUR_TOPSECRET 0x6bc5 272 273 /* 274 * Internet implementation parameters. 275 */ 276 #define MAXTTL 255 /* maximum time to live (seconds) */ 277 #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ 278 #define IPFRAGTTL 60 /* time to live for frags, slowhz */ 279 #define IPTTLDEC 1 /* subtracted when forwarding */ 280 281 #define IP_MSS 576 /* default maximum segment size */ 282 283 __END_DECLS 284 285 #endif /* netinet/ip.h */ 286