Back to index

lightning-sunbird  0.9+nobinonly
in.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1982, 1986, 1990, 1993
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * [3 Deleted as of 22Jul99, see
00014  *     ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
00015  *        for details]
00016  * 4. Neither the name of the University nor the names of its contributors
00017  *    may be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  *     @(#)in.h      8.3 (Berkeley) 1/3/94
00033  */
00034 
00035 /* Adapted for GUSI by Matthias Neeracher <neeri@iis.ee.ethz.ch> */
00036 
00037 #ifndef _NETINET_IN_H_
00038 #define _NETINET_IN_H_
00039 
00040 /* xtonx() mandated available by XNS -- neeri */
00041 #include <machine/endian.h>
00042 
00043 /*
00044  * Constants and structures defined by the internet system,
00045  * Per RFC 790, September 1981, and numerous additions.
00046  */
00047 
00048 /*
00049  * Protocols
00050  */
00051 #define       IPPROTO_IP           0             /* dummy for IP */
00052 #define       IPPROTO_ICMP  1             /* control message protocol */
00053 #define       IPPROTO_IGMP  2             /* group mgmt protocol */
00054 #define       IPPROTO_GGP          3             /* gateway^2 (deprecated) */
00055 #define       IPPROTO_TCP          6             /* tcp */
00056 #define       IPPROTO_EGP          8             /* exterior gateway protocol */
00057 #define       IPPROTO_PUP          12            /* pup */
00058 #define       IPPROTO_UDP          17            /* user datagram protocol */
00059 #define       IPPROTO_IDP          22            /* xns idp */
00060 #define       IPPROTO_TP           29            /* tp-4 w/ class negotiation */
00061 #define       IPPROTO_EON          80            /* ISO cnlp */
00062 #define       IPPROTO_ENCAP 98            /* encapsulation header */
00063 
00064 #define       IPPROTO_RAW          255           /* raw IP packet */
00065 #define       IPPROTO_MAX          256
00066 
00067 
00068 /*
00069  * Local port number conventions:
00070  * Ports < IPPORT_RESERVED are reserved for
00071  * privileged processes (e.g. root).
00072  * Ports > IPPORT_USERRESERVED are reserved
00073  * for servers, not necessarily privileged.
00074  */
00075 #define       IPPORT_RESERVED             1024
00076 #define       IPPORT_USERRESERVED  5000
00077 
00078 /* Types mandated by XNS -- neeri */
00079 typedef uint16_t     in_port_t;
00080 typedef uint32_t     in_addr_t;
00081 
00082 /*
00083  * Internet address (a structure for historical reasons)
00084  */
00085 struct in_addr {
00086        in_addr_t s_addr;
00087 };
00088 
00089 /*
00090  * Definitions of bits in internet address integers.
00091  * On subnets, the decomposition of addresses to host and net parts
00092  * is done according to subnet mask, not the masks here.
00093  */
00094 #define       IN_CLASSA(i)         (((long)(i) & 0x80000000) == 0)
00095 #define       IN_CLASSA_NET        0xff000000
00096 #define       IN_CLASSA_NSHIFT     24
00097 #define       IN_CLASSA_HOST              0x00ffffff
00098 #define       IN_CLASSA_MAX        128
00099 
00100 #define       IN_CLASSB(i)         (((long)(i) & 0xc0000000) == 0x80000000)
00101 #define       IN_CLASSB_NET        0xffff0000
00102 #define       IN_CLASSB_NSHIFT     16
00103 #define       IN_CLASSB_HOST              0x0000ffff
00104 #define       IN_CLASSB_MAX        65536
00105 
00106 #define       IN_CLASSC(i)         (((long)(i) & 0xe0000000) == 0xc0000000)
00107 #define       IN_CLASSC_NET        0xffffff00
00108 #define       IN_CLASSC_NSHIFT     8
00109 #define       IN_CLASSC_HOST              0x000000ff
00110 
00111 #define       IN_CLASSD(i)         (((long)(i) & 0xf0000000) == 0xe0000000)
00112 #define       IN_CLASSD_NET        0xf0000000    /* These ones aren't really */
00113 #define       IN_CLASSD_NSHIFT     28            /* net and host fields, but */
00114 #define       IN_CLASSD_HOST              0x0fffffff    /* routing needn't know.    */
00115 #define       IN_MULTICAST(i)             IN_CLASSD(i)
00116 
00117 #define       IN_EXPERIMENTAL(i)   (((long)(i) & 0xf0000000) == 0xf0000000)
00118 #define       IN_BADCLASS(i)              (((long)(i) & 0xf0000000) == 0xf0000000)
00119 
00120 #define       INADDR_ANY           (u_long)0x00000000
00121 #define       INADDR_BROADCAST     (u_long)0xffffffff   /* must be masked */
00122 #define       INADDR_NONE          0xffffffff           /* -1 return */
00123 
00124 #define       INADDR_UNSPEC_GROUP  (u_long)0xe0000000   /* 224.0.0.0 */
00125 #define       INADDR_ALLHOSTS_GROUP       (u_long)0xe0000001   /* 224.0.0.1 */
00126 #define       INADDR_MAX_LOCAL_GROUP      (u_long)0xe00000ff   /* 224.0.0.255 */
00127 
00128 #define       IN_LOOPBACKNET              127                  /* official! */
00129 
00130 /* Mandated by XNS -- neeri */
00131 #ifndef _SA_FAMILY_T_DEFINED
00132 #define _SA_FAMILY_T_DEFINED
00133 typedef uint16_t sa_family_t;
00134 #endif
00135 
00136 /*
00137  * Socket address, internet style.
00138  */
00139 struct sockaddr_in {
00140        sa_family_t          sin_family;
00141        in_port_t            sin_port;
00142        struct               in_addr sin_addr;
00143        unsigned char sin_zero[8];
00144 };
00145 
00146 /*
00147  * Structure used to describe IP options.
00148  * Used to store options internally, to pass them to a process,
00149  * or to restore options retrieved earlier.
00150  * The ip_dst is used for the first-hop gateway when using a source route
00151  * (this gets put into the header proper).
00152  */
00153 typedef struct {
00154        struct in_addr ip_dst;             /* first hop, 0 w/o src rt */
00155        char   ip_opts[40];         /* actually variable in size */
00156 } ip_opts;
00157 
00158 /*
00159  * Options for use with [gs]etsockopt at the IP level.
00160  * First word of comment is data type; bool is stored in int.
00161  */
00162 #define       IP_OPTIONS                   0x01
00163 #define       IP_TOS                       0x02
00164 #define       IP_TTL                       0x03
00165 #define       IP_REUSEADDR          0x04
00166 #define       IP_DONTROUTE          0x10
00167 #define       IP_BROADCAST          0x20
00168 #define       IP_HDRINCL                   0x1002       
00169 #define       IP_RCVOPTS                   0x1005
00170 #define       IP_RCVDSTADDR         0x1007
00171 #define       IP_MULTICAST_IF       0x1010              /* set/get IP multicast interface  */
00172 #define       IP_MULTICAST_TTL      0x1011              /* set/get IP multicast timetolive */
00173 #define       IP_MULTICAST_LOOP     0x1012              /* set/get IP multicast loopback   */
00174 #define       IP_ADD_MEMBERSHIP     0x1013              /* add an IP group membership             */
00175 #define       IP_DROP_MEMBERSHIP 0x1014          /* drop an IP group membership            */
00176 #define       IP_BROADCAST_IF       0x1015              /* Set interface for broadcasts    */
00177 #define       IP_RCVIFADDR          0x1016              /* Set interface for broadcasts    */
00178 
00179 /*
00180  * Defaults and limits for options
00181  */
00182 #define       IP_DEFAULT_MULTICAST_TTL  1 /* normally limit m'casts to 1 hop  */
00183 #define       IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member  */
00184 #define       IP_MAX_MEMBERSHIPS   20     /* per socket; must fit in one mbuf */
00185 
00186 /*
00187  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
00188  */
00189 struct ip_mreq {
00190        struct in_addr imr_multiaddr;      /* IP multicast address of group */
00191        struct in_addr imr_interface;      /* local IP address of interface */
00192 };
00193 
00194 /*
00195  * Definitions for inet sysctl operations.
00196  *
00197  * Third level is protocol number.
00198  * Fourth level is desired variable within that protocol.
00199  */
00200 #define       IPPROTO_MAXID (IPPROTO_IDP + 1)    /* don't list to IPPROTO_MAX */
00201 
00202 #define       CTL_IPPROTO_NAMES { \
00203        { "ip", CTLTYPE_NODE }, \
00204        { "icmp", CTLTYPE_NODE }, \
00205        { "igmp", CTLTYPE_NODE }, \
00206        { "ggp", CTLTYPE_NODE }, \
00207        { 0, 0 }, \
00208        { 0, 0 }, \
00209        { "tcp", CTLTYPE_NODE }, \
00210        { 0, 0 }, \
00211        { "egp", CTLTYPE_NODE }, \
00212        { 0, 0 }, \
00213        { 0, 0 }, \
00214        { 0, 0 }, \
00215        { "pup", CTLTYPE_NODE }, \
00216        { 0, 0 }, \
00217        { 0, 0 }, \
00218        { 0, 0 }, \
00219        { 0, 0 }, \
00220        { "udp", CTLTYPE_NODE }, \
00221        { 0, 0 }, \
00222        { 0, 0 }, \
00223        { 0, 0 }, \
00224        { 0, 0 }, \
00225        { "idp", CTLTYPE_NODE }, \
00226 }
00227 
00228 /*
00229  * Names for IP sysctl objects
00230  */
00231 #define       IPCTL_FORWARDING     1      /* act as router */
00232 #define       IPCTL_SENDREDIRECTS  2      /* may send redirects when forwarding */
00233 #define       IPCTL_DEFTTL         3      /* default TTL */
00234 #ifdef notyet
00235 #define       IPCTL_DEFMTU         4      /* default MTU */
00236 #endif
00237 #define       IPCTL_MAXID          5
00238 
00239 #define       IPCTL_NAMES { \
00240        { 0, 0 }, \
00241        { "forwarding", CTLTYPE_INT }, \
00242        { "redirect", CTLTYPE_INT }, \
00243        { "ttl", CTLTYPE_INT }, \
00244        { "mtu", CTLTYPE_INT }, \
00245 }
00246 
00247 #endif /* _NETINET_IN_H_ */
00248