in.h revision 1541
1117395Skan/*
2117395Skan * Copyright (c) 1982, 1986, 1990, 1993
3169689Skan *	The Regents of the University of California.  All rights reserved.
4117395Skan *
5117395Skan * Redistribution and use in source and binary forms, with or without
6117395Skan * modification, are permitted provided that the following conditions
7117395Skan * are met:
8117395Skan * 1. Redistributions of source code must retain the above copyright
9117395Skan *    notice, this list of conditions and the following disclaimer.
10117395Skan * 2. Redistributions in binary form must reproduce the above copyright
11117395Skan *    notice, this list of conditions and the following disclaimer in the
12117395Skan *    documentation and/or other materials provided with the distribution.
13117395Skan * 3. All advertising materials mentioning features or use of this software
14117395Skan *    must display the following acknowledgement:
15117395Skan *	This product includes software developed by the University of
16117395Skan *	California, Berkeley and its contributors.
17117395Skan * 4. Neither the name of the University nor the names of its contributors
18117395Skan *    may be used to endorse or promote products derived from this software
19169689Skan *    without specific prior written permission.
20169689Skan *
21117395Skan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22117395Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23132718Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24132718Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25117395Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26117395Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27117395Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28117395Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29117395Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30117395Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31117395Skan * SUCH DAMAGE.
32117395Skan *
33169689Skan *	@(#)in.h	8.3 (Berkeley) 1/3/94
34169689Skan */
35169689Skan
36169689Skan/*
37169689Skan * Constants and structures defined by the internet system,
38169689Skan * Per RFC 790, September 1981, and numerous additions.
39169689Skan */
40132718Skan
41117395Skan/*
42117395Skan * Protocols
43117395Skan */
44117395Skan#define	IPPROTO_IP		0		/* dummy for IP */
45117395Skan#define	IPPROTO_ICMP		1		/* control message protocol */
46132718Skan#define	IPPROTO_IGMP		2		/* group mgmt protocol */
47117395Skan#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
48117395Skan#define	IPPROTO_TCP		6		/* tcp */
49117395Skan#define	IPPROTO_EGP		8		/* exterior gateway protocol */
50117395Skan#define	IPPROTO_PUP		12		/* pup */
51117395Skan#define	IPPROTO_UDP		17		/* user datagram protocol */
52117395Skan#define	IPPROTO_IDP		22		/* xns idp */
53117395Skan#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
54117395Skan#define	IPPROTO_EON		80		/* ISO cnlp */
55117395Skan#define	IPPROTO_ENCAP		98		/* encapsulation header */
56117395Skan
57169689Skan#define	IPPROTO_RAW		255		/* raw IP packet */
58117395Skan#define	IPPROTO_MAX		256
59117395Skan
60117395Skan
61117395Skan/*
62117395Skan * Local port number conventions:
63117395Skan * Ports < IPPORT_RESERVED are reserved for
64117395Skan * privileged processes (e.g. root).
65117395Skan * Ports > IPPORT_USERRESERVED are reserved
66117395Skan * for servers, not necessarily privileged.
67117395Skan */
68117395Skan#define	IPPORT_RESERVED		1024
69117395Skan#define	IPPORT_USERRESERVED	5000
70117395Skan
71117395Skan/*
72117395Skan * Internet address (a structure for historical reasons)
73117395Skan */
74117395Skanstruct in_addr {
75117395Skan	u_long s_addr;
76117395Skan};
77117395Skan
78117395Skan/*
79117395Skan * Definitions of bits in internet address integers.
80117395Skan * On subnets, the decomposition of addresses to host and net parts
81117395Skan * is done according to subnet mask, not the masks here.
82117395Skan */
83117395Skan#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
84117395Skan#define	IN_CLASSA_NET		0xff000000
85117395Skan#define	IN_CLASSA_NSHIFT	24
86117395Skan#define	IN_CLASSA_HOST		0x00ffffff
87117395Skan#define	IN_CLASSA_MAX		128
88117395Skan
89117395Skan#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
90169689Skan#define	IN_CLASSB_NET		0xffff0000
91169689Skan#define	IN_CLASSB_NSHIFT	16
92117395Skan#define	IN_CLASSB_HOST		0x0000ffff
93117395Skan#define	IN_CLASSB_MAX		65536
94169689Skan
95169689Skan#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
96169689Skan#define	IN_CLASSC_NET		0xffffff00
97169689Skan#define	IN_CLASSC_NSHIFT	8
98169689Skan#define	IN_CLASSC_HOST		0x000000ff
99169689Skan
100169689Skan#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
101117395Skan#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
102117395Skan#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
103117395Skan#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
104117395Skan#define	IN_MULTICAST(i)		IN_CLASSD(i)
105117395Skan
106117395Skan#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)
107117395Skan#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
108117395Skan
109117395Skan#define	INADDR_ANY		(u_long)0x00000000
110117395Skan#define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
111117395Skan#ifndef KERNEL
112117395Skan#define	INADDR_NONE		0xffffffff		/* -1 return */
113117395Skan#endif
114117395Skan
115117395Skan#define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
116117395Skan#define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */
117117395Skan#define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
118117395Skan
119117395Skan#define	IN_LOOPBACKNET		127			/* official! */
120117395Skan
121169689Skan/*
122169689Skan * Socket address, internet style.
123117395Skan */
124117395Skanstruct sockaddr_in {
125117395Skan	u_char	sin_len;
126117395Skan	u_char	sin_family;
127169689Skan	u_short	sin_port;
128169689Skan	struct	in_addr sin_addr;
129117395Skan	char	sin_zero[8];
130117395Skan};
131117395Skan
132117395Skan/*
133117395Skan * Structure used to describe IP options.
134117395Skan * Used to store options internally, to pass them to a process,
135117395Skan * or to restore options retrieved earlier.
136117395Skan * The ip_dst is used for the first-hop gateway when using a source route
137117395Skan * (this gets put into the header proper).
138117395Skan */
139117395Skanstruct ip_opts {
140117395Skan	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
141117395Skan	char	ip_opts[40];		/* actually variable in size */
142117395Skan};
143117395Skan
144169689Skan/*
145169689Skan * Options for use with [gs]etsockopt at the IP level.
146117395Skan * First word of comment is data type; bool is stored in int.
147117395Skan */
148132718Skan#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
149132718Skan#define	IP_HDRINCL		2    /* int; header is included with data */
150117395Skan#define	IP_TOS			3    /* int; IP type of service and preced. */
151117395Skan#define	IP_TTL			4    /* int; IP time to live */
152117395Skan#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
153117395Skan#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
154132718Skan#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
155132718Skan#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
156132718Skan#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
157132718Skan#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
158132718Skan#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
159132718Skan#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
160132718Skan#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
161169689Skan
162169689Skan/*
163132718Skan * Defaults and limits for options
164132718Skan */
165132718Skan#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
166132718Skan#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
167132718Skan#define	IP_MAX_MEMBERSHIPS	20	/* per socket; must fit in one mbuf */
168132718Skan
169132718Skan/*
170132718Skan * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
171117395Skan */
172117395Skanstruct ip_mreq {
173117395Skan	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
174117395Skan	struct	in_addr imr_interface;	/* local IP address of interface */
175117395Skan};
176117395Skan
177117395Skan/*
178169689Skan * Definitions for inet sysctl operations.
179169689Skan *
180117395Skan * Third level is protocol number.
181117395Skan * Fourth level is desired variable within that protocol.
182117395Skan */
183132718Skan#define	IPPROTO_MAXID	(IPPROTO_IDP + 1)	/* don't list to IPPROTO_MAX */
184132718Skan
185132718Skan#define	CTL_IPPROTO_NAMES { \
186132718Skan	{ "ip", CTLTYPE_NODE }, \
187132718Skan	{ "icmp", CTLTYPE_NODE }, \
188132718Skan	{ "igmp", CTLTYPE_NODE }, \
189132718Skan	{ "ggp", CTLTYPE_NODE }, \
190132718Skan	{ 0, 0 }, \
191132718Skan	{ 0, 0 }, \
192132718Skan	{ "tcp", CTLTYPE_NODE }, \
193132718Skan	{ 0, 0 }, \
194132718Skan	{ "egp", CTLTYPE_NODE }, \
195169689Skan	{ 0, 0 }, \
196169689Skan	{ 0, 0 }, \
197132718Skan	{ 0, 0 }, \
198132718Skan	{ "pup", CTLTYPE_NODE }, \
199132718Skan	{ 0, 0 }, \
200117395Skan	{ 0, 0 }, \
201117395Skan	{ 0, 0 }, \
202117395Skan	{ 0, 0 }, \
203117395Skan	{ "udp", CTLTYPE_NODE }, \
204117395Skan	{ 0, 0 }, \
205117395Skan	{ 0, 0 }, \
206117395Skan	{ 0, 0 }, \
207117395Skan	{ 0, 0 }, \
208117395Skan	{ "idp", CTLTYPE_NODE }, \
209117395Skan}
210117395Skan
211117395Skan/*
212117395Skan * Names for IP sysctl objects
213117395Skan */
214117395Skan#define	IPCTL_FORWARDING	1	/* act as router */
215117395Skan#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
216117395Skan#define	IPCTL_DEFTTL		3	/* default TTL */
217117395Skan#ifdef notyet
218117395Skan#define	IPCTL_DEFMTU		4	/* default MTU */
219117395Skan#endif
220117395Skan#define	IPCTL_MAXID		5
221117395Skan
222169689Skan#define	IPCTL_NAMES { \
223169689Skan	{ 0, 0 }, \
224169689Skan	{ "forwarding", CTLTYPE_INT }, \
225117395Skan	{ "redirect", CTLTYPE_INT }, \
226117395Skan	{ "ttl", CTLTYPE_INT }, \
227117395Skan	{ "mtu", CTLTYPE_INT }, \
228117395Skan}
229117395Skan
230117395Skan
231117395Skan#ifdef KERNEL
232117395Skanint	 in_broadcast __P((struct in_addr, struct ifnet *));
233117395Skanint	 in_canforward __P((struct in_addr));
234117395Skanint	 in_cksum __P((struct mbuf *, int));
235117395Skanint	 in_localaddr __P((struct in_addr));
236117395Skanu_long	 in_netof __P((struct in_addr));
237117395Skanvoid	 in_socktrim __P((struct sockaddr_in *));
238117395Skan#endif
239117395Skan