in.h revision 9575
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1990, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)in.h	8.3 (Berkeley) 1/3/94
349575Speter * $Id: in.h,v 1.10 1995/06/13 17:51:08 wollman Exp $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IN_H_
382169Spaul#define _NETINET_IN_H_
392169Spaul
401541Srgrimes/*
411541Srgrimes * Constants and structures defined by the internet system,
421541Srgrimes * Per RFC 790, September 1981, and numerous additions.
431541Srgrimes */
441541Srgrimes
451541Srgrimes/*
461541Srgrimes * Protocols
471541Srgrimes */
481541Srgrimes#define	IPPROTO_IP		0		/* dummy for IP */
491541Srgrimes#define	IPPROTO_ICMP		1		/* control message protocol */
501541Srgrimes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
511541Srgrimes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
529209Swollman#define IPPROTO_IPIP		4 		/* IP encapsulation in IP */
531541Srgrimes#define	IPPROTO_TCP		6		/* tcp */
541541Srgrimes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
551541Srgrimes#define	IPPROTO_PUP		12		/* pup */
561541Srgrimes#define	IPPROTO_UDP		17		/* user datagram protocol */
571541Srgrimes#define	IPPROTO_IDP		22		/* xns idp */
581541Srgrimes#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
592531Swollman#define IPPROTO_RSVP		46 		/* resource reservation */
601541Srgrimes#define	IPPROTO_EON		80		/* ISO cnlp */
611541Srgrimes#define	IPPROTO_ENCAP		98		/* encapsulation header */
621541Srgrimes
631541Srgrimes#define	IPPROTO_RAW		255		/* raw IP packet */
641541Srgrimes#define	IPPROTO_MAX		256
651541Srgrimes
661541Srgrimes
671541Srgrimes/*
681541Srgrimes * Local port number conventions:
691541Srgrimes * Ports < IPPORT_RESERVED are reserved for
701541Srgrimes * privileged processes (e.g. root).
711541Srgrimes * Ports > IPPORT_USERRESERVED are reserved
721541Srgrimes * for servers, not necessarily privileged.
731541Srgrimes */
741541Srgrimes#define	IPPORT_RESERVED		1024
751541Srgrimes#define	IPPORT_USERRESERVED	5000
761541Srgrimes
771541Srgrimes/*
781541Srgrimes * Internet address (a structure for historical reasons)
791541Srgrimes */
801541Srgrimesstruct in_addr {
811541Srgrimes	u_long s_addr;
821541Srgrimes};
831541Srgrimes
841541Srgrimes/*
851541Srgrimes * Definitions of bits in internet address integers.
861541Srgrimes * On subnets, the decomposition of addresses to host and net parts
871541Srgrimes * is done according to subnet mask, not the masks here.
881541Srgrimes */
891541Srgrimes#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
901541Srgrimes#define	IN_CLASSA_NET		0xff000000
911541Srgrimes#define	IN_CLASSA_NSHIFT	24
921541Srgrimes#define	IN_CLASSA_HOST		0x00ffffff
931541Srgrimes#define	IN_CLASSA_MAX		128
941541Srgrimes
951541Srgrimes#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
961541Srgrimes#define	IN_CLASSB_NET		0xffff0000
971541Srgrimes#define	IN_CLASSB_NSHIFT	16
981541Srgrimes#define	IN_CLASSB_HOST		0x0000ffff
991541Srgrimes#define	IN_CLASSB_MAX		65536
1001541Srgrimes
1011541Srgrimes#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
1021541Srgrimes#define	IN_CLASSC_NET		0xffffff00
1031541Srgrimes#define	IN_CLASSC_NSHIFT	8
1041541Srgrimes#define	IN_CLASSC_HOST		0x000000ff
1051541Srgrimes
1061541Srgrimes#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
1071541Srgrimes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
1081541Srgrimes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
1091541Srgrimes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
1101541Srgrimes#define	IN_MULTICAST(i)		IN_CLASSD(i)
1111541Srgrimes
1121541Srgrimes#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)
1131541Srgrimes#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
1141541Srgrimes
1151541Srgrimes#define	INADDR_ANY		(u_long)0x00000000
1161541Srgrimes#define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
1171541Srgrimes#ifndef KERNEL
1181541Srgrimes#define	INADDR_NONE		0xffffffff		/* -1 return */
1191541Srgrimes#endif
1201541Srgrimes
1211541Srgrimes#define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
1221541Srgrimes#define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */
1231541Srgrimes#define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
1241541Srgrimes
1251541Srgrimes#define	IN_LOOPBACKNET		127			/* official! */
1261541Srgrimes
1271541Srgrimes/*
1281541Srgrimes * Socket address, internet style.
1291541Srgrimes */
1301541Srgrimesstruct sockaddr_in {
1311541Srgrimes	u_char	sin_len;
1321541Srgrimes	u_char	sin_family;
1331541Srgrimes	u_short	sin_port;
1341541Srgrimes	struct	in_addr sin_addr;
1351541Srgrimes	char	sin_zero[8];
1361541Srgrimes};
1371541Srgrimes
1381541Srgrimes/*
1391541Srgrimes * Structure used to describe IP options.
1401541Srgrimes * Used to store options internally, to pass them to a process,
1411541Srgrimes * or to restore options retrieved earlier.
1421541Srgrimes * The ip_dst is used for the first-hop gateway when using a source route
1431541Srgrimes * (this gets put into the header proper).
1441541Srgrimes */
1451541Srgrimesstruct ip_opts {
1461541Srgrimes	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
1471541Srgrimes	char	ip_opts[40];		/* actually variable in size */
1481541Srgrimes};
1491541Srgrimes
1501541Srgrimes/*
1511541Srgrimes * Options for use with [gs]etsockopt at the IP level.
1521541Srgrimes * First word of comment is data type; bool is stored in int.
1531541Srgrimes */
1541541Srgrimes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
1551541Srgrimes#define	IP_HDRINCL		2    /* int; header is included with data */
1561541Srgrimes#define	IP_TOS			3    /* int; IP type of service and preced. */
1571541Srgrimes#define	IP_TTL			4    /* int; IP time to live */
1581541Srgrimes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
1591541Srgrimes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
1601541Srgrimes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
1611541Srgrimes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
1621541Srgrimes#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
1631541Srgrimes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
1641541Srgrimes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
1651541Srgrimes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
1661541Srgrimes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
1672531Swollman#define IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
1682531Swollman#define IP_RSVP_ON		15   /* enable RSVP in kernel */
1692531Swollman#define IP_RSVP_OFF		16   /* disable RSVP in kernel */
1709209Swollman#define IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
1719209Swollman#define IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
1721541Srgrimes
1731541Srgrimes/*
1741541Srgrimes * Defaults and limits for options
1751541Srgrimes */
1761541Srgrimes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
1771541Srgrimes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
1789209Swollman#define	IP_MAX_MEMBERSHIPS	20	/* per socket */
1791541Srgrimes
1801541Srgrimes/*
1811541Srgrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
1821541Srgrimes */
1831541Srgrimesstruct ip_mreq {
1841541Srgrimes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
1851541Srgrimes	struct	in_addr imr_interface;	/* local IP address of interface */
1861541Srgrimes};
1871541Srgrimes
1881541Srgrimes/*
1891541Srgrimes * Definitions for inet sysctl operations.
1901541Srgrimes *
1911541Srgrimes * Third level is protocol number.
1921541Srgrimes * Fourth level is desired variable within that protocol.
1931541Srgrimes */
1941541Srgrimes#define	IPPROTO_MAXID	(IPPROTO_IDP + 1)	/* don't list to IPPROTO_MAX */
1951541Srgrimes
1961541Srgrimes#define	CTL_IPPROTO_NAMES { \
1971541Srgrimes	{ "ip", CTLTYPE_NODE }, \
1981541Srgrimes	{ "icmp", CTLTYPE_NODE }, \
1991541Srgrimes	{ "igmp", CTLTYPE_NODE }, \
2001541Srgrimes	{ "ggp", CTLTYPE_NODE }, \
2011541Srgrimes	{ 0, 0 }, \
2021541Srgrimes	{ 0, 0 }, \
2031541Srgrimes	{ "tcp", CTLTYPE_NODE }, \
2041541Srgrimes	{ 0, 0 }, \
2051541Srgrimes	{ "egp", CTLTYPE_NODE }, \
2061541Srgrimes	{ 0, 0 }, \
2071541Srgrimes	{ 0, 0 }, \
2081541Srgrimes	{ 0, 0 }, \
2091541Srgrimes	{ "pup", CTLTYPE_NODE }, \
2101541Srgrimes	{ 0, 0 }, \
2111541Srgrimes	{ 0, 0 }, \
2121541Srgrimes	{ 0, 0 }, \
2131541Srgrimes	{ 0, 0 }, \
2141541Srgrimes	{ "udp", CTLTYPE_NODE }, \
2151541Srgrimes	{ 0, 0 }, \
2161541Srgrimes	{ 0, 0 }, \
2171541Srgrimes	{ 0, 0 }, \
2181541Srgrimes	{ 0, 0 }, \
2191541Srgrimes	{ "idp", CTLTYPE_NODE }, \
2201541Srgrimes}
2211541Srgrimes
2221541Srgrimes/*
2231541Srgrimes * Names for IP sysctl objects
2241541Srgrimes */
2251541Srgrimes#define	IPCTL_FORWARDING	1	/* act as router */
2261541Srgrimes#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
2271541Srgrimes#define	IPCTL_DEFTTL		3	/* default TTL */
2281541Srgrimes#ifdef notyet
2291541Srgrimes#define	IPCTL_DEFMTU		4	/* default MTU */
2301541Srgrimes#endif
2315109Swollman#define IPCTL_RTEXPIRE		5	/* cloned route expiration time */
2326399Swollman#define IPCTL_RTMINEXPIRE	6	/* min value for expiration time */
2336399Swollman#define IPCTL_RTMAXCACHE	7	/* trigger level for dynamic expire */
2347091Swollman#define	IPCTL_SOURCEROUTE	8	/* may perform source routes */
2359575Speter#define	IPCTL_DIRECTEDBROADCAST	9	/* may re-broadcast received packets */
2369575Speter#define	IPCTL_MAXID		10
2371541Srgrimes
2381541Srgrimes#define	IPCTL_NAMES { \
2391541Srgrimes	{ 0, 0 }, \
2401541Srgrimes	{ "forwarding", CTLTYPE_INT }, \
2411541Srgrimes	{ "redirect", CTLTYPE_INT }, \
2421541Srgrimes	{ "ttl", CTLTYPE_INT }, \
2431541Srgrimes	{ "mtu", CTLTYPE_INT }, \
2445109Swollman	{ "rtexpire", CTLTYPE_INT }, \
2456399Swollman	{ "rtminexpire", CTLTYPE_INT }, \
2466399Swollman	{ "rtmaxcache", CTLTYPE_INT }, \
2477091Swollman	{ "sourceroute", CTLTYPE_INT }, \
2489575Speter 	{ "directed-broadcast", CTLTYPE_INT }, \
2491541Srgrimes}
2501541Srgrimes
2511541Srgrimes
2521541Srgrimes#ifdef KERNEL
2537088Swollmanstruct ifnet; struct mbuf;	/* forward declarations for Standard C */
2547088Swollman
2551541Srgrimesint	 in_broadcast __P((struct in_addr, struct ifnet *));
2561541Srgrimesint	 in_canforward __P((struct in_addr));
2571541Srgrimesint	 in_cksum __P((struct mbuf *, int));
2581541Srgrimesint	 in_localaddr __P((struct in_addr));
2591541Srgrimesu_long	 in_netof __P((struct in_addr));
2601541Srgrimesvoid	 in_socktrim __P((struct sockaddr_in *));
2617088Swollmanchar 	*inet_ntoa __P((struct in_addr)); /* in libkern */
2621541Srgrimes#endif
2632169Spaul
2642169Spaul#endif
2655109Swollman
266