in.h revision 95336
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
3450477Speter * $FreeBSD: head/sys/netinet/in.h 95336 2002-04-24 01:26:11Z mike $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IN_H_
382169Spaul#define _NETINET_IN_H_
392169Spaul
4095336Smike#include <sys/cdefs.h>
4193514Smike#include <sys/_types.h>
4295336Smike#include <machine/endian.h>
4393514Smike
4495336Smike/* Protocols common to RFC 1700, POSIX, and X/Open. */
4595336Smike#define	IPPROTO_IP		0		/* dummy for IP */
4695336Smike#define	IPPROTO_ICMP		1		/* control message protocol */
4795336Smike#define	IPPROTO_TCP		6		/* tcp */
4895336Smike#define	IPPROTO_UDP		17		/* user datagram protocol */
4995336Smike
5095336Smike#define	INADDR_ANY		(u_int32_t)0x00000000
5195336Smike#define	INADDR_BROADCAST	(u_int32_t)0xffffffff	/* must be masked */
5295336Smike
5395336Smike#ifndef _UINT8_T_DECLARED
5495336Smiketypedef	__uint8_t		uint8_t;
5595336Smike#define	_UINT8_T_DECLARED
5695336Smike#endif
5795336Smike
5895336Smike#ifndef _UINT16_T_DECLARED
5995336Smiketypedef	__uint16_t		uint16_t;
6095336Smike#define	_UINT16_T_DECLARED
6195336Smike#endif
6295336Smike
6395336Smike#ifndef _UINT32_T_DECLARED
6495336Smiketypedef	__uint32_t		uint32_t;
6595336Smike#define	_UINT32_T_DECLARED
6695336Smike#endif
6795336Smike
6895336Smike#ifndef _IN_ADDR_T_DECLARED
6995336Smiketypedef	uint32_t		in_addr_t;
7095336Smike#define	_IN_ADDR_T_DECLARED
7195336Smike#endif
7295336Smike
7395336Smike#ifndef _IN_PORT_T_DECLARED
7495336Smiketypedef	uint16_t		in_port_t;
7595336Smike#define	_IN_PORT_T_DECLARED
7695336Smike#endif
7795336Smike
7895336Smike#ifdef _BSD_SA_FAMILY_T_
7995336Smiketypedef	_BSD_SA_FAMILY_T_	sa_family_t;
8095336Smike#undef _BSD_SA_FAMILY_T_
8195336Smike#endif
8295336Smike
8395336Smike/* Internet address (a structure for historical reasons). */
8495336Smike#ifndef	_STRUCT_IN_ADDR_DECLARED
8595336Smikestruct in_addr {
8695336Smike	in_addr_t s_addr;
8795336Smike};
8895336Smike#define	_STRUCT_IN_ADDR_DECLARED
8995336Smike#endif
9095336Smike
9195336Smike/* Socket address, internet style. */
9295336Smikestruct sockaddr_in {
9395336Smike	uint8_t	sin_len;
9495336Smike	sa_family_t	sin_family;
9595336Smike	in_port_t	sin_port;
9695336Smike	struct	in_addr sin_addr;
9795336Smike	char	sin_zero[8];
9895336Smike};
9995336Smike
10095336Smike#ifndef _KERNEL
10195336Smike
10295336Smike#ifndef _BYTEORDER_PROTOTYPED
10395336Smike#define	_BYTEORDER_PROTOTYPED
10495336Smike__BEGIN_DECLS
10595336Smikeuint32_t	htonl(uint32_t);
10695336Smikeuint16_t	htons(uint16_t);
10795336Smikeuint32_t	ntohl(uint32_t);
10895336Smikeuint16_t	ntohs(uint16_t);
10995336Smike__END_DECLS
11095336Smike#endif
11195336Smike
11295336Smike#ifndef _BYTEORDER_FUNC_DEFINED
11395336Smike#define	_BYTEORDER_FUNC_DEFINED
11495336Smike#define	htonl(x)	__htonl(x)
11595336Smike#define	htons(x)	__htons(x)
11695336Smike#define	ntohl(x)	__ntohl(x)
11795336Smike#define	ntohs(x)	__ntohs(x)
11895336Smike#endif
11995336Smike
12095336Smike#endif /* !_KERNEL */
12195336Smike
12295336Smike#if __POSIX_VISIBLE >= 200112
12395336Smike#define	IPPROTO_RAW		255		/* raw IP packet */
12495336Smike#define	INET_ADDRSTRLEN		16
12595336Smike#endif
12695336Smike
12795336Smike#if __BSD_VISIBLE
1281541Srgrimes/*
1291541Srgrimes * Constants and structures defined by the internet system,
1301541Srgrimes * Per RFC 790, September 1981, and numerous additions.
1311541Srgrimes */
1321541Srgrimes
1331541Srgrimes/*
13433804Sjulian * Protocols (RFC 1700)
1351541Srgrimes */
13652904Sshin#define	IPPROTO_HOPOPTS		0		/* IP6 hop-by-hop options */
1371541Srgrimes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
1381541Srgrimes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
13952904Sshin#define IPPROTO_IPV4		4 		/* IPv4 encapsulation */
14052904Sshin#define IPPROTO_IPIP		IPPROTO_IPV4	/* for compatibility */
14133804Sjulian#define	IPPROTO_ST		7		/* Stream protocol II */
1421541Srgrimes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
14333804Sjulian#define	IPPROTO_PIGP		9		/* private interior gateway */
14433804Sjulian#define	IPPROTO_RCCMON		10		/* BBN RCC Monitoring */
14533804Sjulian#define	IPPROTO_NVPII		11		/* network voice protocol*/
1461541Srgrimes#define	IPPROTO_PUP		12		/* pup */
14733804Sjulian#define	IPPROTO_ARGUS		13		/* Argus */
14833804Sjulian#define	IPPROTO_EMCON		14		/* EMCON */
14933804Sjulian#define	IPPROTO_XNET		15		/* Cross Net Debugger */
15033804Sjulian#define	IPPROTO_CHAOS		16		/* Chaos*/
15133804Sjulian#define	IPPROTO_MUX		18		/* Multiplexing */
15233804Sjulian#define	IPPROTO_MEAS		19		/* DCN Measurement Subsystems */
15333804Sjulian#define	IPPROTO_HMP		20		/* Host Monitoring */
15433804Sjulian#define	IPPROTO_PRM		21		/* Packet Radio Measurement */
1551541Srgrimes#define	IPPROTO_IDP		22		/* xns idp */
15633804Sjulian#define	IPPROTO_TRUNK1		23		/* Trunk-1 */
15733804Sjulian#define	IPPROTO_TRUNK2		24		/* Trunk-2 */
15833804Sjulian#define	IPPROTO_LEAF1		25		/* Leaf-1 */
15933804Sjulian#define	IPPROTO_LEAF2		26		/* Leaf-2 */
16033804Sjulian#define	IPPROTO_RDP		27		/* Reliable Data */
16133804Sjulian#define	IPPROTO_IRTP		28		/* Reliable Transaction */
1621541Srgrimes#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
16333804Sjulian#define	IPPROTO_BLT		30		/* Bulk Data Transfer */
16433804Sjulian#define	IPPROTO_NSP		31		/* Network Services */
16533804Sjulian#define	IPPROTO_INP		32		/* Merit Internodal */
16633804Sjulian#define	IPPROTO_SEP		33		/* Sequential Exchange */
16733804Sjulian#define	IPPROTO_3PC		34		/* Third Party Connect */
16833804Sjulian#define	IPPROTO_IDPR		35		/* InterDomain Policy Routing */
16933804Sjulian#define	IPPROTO_XTP		36		/* XTP */
17033804Sjulian#define	IPPROTO_DDP		37		/* Datagram Delivery */
17133804Sjulian#define	IPPROTO_CMTP		38		/* Control Message Transport */
17233804Sjulian#define	IPPROTO_TPXX		39		/* TP++ Transport */
17333804Sjulian#define	IPPROTO_IL		40		/* IL transport protocol */
17452904Sshin#define	IPPROTO_IPV6		41		/* IP6 header */
17533804Sjulian#define	IPPROTO_SDRP		42		/* Source Demand Routing */
17652904Sshin#define	IPPROTO_ROUTING		43		/* IP6 routing header */
17752904Sshin#define	IPPROTO_FRAGMENT	44		/* IP6 fragmentation header */
17833804Sjulian#define	IPPROTO_IDRP		45		/* InterDomain Routing*/
17952904Sshin#define	IPPROTO_RSVP		46 		/* resource reservation */
18033804Sjulian#define	IPPROTO_GRE		47		/* General Routing Encap. */
18133804Sjulian#define	IPPROTO_MHRP		48		/* Mobile Host Routing */
18233804Sjulian#define	IPPROTO_BHA		49		/* BHA */
18352904Sshin#define	IPPROTO_ESP		50		/* IP6 Encap Sec. Payload */
18452904Sshin#define	IPPROTO_AH		51		/* IP6 Auth Header */
18533804Sjulian#define	IPPROTO_INLSP		52		/* Integ. Net Layer Security */
18633804Sjulian#define	IPPROTO_SWIPE		53		/* IP with encryption */
18733804Sjulian#define	IPPROTO_NHRP		54		/* Next Hop Resolution */
18872486Sasmodai#define IPPROTO_MOBILE		55		/* IP Mobility */
18972486Sasmodai#define IPPROTO_TLSP		56		/* Transport Layer Security */
19072486Sasmodai#define IPPROTO_SKIP		57		/* SKIP */
19152904Sshin#define	IPPROTO_ICMPV6		58		/* ICMP6 */
19252904Sshin#define	IPPROTO_NONE		59		/* IP6 no next header */
19352904Sshin#define	IPPROTO_DSTOPTS		60		/* IP6 destination option */
19433804Sjulian#define	IPPROTO_AHIP		61		/* any host internal protocol */
19533804Sjulian#define	IPPROTO_CFTP		62		/* CFTP */
19633804Sjulian#define	IPPROTO_HELLO		63		/* "hello" routing protocol */
19733804Sjulian#define	IPPROTO_SATEXPAK	64		/* SATNET/Backroom EXPAK */
19833804Sjulian#define	IPPROTO_KRYPTOLAN	65		/* Kryptolan */
19933804Sjulian#define	IPPROTO_RVD		66		/* Remote Virtual Disk */
20033804Sjulian#define	IPPROTO_IPPC		67		/* Pluribus Packet Core */
20133804Sjulian#define	IPPROTO_ADFS		68		/* Any distributed FS */
20233804Sjulian#define	IPPROTO_SATMON		69		/* Satnet Monitoring */
20333804Sjulian#define	IPPROTO_VISA		70		/* VISA Protocol */
20433804Sjulian#define	IPPROTO_IPCV		71		/* Packet Core Utility */
20533804Sjulian#define	IPPROTO_CPNX		72		/* Comp. Prot. Net. Executive */
20633804Sjulian#define	IPPROTO_CPHB		73		/* Comp. Prot. HeartBeat */
20733804Sjulian#define	IPPROTO_WSN		74		/* Wang Span Network */
20833804Sjulian#define	IPPROTO_PVP		75		/* Packet Video Protocol */
20933804Sjulian#define	IPPROTO_BRSATMON	76		/* BackRoom SATNET Monitoring */
21033804Sjulian#define	IPPROTO_ND		77		/* Sun net disk proto (temp.) */
21133804Sjulian#define	IPPROTO_WBMON		78		/* WIDEBAND Monitoring */
21233804Sjulian#define	IPPROTO_WBEXPAK		79		/* WIDEBAND EXPAK */
2131541Srgrimes#define	IPPROTO_EON		80		/* ISO cnlp */
21433804Sjulian#define	IPPROTO_VMTP		81		/* VMTP */
21533804Sjulian#define	IPPROTO_SVMTP		82		/* Secure VMTP */
21633804Sjulian#define	IPPROTO_VINES		83		/* Banyon VINES */
21733804Sjulian#define	IPPROTO_TTP		84		/* TTP */
21833804Sjulian#define	IPPROTO_IGP		85		/* NSFNET-IGP */
21933804Sjulian#define	IPPROTO_DGP		86		/* dissimilar gateway prot. */
22033814Sjulian#define	IPPROTO_TCF		87		/* TCF */
22133804Sjulian#define	IPPROTO_IGRP		88		/* Cisco/GXS IGRP */
22233804Sjulian#define	IPPROTO_OSPFIGP		89		/* OSPFIGP */
22333804Sjulian#define	IPPROTO_SRPC		90		/* Strite RPC protocol */
22433804Sjulian#define	IPPROTO_LARP		91		/* Locus Address Resoloution */
22533804Sjulian#define	IPPROTO_MTP		92		/* Multicast Transport */
22633804Sjulian#define	IPPROTO_AX25		93		/* AX.25 Frames */
22733804Sjulian#define	IPPROTO_IPEIP		94		/* IP encapsulated in IP */
22833804Sjulian#define	IPPROTO_MICP		95		/* Mobile Int.ing control */
22933804Sjulian#define	IPPROTO_SCCSP		96		/* Semaphore Comm. security */
23033804Sjulian#define	IPPROTO_ETHERIP		97		/* Ethernet IP encapsulation */
2311541Srgrimes#define	IPPROTO_ENCAP		98		/* encapsulation header */
23233804Sjulian#define	IPPROTO_APES		99		/* any private encr. scheme */
23333804Sjulian#define	IPPROTO_GMTP		100		/* GMTP*/
23452904Sshin#define	IPPROTO_IPCOMP		108		/* payload compression (IPComp) */
23546420Sluigi/* 101-254: Partly Unassigned */
23652904Sshin#define	IPPROTO_PIM		103		/* Protocol Independent Mcast */
23746420Sluigi#define	IPPROTO_PGM		113		/* PGM */
23833804Sjulian/* 255: Reserved */
23933804Sjulian/* BSD Private, local use, namespace incursion */
24017072Sjulian#define	IPPROTO_DIVERT		254		/* divert pseudo-protocol */
2411541Srgrimes#define	IPPROTO_MAX		256
2421541Srgrimes
24352904Sshin/* last return value of *_input(), meaning "all job for this pkt is done".  */
24452904Sshin#define	IPPROTO_DONE		257
2451541Srgrimes
2461541Srgrimes/*
2471541Srgrimes * Local port number conventions:
24814195Speter *
24914195Speter * When a user does a bind(2) or connect(2) with a port number of zero,
25014195Speter * a non-conflicting local port address is chosen.
25194291Ssilby * The default range is IPPORT_HIFIRSTAUTO through
25294291Ssilby * IPPORT_HILASTAUTO, although that is settable by sysctl.
25314195Speter *
25414195Speter * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
25514195Speter * default assignment range.
25614195Speter *
25714195Speter * The value IP_PORTRANGE_DEFAULT causes the default behavior.
25814195Speter *
25914195Speter * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
26014195Speter * into the "high" range.  These are reserved for client outbound connections
26194291Ssilby * which do not want to be filtered by any firewalls.  Note that by default
26294291Ssilby * this is the same as IP_PORTRANGE_DEFAULT.
26314195Speter *
26414195Speter * The value IP_PORTRANGE_LOW changes the range to the "low" are
26514195Speter * that is (by convention) restricted to privileged processes.  This
26614195Speter * convention is based on "vouchsafe" principles only.  It is only secure
26714195Speter * if you trust the remote host to restrict these ports.
26814195Speter *
26914195Speter * The default range of ports and the high range can be changed by
27017541Speter * sysctl(3).  (net.inet.ip.port{hi,low}{first,last}_auto)
27114195Speter *
27214195Speter * Changing those values has bad security implications if you are
27314195Speter * using a a stateless firewall that is allowing packets outside of that
27414195Speter * range in order to allow transparent outgoing connections.
27514195Speter *
27614195Speter * Such a firewall configuration will generally depend on the use of these
27714195Speter * default values.  If you change them, you may find your Security
27814195Speter * Administrator looking for you with a heavy object.
27935304Sphk *
28035304Sphk * For a slightly more orthodox text view on this:
28135304Sphk *
28235304Sphk *            ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers
28335304Sphk *
28435304Sphk *    port numbers are divided into three ranges:
28535304Sphk *
28635304Sphk *                0 -  1023 Well Known Ports
28735304Sphk *             1024 - 49151 Registered Ports
28835304Sphk *            49152 - 65535 Dynamic and/or Private Ports
28935304Sphk *
29014195Speter */
29114195Speter
29214195Speter/*
2931541Srgrimes * Ports < IPPORT_RESERVED are reserved for
29414195Speter * privileged processes (e.g. root).         (IP_PORTRANGE_LOW)
2951541Srgrimes */
2961541Srgrimes#define	IPPORT_RESERVED		1024
2971541Srgrimes
2981541Srgrimes/*
29994379Ssilby * Default local port range, used by both IP_PORTRANGE_DEFAULT
30094379Ssilby * and IP_PORTRANGE_HIGH.
30113491Speter */
30235304Sphk#define	IPPORT_HIFIRSTAUTO	49152
30335304Sphk#define	IPPORT_HILASTAUTO	65535
30413491Speter
30513491Speter/*
30617541Speter * Scanning for a free reserved port return a value below IPPORT_RESERVED,
30717541Speter * but higher than IPPORT_RESERVEDSTART.  Traditionally the start value was
30817541Speter * 512, but that conflicts with some well-known-services that firewalls may
30917541Speter * have a fit if we use.
31017541Speter */
31117541Speter#define IPPORT_RESERVEDSTART	600
31217541Speter
31387158Smike#define	IPPORT_MAX		65535
31487158Smike
31593514Smike#ifndef _UINT8_T_DECLARED
31693514Smiketypedef	__uint8_t		uint8_t;
31793514Smike#define	_UINT8_T_DECLARED
31887158Smike#endif
31987158Smike
32093514Smike#ifndef _UINT16_T_DECLARED
32193514Smiketypedef	__uint16_t		uint16_t;
32293514Smike#define	_UINT16_T_DECLARED
32387158Smike#endif
32487158Smike
32593514Smike#ifndef _UINT32_T_DECLARED
32693514Smiketypedef	__uint32_t		uint32_t;
32793514Smike#define	_UINT32_T_DECLARED
32893514Smike#endif
32993514Smike
33093514Smike#ifndef _IN_ADDR_T_DECLARED
33193514Smiketypedef	uint32_t		in_addr_t;
33293514Smike#define	_IN_ADDR_T_DECLARED
33393514Smike#endif
33493514Smike
33593514Smike#ifndef _IN_PORT_T_DECLARED
33693514Smiketypedef	uint16_t		in_port_t;
33793514Smike#define	_IN_PORT_T_DECLARED
33893514Smike#endif
33993514Smike
34095099Smike#ifdef _BSD_SA_FAMILY_T_
34195099Smiketypedef	_BSD_SA_FAMILY_T_	sa_family_t;
34295099Smike#undef _BSD_SA_FAMILY_T_
34395099Smike#endif
34495099Smike
34517541Speter/*
3461541Srgrimes * Internet address (a structure for historical reasons)
3471541Srgrimes */
34887158Smike#ifndef	_STRUCT_IN_ADDR_DECLARED
3491541Srgrimesstruct in_addr {
35074700Sume	in_addr_t s_addr;
3511541Srgrimes};
35287158Smike#define	_STRUCT_IN_ADDR_DECLARED
35387158Smike#endif
3541541Srgrimes
3551541Srgrimes/*
3561541Srgrimes * Definitions of bits in internet address integers.
3571541Srgrimes * On subnets, the decomposition of addresses to host and net parts
3581541Srgrimes * is done according to subnet mask, not the masks here.
3591541Srgrimes */
36035919Sjb#define	IN_CLASSA(i)		(((u_int32_t)(i) & 0x80000000) == 0)
3611541Srgrimes#define	IN_CLASSA_NET		0xff000000
3621541Srgrimes#define	IN_CLASSA_NSHIFT	24
3631541Srgrimes#define	IN_CLASSA_HOST		0x00ffffff
3641541Srgrimes#define	IN_CLASSA_MAX		128
3651541Srgrimes
36635919Sjb#define	IN_CLASSB(i)		(((u_int32_t)(i) & 0xc0000000) == 0x80000000)
3671541Srgrimes#define	IN_CLASSB_NET		0xffff0000
3681541Srgrimes#define	IN_CLASSB_NSHIFT	16
3691541Srgrimes#define	IN_CLASSB_HOST		0x0000ffff
3701541Srgrimes#define	IN_CLASSB_MAX		65536
3711541Srgrimes
37235919Sjb#define	IN_CLASSC(i)		(((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
3731541Srgrimes#define	IN_CLASSC_NET		0xffffff00
3741541Srgrimes#define	IN_CLASSC_NSHIFT	8
3751541Srgrimes#define	IN_CLASSC_HOST		0x000000ff
3761541Srgrimes
37735919Sjb#define	IN_CLASSD(i)		(((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
3781541Srgrimes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
3791541Srgrimes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
3801541Srgrimes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
3811541Srgrimes#define	IN_MULTICAST(i)		IN_CLASSD(i)
3821541Srgrimes
38335919Sjb#define	IN_EXPERIMENTAL(i)	(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
38435919Sjb#define	IN_BADCLASS(i)		(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
3851541Srgrimes
38635919Sjb#define	INADDR_LOOPBACK		(u_int32_t)0x7f000001
38755205Speter#ifndef _KERNEL
3881541Srgrimes#define	INADDR_NONE		0xffffffff		/* -1 return */
3891541Srgrimes#endif
3901541Srgrimes
39135919Sjb#define	INADDR_UNSPEC_GROUP	(u_int32_t)0xe0000000	/* 224.0.0.0 */
39235919Sjb#define	INADDR_ALLHOSTS_GROUP	(u_int32_t)0xe0000001	/* 224.0.0.1 */
39335919Sjb#define	INADDR_ALLRTRS_GROUP	(u_int32_t)0xe0000002	/* 224.0.0.2 */
39435919Sjb#define	INADDR_MAX_LOCAL_GROUP	(u_int32_t)0xe00000ff	/* 224.0.0.255 */
3951541Srgrimes
3961541Srgrimes#define	IN_LOOPBACKNET		127			/* official! */
3971541Srgrimes
3981541Srgrimes/*
3991541Srgrimes * Options for use with [gs]etsockopt at the IP level.
4001541Srgrimes * First word of comment is data type; bool is stored in int.
4011541Srgrimes */
4021541Srgrimes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
4031541Srgrimes#define	IP_HDRINCL		2    /* int; header is included with data */
4041541Srgrimes#define	IP_TOS			3    /* int; IP type of service and preced. */
4051541Srgrimes#define	IP_TTL			4    /* int; IP time to live */
4061541Srgrimes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
4071541Srgrimes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
4081541Srgrimes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
4091541Srgrimes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
4101541Srgrimes#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
4111541Srgrimes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
4121541Srgrimes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
4131541Srgrimes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
4141541Srgrimes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
4152531Swollman#define IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
4162531Swollman#define IP_RSVP_ON		15   /* enable RSVP in kernel */
4172531Swollman#define IP_RSVP_OFF		16   /* disable RSVP in kernel */
4189209Swollman#define IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
4199209Swollman#define IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
42014195Speter#define IP_PORTRANGE		19   /* int; range to choose for unspec port */
42119622Sfenner#define	IP_RECVIF		20   /* bool; receive reception if w/dgram */
42252904Sshin/* for IPSEC */
42352904Sshin#define	IP_IPSEC_POLICY		21   /* int; set/get security policy */
42452904Sshin#define	IP_FAITH		22   /* bool; accept FAITH'ed connections */
4251541Srgrimes
42652904Sshin#define	IP_FW_ADD     		50   /* add a firewall rule to chain */
42752904Sshin#define	IP_FW_DEL    		51   /* delete a firewall rule from chain */
42852904Sshin#define	IP_FW_FLUSH   		52   /* flush firewall rule chain */
42952904Sshin#define	IP_FW_ZERO    		53   /* clear single/all firewall counter(s) */
43052904Sshin#define	IP_FW_GET     		54   /* get entire firewall rule chain */
43152904Sshin#define	IP_FW_RESETLOG		55   /* reset logging counters */
43217758Ssos
43341793Sluigi#define	IP_DUMMYNET_CONFIGURE	60   /* add/configure a dummynet pipe */
43441793Sluigi#define	IP_DUMMYNET_DEL		61   /* delete a dummynet pipe from chain */
43541793Sluigi#define	IP_DUMMYNET_FLUSH	62   /* flush dummynet */
43641793Sluigi#define	IP_DUMMYNET_GET		64   /* get entire dummynet pipes */
43741793Sluigi
4381541Srgrimes/*
4391541Srgrimes * Defaults and limits for options
4401541Srgrimes */
4411541Srgrimes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
4421541Srgrimes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
4439209Swollman#define	IP_MAX_MEMBERSHIPS	20	/* per socket */
4441541Srgrimes
4451541Srgrimes/*
4461541Srgrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
4471541Srgrimes */
4481541Srgrimesstruct ip_mreq {
4491541Srgrimes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
4501541Srgrimes	struct	in_addr imr_interface;	/* local IP address of interface */
4511541Srgrimes};
4521541Srgrimes
4531541Srgrimes/*
45414195Speter * Argument for IP_PORTRANGE:
45514195Speter * - which range to search when port is unspecified at bind() or connect()
45614195Speter */
45714195Speter#define	IP_PORTRANGE_DEFAULT	0	/* default range */
45814195Speter#define	IP_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
45914195Speter#define	IP_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
46014195Speter
46114195Speter/*
4621541Srgrimes * Definitions for inet sysctl operations.
4631541Srgrimes *
4641541Srgrimes * Third level is protocol number.
4651541Srgrimes * Fourth level is desired variable within that protocol.
4661541Srgrimes */
46762587Sitojun#define	IPPROTO_MAXID	(IPPROTO_AH + 1)	/* don't list to IPPROTO_MAX */
4681541Srgrimes
4691541Srgrimes#define	CTL_IPPROTO_NAMES { \
4701541Srgrimes	{ "ip", CTLTYPE_NODE }, \
4711541Srgrimes	{ "icmp", CTLTYPE_NODE }, \
4721541Srgrimes	{ "igmp", CTLTYPE_NODE }, \
4731541Srgrimes	{ "ggp", CTLTYPE_NODE }, \
4741541Srgrimes	{ 0, 0 }, \
4751541Srgrimes	{ 0, 0 }, \
4761541Srgrimes	{ "tcp", CTLTYPE_NODE }, \
4771541Srgrimes	{ 0, 0 }, \
4781541Srgrimes	{ "egp", CTLTYPE_NODE }, \
4791541Srgrimes	{ 0, 0 }, \
4801541Srgrimes	{ 0, 0 }, \
4811541Srgrimes	{ 0, 0 }, \
4821541Srgrimes	{ "pup", CTLTYPE_NODE }, \
4831541Srgrimes	{ 0, 0 }, \
4841541Srgrimes	{ 0, 0 }, \
4851541Srgrimes	{ 0, 0 }, \
4861541Srgrimes	{ 0, 0 }, \
4871541Srgrimes	{ "udp", CTLTYPE_NODE }, \
4881541Srgrimes	{ 0, 0 }, \
4891541Srgrimes	{ 0, 0 }, \
4901541Srgrimes	{ 0, 0 }, \
4911541Srgrimes	{ 0, 0 }, \
4921541Srgrimes	{ "idp", CTLTYPE_NODE }, \
49362587Sitojun	{ 0, 0 }, \
49462587Sitojun	{ 0, 0 }, \
49562587Sitojun	{ 0, 0 }, \
49662587Sitojun	{ 0, 0 }, \
49762587Sitojun	{ 0, 0 }, \
49862587Sitojun	{ 0, 0 }, \
49962587Sitojun	{ 0, 0 }, \
50062587Sitojun	{ 0, 0 }, \
50162587Sitojun	{ 0, 0 }, \
50262587Sitojun	{ 0, 0 }, \
50362587Sitojun	{ 0, 0 }, \
50462587Sitojun	{ 0, 0 }, \
50562587Sitojun	{ 0, 0 }, \
50662587Sitojun	{ 0, 0 }, \
50762587Sitojun	{ 0, 0 }, \
50862587Sitojun	{ 0, 0 }, \
50962587Sitojun	{ 0, 0 }, \
51062587Sitojun	{ 0, 0 }, \
51162587Sitojun	{ 0, 0 }, \
51262587Sitojun	{ 0, 0 }, \
51362587Sitojun	{ 0, 0 }, \
51462587Sitojun	{ 0, 0 }, \
51562587Sitojun	{ 0, 0 }, \
51662587Sitojun	{ 0, 0 }, \
51762587Sitojun	{ 0, 0 }, \
51862587Sitojun	{ 0, 0 }, \
51962587Sitojun	{ 0, 0 }, \
52062587Sitojun	{ 0, 0 }, \
52162587Sitojun	{ "ipsec", CTLTYPE_NODE }, \
5221541Srgrimes}
5231541Srgrimes
5241541Srgrimes/*
5251541Srgrimes * Names for IP sysctl objects
5261541Srgrimes */
5271541Srgrimes#define	IPCTL_FORWARDING	1	/* act as router */
5281541Srgrimes#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
5291541Srgrimes#define	IPCTL_DEFTTL		3	/* default TTL */
5301541Srgrimes#ifdef notyet
5311541Srgrimes#define	IPCTL_DEFMTU		4	/* default MTU */
5321541Srgrimes#endif
5335109Swollman#define IPCTL_RTEXPIRE		5	/* cloned route expiration time */
5346399Swollman#define IPCTL_RTMINEXPIRE	6	/* min value for expiration time */
5356399Swollman#define IPCTL_RTMAXCACHE	7	/* trigger level for dynamic expire */
5367091Swollman#define	IPCTL_SOURCEROUTE	8	/* may perform source routes */
5379575Speter#define	IPCTL_DIRECTEDBROADCAST	9	/* may re-broadcast received packets */
53812003Swollman#define IPCTL_INTRQMAXLEN	10	/* max length of netisr queue */
53952904Sshin#define	IPCTL_INTRQDROPS	11	/* number of netisr q drops */
54029838Swollman#define	IPCTL_STATS		12	/* ipstat structure */
54133440Sguido#define	IPCTL_ACCEPTSOURCEROUTE	13	/* may accept source routed packets */
54252904Sshin#define	IPCTL_FASTFORWARDING	14	/* use fast IP forwarding code */
54355009Sshin#define	IPCTL_KEEPFAITH		15	/* FAITH IPv4->IPv6 translater ctl */
54452904Sshin#define	IPCTL_GIF_TTL		16	/* default TTL for gif encap packet */
54552904Sshin#define	IPCTL_MAXID		17
5461541Srgrimes
5471541Srgrimes#define	IPCTL_NAMES { \
5481541Srgrimes	{ 0, 0 }, \
5491541Srgrimes	{ "forwarding", CTLTYPE_INT }, \
5501541Srgrimes	{ "redirect", CTLTYPE_INT }, \
5511541Srgrimes	{ "ttl", CTLTYPE_INT }, \
5521541Srgrimes	{ "mtu", CTLTYPE_INT }, \
5535109Swollman	{ "rtexpire", CTLTYPE_INT }, \
5546399Swollman	{ "rtminexpire", CTLTYPE_INT }, \
5556399Swollman	{ "rtmaxcache", CTLTYPE_INT }, \
5567091Swollman	{ "sourceroute", CTLTYPE_INT }, \
5579575Speter 	{ "directed-broadcast", CTLTYPE_INT }, \
55812003Swollman	{ "intr-queue-maxlen", CTLTYPE_INT }, \
55912003Swollman	{ "intr-queue-drops", CTLTYPE_INT }, \
56029838Swollman	{ "stats", CTLTYPE_STRUCT }, \
56133440Sguido	{ "accept_sourceroute", CTLTYPE_INT }, \
56236192Sdg	{ "fastforwarding", CTLTYPE_INT }, \
5631541Srgrimes}
5641541Srgrimes
56595336Smike#endif /* __BSD_VISIBLE */
56695336Smike
56778243Speter#ifdef _KERNEL
56895336Smike
56978243Speterstruct ifnet; struct mbuf;	/* forward declarations for Standard C */
57078243Speter
57192723Salfredint	 in_broadcast(struct in_addr, struct ifnet *);
57292723Salfredint	 in_canforward(struct in_addr);
57392723Salfredint	 in_localaddr(struct in_addr);
57492723Salfredchar 	*inet_ntoa(struct in_addr); /* in libkern */
57592723Salfredchar	*inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */
5762169Spaul
57784101Sjlemon#define satosin(sa)	((struct sockaddr_in *)(sa))
57884101Sjlemon#define sintosa(sin)	((struct sockaddr *)(sin))
57984101Sjlemon#define ifatoia(ifa)	((struct in_ifaddr *)(ifa))
58084101Sjlemon
58195336Smike#endif /* _KERNEL */
58290868Smike
58395336Smike/* INET6 stuff */
58495336Smike#if __POSIX_VISIBLE >= 200112
58595336Smike#define	__KAME_NETINET_IN_H_INCLUDED_
58695336Smike#include <netinet6/in6.h>
58795336Smike#undef __KAME_NETINET_IN_H_INCLUDED_
58891959Smike#endif
58991959Smike
59095336Smike#endif /* !_NETINET_IN_H_*/
591