Back to index

glibc  2.9
ip.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991,92,93,95,96,97,98,99,2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef __NETINET_IP_H
00020 #define __NETINET_IP_H 1
00021 
00022 #include <features.h>
00023 #include <sys/types.h>
00024 
00025 #include <netinet/in.h>
00026 
00027 __BEGIN_DECLS
00028 
00029 struct timestamp
00030   {
00031     u_int8_t len;
00032     u_int8_t ptr;
00033 #if __BYTE_ORDER == __LITTLE_ENDIAN
00034     unsigned int flags:4;
00035     unsigned int overflow:4;
00036 #elif __BYTE_ORDER == __BIG_ENDIAN
00037     unsigned int overflow:4;
00038     unsigned int flags:4;
00039 #else
00040 # error       "Please fix <bits/endian.h>"
00041 #endif
00042     u_int32_t data[9];
00043   };
00044 
00045 struct iphdr
00046   {
00047 #if __BYTE_ORDER == __LITTLE_ENDIAN
00048     unsigned int ihl:4;
00049     unsigned int version:4;
00050 #elif __BYTE_ORDER == __BIG_ENDIAN
00051     unsigned int version:4;
00052     unsigned int ihl:4;
00053 #else
00054 # error       "Please fix <bits/endian.h>"
00055 #endif
00056     u_int8_t tos;
00057     u_int16_t tot_len;
00058     u_int16_t id;
00059     u_int16_t frag_off;
00060     u_int8_t ttl;
00061     u_int8_t protocol;
00062     u_int16_t check;
00063     u_int32_t saddr;
00064     u_int32_t daddr;
00065     /*The options start here. */
00066   };
00067 
00068 #ifdef __USE_BSD
00069 /*
00070  * Copyright (c) 1982, 1986, 1993
00071  *     The Regents of the University of California.  All rights reserved.
00072  *
00073  * Redistribution and use in source and binary forms, with or without
00074  * modification, are permitted provided that the following conditions
00075  * are met:
00076  * 1. Redistributions of source code must retain the above copyright
00077  *    notice, this list of conditions and the following disclaimer.
00078  * 2. Redistributions in binary form must reproduce the above copyright
00079  *    notice, this list of conditions and the following disclaimer in the
00080  *    documentation and/or other materials provided with the distribution.
00081  * 4. Neither the name of the University nor the names of its contributors
00082  *    may be used to endorse or promote products derived from this software
00083  *    without specific prior written permission.
00084  *
00085  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00086  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00088  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00089  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00090  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00091  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00092  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00093  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00094  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00095  * SUCH DAMAGE.
00096  *
00097  *     @(#)ip.h      8.1 (Berkeley) 6/10/93
00098  */
00099 
00100 /*
00101  * Definitions for internet protocol version 4.
00102  * Per RFC 791, September 1981.
00103  */
00104 
00105 /*
00106  * Structure of an internet header, naked of options.
00107  */
00108 struct ip
00109   {
00110 #if __BYTE_ORDER == __LITTLE_ENDIAN
00111     unsigned int ip_hl:4;          /* header length */
00112     unsigned int ip_v:4;           /* version */
00113 #endif
00114 #if __BYTE_ORDER == __BIG_ENDIAN
00115     unsigned int ip_v:4;           /* version */
00116     unsigned int ip_hl:4;          /* header length */
00117 #endif
00118     u_int8_t ip_tos;               /* type of service */
00119     u_short ip_len;                /* total length */
00120     u_short ip_id;                 /* identification */
00121     u_short ip_off;                /* fragment offset field */
00122 #define       IP_RF 0x8000                /* reserved fragment flag */
00123 #define       IP_DF 0x4000                /* dont fragment flag */
00124 #define       IP_MF 0x2000                /* more fragments flag */
00125 #define       IP_OFFMASK 0x1fff           /* mask for fragmenting bits */
00126     u_int8_t ip_ttl;               /* time to live */
00127     u_int8_t ip_p;                 /* protocol */
00128     u_short ip_sum;                /* checksum */
00129     struct in_addr ip_src, ip_dst; /* source and dest address */
00130   };
00131 
00132 /*
00133  * Time stamp option structure.
00134  */
00135 struct ip_timestamp
00136   {
00137     u_int8_t ipt_code;                    /* IPOPT_TS */
00138     u_int8_t ipt_len;                     /* size of structure (variable) */
00139     u_int8_t ipt_ptr;                     /* index of current entry */
00140 #if __BYTE_ORDER == __LITTLE_ENDIAN
00141     unsigned int ipt_flg:4;        /* flags, see below */
00142     unsigned int ipt_oflw:4;              /* overflow counter */
00143 #endif
00144 #if __BYTE_ORDER == __BIG_ENDIAN
00145     unsigned int ipt_oflw:4;              /* overflow counter */
00146     unsigned int ipt_flg:4;        /* flags, see below */
00147 #endif
00148     u_int32_t data[9];
00149   };
00150 #endif /* __USE_BSD */
00151 
00152 #define       IPVERSION     4               /* IP version number */
00153 #define       IP_MAXPACKET  65535         /* maximum packet size */
00154 
00155 /*
00156  * Definitions for IP type of service (ip_tos)
00157  */
00158 #define       IPTOS_TOS_MASK              0x1E
00159 #define       IPTOS_TOS(tos)              ((tos) & IPTOS_TOS_MASK)
00160 #define       IPTOS_LOWDELAY              0x10
00161 #define       IPTOS_THROUGHPUT     0x08
00162 #define       IPTOS_RELIABILITY    0x04
00163 #define       IPTOS_LOWCOST        0x02
00164 #define       IPTOS_MINCOST        IPTOS_LOWCOST
00165 
00166 /*
00167  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
00168  */
00169 #define       IPTOS_PREC_MASK                    0xe0
00170 #define       IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
00171 #define       IPTOS_PREC_NETCONTROL              0xe0
00172 #define       IPTOS_PREC_INTERNETCONTROL  0xc0
00173 #define       IPTOS_PREC_CRITIC_ECP              0xa0
00174 #define       IPTOS_PREC_FLASHOVERRIDE    0x80
00175 #define       IPTOS_PREC_FLASH            0x60
00176 #define       IPTOS_PREC_IMMEDIATE        0x40
00177 #define       IPTOS_PREC_PRIORITY         0x20
00178 #define       IPTOS_PREC_ROUTINE          0x00
00179 
00180 /*
00181  * Definitions for options.
00182  */
00183 #define       IPOPT_COPY           0x80
00184 #define       IPOPT_CLASS_MASK     0x60
00185 #define       IPOPT_NUMBER_MASK    0x1f
00186 
00187 #define       IPOPT_COPIED(o)             ((o) & IPOPT_COPY)
00188 #define       IPOPT_CLASS(o)              ((o) & IPOPT_CLASS_MASK)
00189 #define       IPOPT_NUMBER(o)             ((o) & IPOPT_NUMBER_MASK)
00190 
00191 #define       IPOPT_CONTROL        0x00
00192 #define       IPOPT_RESERVED1             0x20
00193 #define       IPOPT_DEBMEAS        0x40
00194 #define       IPOPT_MEASUREMENT       IPOPT_DEBMEAS
00195 #define       IPOPT_RESERVED2             0x60
00196 
00197 #define       IPOPT_EOL            0             /* end of option list */
00198 #define       IPOPT_END            IPOPT_EOL
00199 #define       IPOPT_NOP            1             /* no operation */
00200 #define       IPOPT_NOOP           IPOPT_NOP
00201 
00202 #define       IPOPT_RR             7             /* record packet route */
00203 #define       IPOPT_TS             68            /* timestamp */
00204 #define       IPOPT_TIMESTAMP             IPOPT_TS
00205 #define       IPOPT_SECURITY              130           /* provide s,c,h,tcc */
00206 #define       IPOPT_SEC            IPOPT_SECURITY
00207 #define       IPOPT_LSRR           131           /* loose source route */
00208 #define       IPOPT_SATID          136           /* satnet id */
00209 #define       IPOPT_SID            IPOPT_SATID
00210 #define       IPOPT_SSRR           137           /* strict source route */
00211 #define       IPOPT_RA             148           /* router alert */
00212 
00213 /*
00214  * Offsets to fields in options other than EOL and NOP.
00215  */
00216 #define       IPOPT_OPTVAL         0             /* option ID */
00217 #define       IPOPT_OLEN           1             /* option length */
00218 #define       IPOPT_OFFSET         2             /* offset within option */
00219 #define       IPOPT_MINOFF         4             /* min value of above */
00220 
00221 #define       MAX_IPOPTLEN         40
00222 
00223 /* flag bits for ipt_flg */
00224 #define       IPOPT_TS_TSONLY             0             /* timestamps only */
00225 #define       IPOPT_TS_TSANDADDR   1             /* timestamps and addresses */
00226 #define       IPOPT_TS_PRESPEC     3             /* specified modules only */
00227 
00228 /* bits for security (not byte swapped) */
00229 #define       IPOPT_SECUR_UNCLASS  0x0000
00230 #define       IPOPT_SECUR_CONFID   0xf135
00231 #define       IPOPT_SECUR_EFTO     0x789a
00232 #define       IPOPT_SECUR_MMMM     0xbc4d
00233 #define       IPOPT_SECUR_RESTR    0xaf13
00234 #define       IPOPT_SECUR_SECRET   0xd788
00235 #define       IPOPT_SECUR_TOPSECRET       0x6bc5
00236 
00237 /*
00238  * Internet implementation parameters.
00239  */
00240 #define       MAXTTL        255           /* maximum time to live (seconds) */
00241 #define       IPDEFTTL      64            /* default ttl, from RFC 1340 */
00242 #define       IPFRAGTTL     60            /* time to live for frags, slowhz */
00243 #define       IPTTLDEC      1             /* subtracted when forwarding */
00244 
00245 #define       IP_MSS        576           /* default maximum segment size */
00246 
00247 __END_DECLS
00248 
00249 #endif /* netinet/ip.h */