1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1990, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33df8bae1dSRodney W. Grimes * @(#)in.h 8.3 (Berkeley) 1/3/94 34df8bae1dSRodney W. Grimes */ 35df8bae1dSRodney W. Grimes 36df8bae1dSRodney W. Grimes /* 37df8bae1dSRodney W. Grimes * Constants and structures defined by the internet system, 38df8bae1dSRodney W. Grimes * Per RFC 790, September 1981, and numerous additions. 39df8bae1dSRodney W. Grimes */ 40df8bae1dSRodney W. Grimes 41df8bae1dSRodney W. Grimes /* 42df8bae1dSRodney W. Grimes * Protocols 43df8bae1dSRodney W. Grimes */ 44df8bae1dSRodney W. Grimes #define IPPROTO_IP 0 /* dummy for IP */ 45df8bae1dSRodney W. Grimes #define IPPROTO_ICMP 1 /* control message protocol */ 46df8bae1dSRodney W. Grimes #define IPPROTO_IGMP 2 /* group mgmt protocol */ 47df8bae1dSRodney W. Grimes #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 48df8bae1dSRodney W. Grimes #define IPPROTO_TCP 6 /* tcp */ 49df8bae1dSRodney W. Grimes #define IPPROTO_EGP 8 /* exterior gateway protocol */ 50df8bae1dSRodney W. Grimes #define IPPROTO_PUP 12 /* pup */ 51df8bae1dSRodney W. Grimes #define IPPROTO_UDP 17 /* user datagram protocol */ 52df8bae1dSRodney W. Grimes #define IPPROTO_IDP 22 /* xns idp */ 53df8bae1dSRodney W. Grimes #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 54df8bae1dSRodney W. Grimes #define IPPROTO_EON 80 /* ISO cnlp */ 55df8bae1dSRodney W. Grimes #define IPPROTO_ENCAP 98 /* encapsulation header */ 56df8bae1dSRodney W. Grimes 57df8bae1dSRodney W. Grimes #define IPPROTO_RAW 255 /* raw IP packet */ 58df8bae1dSRodney W. Grimes #define IPPROTO_MAX 256 59df8bae1dSRodney W. Grimes 60df8bae1dSRodney W. Grimes 61df8bae1dSRodney W. Grimes /* 62df8bae1dSRodney W. Grimes * Local port number conventions: 63df8bae1dSRodney W. Grimes * Ports < IPPORT_RESERVED are reserved for 64df8bae1dSRodney W. Grimes * privileged processes (e.g. root). 65df8bae1dSRodney W. Grimes * Ports > IPPORT_USERRESERVED are reserved 66df8bae1dSRodney W. Grimes * for servers, not necessarily privileged. 67df8bae1dSRodney W. Grimes */ 68df8bae1dSRodney W. Grimes #define IPPORT_RESERVED 1024 69df8bae1dSRodney W. Grimes #define IPPORT_USERRESERVED 5000 70df8bae1dSRodney W. Grimes 71df8bae1dSRodney W. Grimes /* 72df8bae1dSRodney W. Grimes * Internet address (a structure for historical reasons) 73df8bae1dSRodney W. Grimes */ 74df8bae1dSRodney W. Grimes struct in_addr { 75df8bae1dSRodney W. Grimes u_long s_addr; 76df8bae1dSRodney W. Grimes }; 77df8bae1dSRodney W. Grimes 78df8bae1dSRodney W. Grimes /* 79df8bae1dSRodney W. Grimes * Definitions of bits in internet address integers. 80df8bae1dSRodney W. Grimes * On subnets, the decomposition of addresses to host and net parts 81df8bae1dSRodney W. Grimes * is done according to subnet mask, not the masks here. 82df8bae1dSRodney W. Grimes */ 83df8bae1dSRodney W. Grimes #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 84df8bae1dSRodney W. Grimes #define IN_CLASSA_NET 0xff000000 85df8bae1dSRodney W. Grimes #define IN_CLASSA_NSHIFT 24 86df8bae1dSRodney W. Grimes #define IN_CLASSA_HOST 0x00ffffff 87df8bae1dSRodney W. Grimes #define IN_CLASSA_MAX 128 88df8bae1dSRodney W. Grimes 89df8bae1dSRodney W. Grimes #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 90df8bae1dSRodney W. Grimes #define IN_CLASSB_NET 0xffff0000 91df8bae1dSRodney W. Grimes #define IN_CLASSB_NSHIFT 16 92df8bae1dSRodney W. Grimes #define IN_CLASSB_HOST 0x0000ffff 93df8bae1dSRodney W. Grimes #define IN_CLASSB_MAX 65536 94df8bae1dSRodney W. Grimes 95df8bae1dSRodney W. Grimes #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 96df8bae1dSRodney W. Grimes #define IN_CLASSC_NET 0xffffff00 97df8bae1dSRodney W. Grimes #define IN_CLASSC_NSHIFT 8 98df8bae1dSRodney W. Grimes #define IN_CLASSC_HOST 0x000000ff 99df8bae1dSRodney W. Grimes 100df8bae1dSRodney W. Grimes #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 101df8bae1dSRodney W. Grimes #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 102df8bae1dSRodney W. Grimes #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 103df8bae1dSRodney W. Grimes #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 104df8bae1dSRodney W. Grimes #define IN_MULTICAST(i) IN_CLASSD(i) 105df8bae1dSRodney W. Grimes 106df8bae1dSRodney W. Grimes #define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000) 107df8bae1dSRodney W. Grimes #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 108df8bae1dSRodney W. Grimes 109df8bae1dSRodney W. Grimes #define INADDR_ANY (u_long)0x00000000 110df8bae1dSRodney W. Grimes #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 111df8bae1dSRodney W. Grimes #ifndef KERNEL 112df8bae1dSRodney W. Grimes #define INADDR_NONE 0xffffffff /* -1 return */ 113df8bae1dSRodney W. Grimes #endif 114df8bae1dSRodney W. Grimes 115df8bae1dSRodney W. Grimes #define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ 116df8bae1dSRodney W. Grimes #define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ 117df8bae1dSRodney W. Grimes #define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ 118df8bae1dSRodney W. Grimes 119df8bae1dSRodney W. Grimes #define IN_LOOPBACKNET 127 /* official! */ 120df8bae1dSRodney W. Grimes 121df8bae1dSRodney W. Grimes /* 122df8bae1dSRodney W. Grimes * Socket address, internet style. 123df8bae1dSRodney W. Grimes */ 124df8bae1dSRodney W. Grimes struct sockaddr_in { 125df8bae1dSRodney W. Grimes u_char sin_len; 126df8bae1dSRodney W. Grimes u_char sin_family; 127df8bae1dSRodney W. Grimes u_short sin_port; 128df8bae1dSRodney W. Grimes struct in_addr sin_addr; 129df8bae1dSRodney W. Grimes char sin_zero[8]; 130df8bae1dSRodney W. Grimes }; 131df8bae1dSRodney W. Grimes 132df8bae1dSRodney W. Grimes /* 133df8bae1dSRodney W. Grimes * Structure used to describe IP options. 134df8bae1dSRodney W. Grimes * Used to store options internally, to pass them to a process, 135df8bae1dSRodney W. Grimes * or to restore options retrieved earlier. 136df8bae1dSRodney W. Grimes * The ip_dst is used for the first-hop gateway when using a source route 137df8bae1dSRodney W. Grimes * (this gets put into the header proper). 138df8bae1dSRodney W. Grimes */ 139df8bae1dSRodney W. Grimes struct ip_opts { 140df8bae1dSRodney W. Grimes struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 141df8bae1dSRodney W. Grimes char ip_opts[40]; /* actually variable in size */ 142df8bae1dSRodney W. Grimes }; 143df8bae1dSRodney W. Grimes 144df8bae1dSRodney W. Grimes /* 145df8bae1dSRodney W. Grimes * Options for use with [gs]etsockopt at the IP level. 146df8bae1dSRodney W. Grimes * First word of comment is data type; bool is stored in int. 147df8bae1dSRodney W. Grimes */ 148df8bae1dSRodney W. Grimes #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 149df8bae1dSRodney W. Grimes #define IP_HDRINCL 2 /* int; header is included with data */ 150df8bae1dSRodney W. Grimes #define IP_TOS 3 /* int; IP type of service and preced. */ 151df8bae1dSRodney W. Grimes #define IP_TTL 4 /* int; IP time to live */ 152df8bae1dSRodney W. Grimes #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 153df8bae1dSRodney W. Grimes #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 154df8bae1dSRodney W. Grimes #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 155df8bae1dSRodney W. Grimes #define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 156df8bae1dSRodney W. Grimes #define IP_MULTICAST_IF 9 /* u_char; set/get IP multicast i/f */ 157df8bae1dSRodney W. Grimes #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 158df8bae1dSRodney W. Grimes #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 159df8bae1dSRodney W. Grimes #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 160df8bae1dSRodney W. Grimes #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 161df8bae1dSRodney W. Grimes 162df8bae1dSRodney W. Grimes /* 163df8bae1dSRodney W. Grimes * Defaults and limits for options 164df8bae1dSRodney W. Grimes */ 165df8bae1dSRodney W. Grimes #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 166df8bae1dSRodney W. Grimes #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 167df8bae1dSRodney W. Grimes #define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */ 168df8bae1dSRodney W. Grimes 169df8bae1dSRodney W. Grimes /* 170df8bae1dSRodney W. Grimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 171df8bae1dSRodney W. Grimes */ 172df8bae1dSRodney W. Grimes struct ip_mreq { 173df8bae1dSRodney W. Grimes struct in_addr imr_multiaddr; /* IP multicast address of group */ 174df8bae1dSRodney W. Grimes struct in_addr imr_interface; /* local IP address of interface */ 175df8bae1dSRodney W. Grimes }; 176df8bae1dSRodney W. Grimes 177df8bae1dSRodney W. Grimes /* 178df8bae1dSRodney W. Grimes * Definitions for inet sysctl operations. 179df8bae1dSRodney W. Grimes * 180df8bae1dSRodney W. Grimes * Third level is protocol number. 181df8bae1dSRodney W. Grimes * Fourth level is desired variable within that protocol. 182df8bae1dSRodney W. Grimes */ 183df8bae1dSRodney W. Grimes #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ 184df8bae1dSRodney W. Grimes 185df8bae1dSRodney W. Grimes #define CTL_IPPROTO_NAMES { \ 186df8bae1dSRodney W. Grimes { "ip", CTLTYPE_NODE }, \ 187df8bae1dSRodney W. Grimes { "icmp", CTLTYPE_NODE }, \ 188df8bae1dSRodney W. Grimes { "igmp", CTLTYPE_NODE }, \ 189df8bae1dSRodney W. Grimes { "ggp", CTLTYPE_NODE }, \ 190df8bae1dSRodney W. Grimes { 0, 0 }, \ 191df8bae1dSRodney W. Grimes { 0, 0 }, \ 192df8bae1dSRodney W. Grimes { "tcp", CTLTYPE_NODE }, \ 193df8bae1dSRodney W. Grimes { 0, 0 }, \ 194df8bae1dSRodney W. Grimes { "egp", CTLTYPE_NODE }, \ 195df8bae1dSRodney W. Grimes { 0, 0 }, \ 196df8bae1dSRodney W. Grimes { 0, 0 }, \ 197df8bae1dSRodney W. Grimes { 0, 0 }, \ 198df8bae1dSRodney W. Grimes { "pup", CTLTYPE_NODE }, \ 199df8bae1dSRodney W. Grimes { 0, 0 }, \ 200df8bae1dSRodney W. Grimes { 0, 0 }, \ 201df8bae1dSRodney W. Grimes { 0, 0 }, \ 202df8bae1dSRodney W. Grimes { 0, 0 }, \ 203df8bae1dSRodney W. Grimes { "udp", CTLTYPE_NODE }, \ 204df8bae1dSRodney W. Grimes { 0, 0 }, \ 205df8bae1dSRodney W. Grimes { 0, 0 }, \ 206df8bae1dSRodney W. Grimes { 0, 0 }, \ 207df8bae1dSRodney W. Grimes { 0, 0 }, \ 208df8bae1dSRodney W. Grimes { "idp", CTLTYPE_NODE }, \ 209df8bae1dSRodney W. Grimes } 210df8bae1dSRodney W. Grimes 211df8bae1dSRodney W. Grimes /* 212df8bae1dSRodney W. Grimes * Names for IP sysctl objects 213df8bae1dSRodney W. Grimes */ 214df8bae1dSRodney W. Grimes #define IPCTL_FORWARDING 1 /* act as router */ 215df8bae1dSRodney W. Grimes #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 216df8bae1dSRodney W. Grimes #define IPCTL_DEFTTL 3 /* default TTL */ 217df8bae1dSRodney W. Grimes #ifdef notyet 218df8bae1dSRodney W. Grimes #define IPCTL_DEFMTU 4 /* default MTU */ 219df8bae1dSRodney W. Grimes #endif 220df8bae1dSRodney W. Grimes #define IPCTL_MAXID 5 221df8bae1dSRodney W. Grimes 222df8bae1dSRodney W. Grimes #define IPCTL_NAMES { \ 223df8bae1dSRodney W. Grimes { 0, 0 }, \ 224df8bae1dSRodney W. Grimes { "forwarding", CTLTYPE_INT }, \ 225df8bae1dSRodney W. Grimes { "redirect", CTLTYPE_INT }, \ 226df8bae1dSRodney W. Grimes { "ttl", CTLTYPE_INT }, \ 227df8bae1dSRodney W. Grimes { "mtu", CTLTYPE_INT }, \ 228df8bae1dSRodney W. Grimes } 229df8bae1dSRodney W. Grimes 230df8bae1dSRodney W. Grimes 231df8bae1dSRodney W. Grimes #ifdef KERNEL 232df8bae1dSRodney W. Grimes int in_broadcast __P((struct in_addr, struct ifnet *)); 233df8bae1dSRodney W. Grimes int in_canforward __P((struct in_addr)); 234df8bae1dSRodney W. Grimes int in_cksum __P((struct mbuf *, int)); 235df8bae1dSRodney W. Grimes int in_localaddr __P((struct in_addr)); 236df8bae1dSRodney W. Grimes u_long in_netof __P((struct in_addr)); 237df8bae1dSRodney W. Grimes void in_socktrim __P((struct sockaddr_in *)); 238df8bae1dSRodney W. Grimes #endif 239