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 341c5de19aSGarrett Wollman * $Id: in.h,v 1.9 1995/03/16 18:22:26 wollman Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37707f139eSPaul Richards #ifndef _NETINET_IN_H_ 38707f139eSPaul Richards #define _NETINET_IN_H_ 39707f139eSPaul Richards 40df8bae1dSRodney W. Grimes /* 41df8bae1dSRodney W. Grimes * Constants and structures defined by the internet system, 42df8bae1dSRodney W. Grimes * Per RFC 790, September 1981, and numerous additions. 43df8bae1dSRodney W. Grimes */ 44df8bae1dSRodney W. Grimes 45df8bae1dSRodney W. Grimes /* 46df8bae1dSRodney W. Grimes * Protocols 47df8bae1dSRodney W. Grimes */ 48df8bae1dSRodney W. Grimes #define IPPROTO_IP 0 /* dummy for IP */ 49df8bae1dSRodney W. Grimes #define IPPROTO_ICMP 1 /* control message protocol */ 50df8bae1dSRodney W. Grimes #define IPPROTO_IGMP 2 /* group mgmt protocol */ 51df8bae1dSRodney W. Grimes #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 521c5de19aSGarrett Wollman #define IPPROTO_IPIP 4 /* IP encapsulation in IP */ 53df8bae1dSRodney W. Grimes #define IPPROTO_TCP 6 /* tcp */ 54df8bae1dSRodney W. Grimes #define IPPROTO_EGP 8 /* exterior gateway protocol */ 55df8bae1dSRodney W. Grimes #define IPPROTO_PUP 12 /* pup */ 56df8bae1dSRodney W. Grimes #define IPPROTO_UDP 17 /* user datagram protocol */ 57df8bae1dSRodney W. Grimes #define IPPROTO_IDP 22 /* xns idp */ 58df8bae1dSRodney W. Grimes #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 59f0068c4aSGarrett Wollman #define IPPROTO_RSVP 46 /* resource reservation */ 60df8bae1dSRodney W. Grimes #define IPPROTO_EON 80 /* ISO cnlp */ 61df8bae1dSRodney W. Grimes #define IPPROTO_ENCAP 98 /* encapsulation header */ 62df8bae1dSRodney W. Grimes 63df8bae1dSRodney W. Grimes #define IPPROTO_RAW 255 /* raw IP packet */ 64df8bae1dSRodney W. Grimes #define IPPROTO_MAX 256 65df8bae1dSRodney W. Grimes 66df8bae1dSRodney W. Grimes 67df8bae1dSRodney W. Grimes /* 68df8bae1dSRodney W. Grimes * Local port number conventions: 69df8bae1dSRodney W. Grimes * Ports < IPPORT_RESERVED are reserved for 70df8bae1dSRodney W. Grimes * privileged processes (e.g. root). 71df8bae1dSRodney W. Grimes * Ports > IPPORT_USERRESERVED are reserved 72df8bae1dSRodney W. Grimes * for servers, not necessarily privileged. 73df8bae1dSRodney W. Grimes */ 74df8bae1dSRodney W. Grimes #define IPPORT_RESERVED 1024 75df8bae1dSRodney W. Grimes #define IPPORT_USERRESERVED 5000 76df8bae1dSRodney W. Grimes 77df8bae1dSRodney W. Grimes /* 78df8bae1dSRodney W. Grimes * Internet address (a structure for historical reasons) 79df8bae1dSRodney W. Grimes */ 80df8bae1dSRodney W. Grimes struct in_addr { 81df8bae1dSRodney W. Grimes u_long s_addr; 82df8bae1dSRodney W. Grimes }; 83df8bae1dSRodney W. Grimes 84df8bae1dSRodney W. Grimes /* 85df8bae1dSRodney W. Grimes * Definitions of bits in internet address integers. 86df8bae1dSRodney W. Grimes * On subnets, the decomposition of addresses to host and net parts 87df8bae1dSRodney W. Grimes * is done according to subnet mask, not the masks here. 88df8bae1dSRodney W. Grimes */ 89df8bae1dSRodney W. Grimes #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 90df8bae1dSRodney W. Grimes #define IN_CLASSA_NET 0xff000000 91df8bae1dSRodney W. Grimes #define IN_CLASSA_NSHIFT 24 92df8bae1dSRodney W. Grimes #define IN_CLASSA_HOST 0x00ffffff 93df8bae1dSRodney W. Grimes #define IN_CLASSA_MAX 128 94df8bae1dSRodney W. Grimes 95df8bae1dSRodney W. Grimes #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 96df8bae1dSRodney W. Grimes #define IN_CLASSB_NET 0xffff0000 97df8bae1dSRodney W. Grimes #define IN_CLASSB_NSHIFT 16 98df8bae1dSRodney W. Grimes #define IN_CLASSB_HOST 0x0000ffff 99df8bae1dSRodney W. Grimes #define IN_CLASSB_MAX 65536 100df8bae1dSRodney W. Grimes 101df8bae1dSRodney W. Grimes #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 102df8bae1dSRodney W. Grimes #define IN_CLASSC_NET 0xffffff00 103df8bae1dSRodney W. Grimes #define IN_CLASSC_NSHIFT 8 104df8bae1dSRodney W. Grimes #define IN_CLASSC_HOST 0x000000ff 105df8bae1dSRodney W. Grimes 106df8bae1dSRodney W. Grimes #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 107df8bae1dSRodney W. Grimes #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 108df8bae1dSRodney W. Grimes #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 109df8bae1dSRodney W. Grimes #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 110df8bae1dSRodney W. Grimes #define IN_MULTICAST(i) IN_CLASSD(i) 111df8bae1dSRodney W. Grimes 112df8bae1dSRodney W. Grimes #define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000) 113df8bae1dSRodney W. Grimes #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 114df8bae1dSRodney W. Grimes 115df8bae1dSRodney W. Grimes #define INADDR_ANY (u_long)0x00000000 116df8bae1dSRodney W. Grimes #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 117df8bae1dSRodney W. Grimes #ifndef KERNEL 118df8bae1dSRodney W. Grimes #define INADDR_NONE 0xffffffff /* -1 return */ 119df8bae1dSRodney W. Grimes #endif 120df8bae1dSRodney W. Grimes 121df8bae1dSRodney W. Grimes #define INADDR_UNSPEC_GROUP (u_long)0xe0000000 /* 224.0.0.0 */ 122df8bae1dSRodney W. Grimes #define INADDR_ALLHOSTS_GROUP (u_long)0xe0000001 /* 224.0.0.1 */ 123df8bae1dSRodney W. Grimes #define INADDR_MAX_LOCAL_GROUP (u_long)0xe00000ff /* 224.0.0.255 */ 124df8bae1dSRodney W. Grimes 125df8bae1dSRodney W. Grimes #define IN_LOOPBACKNET 127 /* official! */ 126df8bae1dSRodney W. Grimes 127df8bae1dSRodney W. Grimes /* 128df8bae1dSRodney W. Grimes * Socket address, internet style. 129df8bae1dSRodney W. Grimes */ 130df8bae1dSRodney W. Grimes struct sockaddr_in { 131df8bae1dSRodney W. Grimes u_char sin_len; 132df8bae1dSRodney W. Grimes u_char sin_family; 133df8bae1dSRodney W. Grimes u_short sin_port; 134df8bae1dSRodney W. Grimes struct in_addr sin_addr; 135df8bae1dSRodney W. Grimes char sin_zero[8]; 136df8bae1dSRodney W. Grimes }; 137df8bae1dSRodney W. Grimes 138df8bae1dSRodney W. Grimes /* 139df8bae1dSRodney W. Grimes * Structure used to describe IP options. 140df8bae1dSRodney W. Grimes * Used to store options internally, to pass them to a process, 141df8bae1dSRodney W. Grimes * or to restore options retrieved earlier. 142df8bae1dSRodney W. Grimes * The ip_dst is used for the first-hop gateway when using a source route 143df8bae1dSRodney W. Grimes * (this gets put into the header proper). 144df8bae1dSRodney W. Grimes */ 145df8bae1dSRodney W. Grimes struct ip_opts { 146df8bae1dSRodney W. Grimes struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 147df8bae1dSRodney W. Grimes char ip_opts[40]; /* actually variable in size */ 148df8bae1dSRodney W. Grimes }; 149df8bae1dSRodney W. Grimes 150df8bae1dSRodney W. Grimes /* 151df8bae1dSRodney W. Grimes * Options for use with [gs]etsockopt at the IP level. 152df8bae1dSRodney W. Grimes * First word of comment is data type; bool is stored in int. 153df8bae1dSRodney W. Grimes */ 154df8bae1dSRodney W. Grimes #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 155df8bae1dSRodney W. Grimes #define IP_HDRINCL 2 /* int; header is included with data */ 156df8bae1dSRodney W. Grimes #define IP_TOS 3 /* int; IP type of service and preced. */ 157df8bae1dSRodney W. Grimes #define IP_TTL 4 /* int; IP time to live */ 158df8bae1dSRodney W. Grimes #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 159df8bae1dSRodney W. Grimes #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 160df8bae1dSRodney W. Grimes #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 161df8bae1dSRodney W. Grimes #define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 162df8bae1dSRodney W. Grimes #define IP_MULTICAST_IF 9 /* u_char; set/get IP multicast i/f */ 163df8bae1dSRodney W. Grimes #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 164df8bae1dSRodney W. Grimes #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 165df8bae1dSRodney W. Grimes #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 166df8bae1dSRodney W. Grimes #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 167f0068c4aSGarrett Wollman #define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */ 168f0068c4aSGarrett Wollman #define IP_RSVP_ON 15 /* enable RSVP in kernel */ 169f0068c4aSGarrett Wollman #define IP_RSVP_OFF 16 /* disable RSVP in kernel */ 1701c5de19aSGarrett Wollman #define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */ 1711c5de19aSGarrett Wollman #define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */ 172df8bae1dSRodney W. Grimes 173df8bae1dSRodney W. Grimes /* 174df8bae1dSRodney W. Grimes * Defaults and limits for options 175df8bae1dSRodney W. Grimes */ 176df8bae1dSRodney W. Grimes #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 177df8bae1dSRodney W. Grimes #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 1781c5de19aSGarrett Wollman #define IP_MAX_MEMBERSHIPS 20 /* per socket */ 179df8bae1dSRodney W. Grimes 180df8bae1dSRodney W. Grimes /* 181df8bae1dSRodney W. Grimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 182df8bae1dSRodney W. Grimes */ 183df8bae1dSRodney W. Grimes struct ip_mreq { 184df8bae1dSRodney W. Grimes struct in_addr imr_multiaddr; /* IP multicast address of group */ 185df8bae1dSRodney W. Grimes struct in_addr imr_interface; /* local IP address of interface */ 186df8bae1dSRodney W. Grimes }; 187df8bae1dSRodney W. Grimes 188df8bae1dSRodney W. Grimes /* 189df8bae1dSRodney W. Grimes * Definitions for inet sysctl operations. 190df8bae1dSRodney W. Grimes * 191df8bae1dSRodney W. Grimes * Third level is protocol number. 192df8bae1dSRodney W. Grimes * Fourth level is desired variable within that protocol. 193df8bae1dSRodney W. Grimes */ 194df8bae1dSRodney W. Grimes #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ 195df8bae1dSRodney W. Grimes 196df8bae1dSRodney W. Grimes #define CTL_IPPROTO_NAMES { \ 197df8bae1dSRodney W. Grimes { "ip", CTLTYPE_NODE }, \ 198df8bae1dSRodney W. Grimes { "icmp", CTLTYPE_NODE }, \ 199df8bae1dSRodney W. Grimes { "igmp", CTLTYPE_NODE }, \ 200df8bae1dSRodney W. Grimes { "ggp", CTLTYPE_NODE }, \ 201df8bae1dSRodney W. Grimes { 0, 0 }, \ 202df8bae1dSRodney W. Grimes { 0, 0 }, \ 203df8bae1dSRodney W. Grimes { "tcp", CTLTYPE_NODE }, \ 204df8bae1dSRodney W. Grimes { 0, 0 }, \ 205df8bae1dSRodney W. Grimes { "egp", CTLTYPE_NODE }, \ 206df8bae1dSRodney W. Grimes { 0, 0 }, \ 207df8bae1dSRodney W. Grimes { 0, 0 }, \ 208df8bae1dSRodney W. Grimes { 0, 0 }, \ 209df8bae1dSRodney W. Grimes { "pup", CTLTYPE_NODE }, \ 210df8bae1dSRodney W. Grimes { 0, 0 }, \ 211df8bae1dSRodney W. Grimes { 0, 0 }, \ 212df8bae1dSRodney W. Grimes { 0, 0 }, \ 213df8bae1dSRodney W. Grimes { 0, 0 }, \ 214df8bae1dSRodney W. Grimes { "udp", CTLTYPE_NODE }, \ 215df8bae1dSRodney W. Grimes { 0, 0 }, \ 216df8bae1dSRodney W. Grimes { 0, 0 }, \ 217df8bae1dSRodney W. Grimes { 0, 0 }, \ 218df8bae1dSRodney W. Grimes { 0, 0 }, \ 219df8bae1dSRodney W. Grimes { "idp", CTLTYPE_NODE }, \ 220df8bae1dSRodney W. Grimes } 221df8bae1dSRodney W. Grimes 222df8bae1dSRodney W. Grimes /* 223df8bae1dSRodney W. Grimes * Names for IP sysctl objects 224df8bae1dSRodney W. Grimes */ 225df8bae1dSRodney W. Grimes #define IPCTL_FORWARDING 1 /* act as router */ 226df8bae1dSRodney W. Grimes #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 227df8bae1dSRodney W. Grimes #define IPCTL_DEFTTL 3 /* default TTL */ 228df8bae1dSRodney W. Grimes #ifdef notyet 229df8bae1dSRodney W. Grimes #define IPCTL_DEFMTU 4 /* default MTU */ 230df8bae1dSRodney W. Grimes #endif 2315be2baf8SGarrett Wollman #define IPCTL_RTEXPIRE 5 /* cloned route expiration time */ 232ea80aed1SGarrett Wollman #define IPCTL_RTMINEXPIRE 6 /* min value for expiration time */ 233ea80aed1SGarrett Wollman #define IPCTL_RTMAXCACHE 7 /* trigger level for dynamic expire */ 2341025071fSGarrett Wollman #define IPCTL_SOURCEROUTE 8 /* may perform source routes */ 2351025071fSGarrett Wollman #define IPCTL_MAXID 9 236df8bae1dSRodney W. Grimes 237df8bae1dSRodney W. Grimes #define IPCTL_NAMES { \ 238df8bae1dSRodney W. Grimes { 0, 0 }, \ 239df8bae1dSRodney W. Grimes { "forwarding", CTLTYPE_INT }, \ 240df8bae1dSRodney W. Grimes { "redirect", CTLTYPE_INT }, \ 241df8bae1dSRodney W. Grimes { "ttl", CTLTYPE_INT }, \ 242df8bae1dSRodney W. Grimes { "mtu", CTLTYPE_INT }, \ 2435be2baf8SGarrett Wollman { "rtexpire", CTLTYPE_INT }, \ 244ea80aed1SGarrett Wollman { "rtminexpire", CTLTYPE_INT }, \ 245ea80aed1SGarrett Wollman { "rtmaxcache", CTLTYPE_INT }, \ 2461025071fSGarrett Wollman { "sourceroute", CTLTYPE_INT }, \ 247df8bae1dSRodney W. Grimes } 248df8bae1dSRodney W. Grimes 249df8bae1dSRodney W. Grimes 250df8bae1dSRodney W. Grimes #ifdef KERNEL 251ef0cdf33SGarrett Wollman struct ifnet; struct mbuf; /* forward declarations for Standard C */ 252ef0cdf33SGarrett Wollman 253df8bae1dSRodney W. Grimes int in_broadcast __P((struct in_addr, struct ifnet *)); 254df8bae1dSRodney W. Grimes int in_canforward __P((struct in_addr)); 255df8bae1dSRodney W. Grimes int in_cksum __P((struct mbuf *, int)); 256df8bae1dSRodney W. Grimes int in_localaddr __P((struct in_addr)); 257df8bae1dSRodney W. Grimes u_long in_netof __P((struct in_addr)); 258df8bae1dSRodney W. Grimes void in_socktrim __P((struct sockaddr_in *)); 259ef0cdf33SGarrett Wollman char *inet_ntoa __P((struct in_addr)); /* in libkern */ 260df8bae1dSRodney W. Grimes #endif 261707f139eSPaul Richards 262707f139eSPaul Richards #endif 2635be2baf8SGarrett Wollman 264