xref: /original-bsd/sys/netinet/in.h (revision 333da485)
1 /*
2  * Copyright (c) 1982, 1986, 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)in.h	8.3 (Berkeley) 01/03/94
8  */
9 
10 /*
11  * Constants and structures defined by the internet system,
12  * Per RFC 790, September 1981, and numerous additions.
13  */
14 
15 /*
16  * Protocols
17  */
18 #define	IPPROTO_IP		0		/* dummy for IP */
19 #define	IPPROTO_ICMP		1		/* control message protocol */
20 #define	IPPROTO_IGMP		2		/* group mgmt protocol */
21 #define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
22 #define	IPPROTO_TCP		6		/* tcp */
23 #define	IPPROTO_EGP		8		/* exterior gateway protocol */
24 #define	IPPROTO_PUP		12		/* pup */
25 #define	IPPROTO_UDP		17		/* user datagram protocol */
26 #define	IPPROTO_IDP		22		/* xns idp */
27 #define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
28 #define	IPPROTO_EON		80		/* ISO cnlp */
29 #define	IPPROTO_ENCAP		98		/* encapsulation header */
30 
31 #define	IPPROTO_RAW		255		/* raw IP packet */
32 #define	IPPROTO_MAX		256
33 
34 
35 /*
36  * Local port number conventions:
37  * Ports < IPPORT_RESERVED are reserved for
38  * privileged processes (e.g. root).
39  * Ports > IPPORT_USERRESERVED are reserved
40  * for servers, not necessarily privileged.
41  */
42 #define	IPPORT_RESERVED		1024
43 #define	IPPORT_USERRESERVED	5000
44 
45 /*
46  * Internet address (a structure for historical reasons)
47  */
48 struct in_addr {
49 	u_long s_addr;
50 };
51 
52 /*
53  * Definitions of bits in internet address integers.
54  * On subnets, the decomposition of addresses to host and net parts
55  * is done according to subnet mask, not the masks here.
56  */
57 #define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
58 #define	IN_CLASSA_NET		0xff000000
59 #define	IN_CLASSA_NSHIFT	24
60 #define	IN_CLASSA_HOST		0x00ffffff
61 #define	IN_CLASSA_MAX		128
62 
63 #define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
64 #define	IN_CLASSB_NET		0xffff0000
65 #define	IN_CLASSB_NSHIFT	16
66 #define	IN_CLASSB_HOST		0x0000ffff
67 #define	IN_CLASSB_MAX		65536
68 
69 #define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
70 #define	IN_CLASSC_NET		0xffffff00
71 #define	IN_CLASSC_NSHIFT	8
72 #define	IN_CLASSC_HOST		0x000000ff
73 
74 #define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
75 #define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
76 #define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
77 #define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
78 #define	IN_MULTICAST(i)		IN_CLASSD(i)
79 
80 #define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)
81 #define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
82 
83 #define	INADDR_ANY		(u_long)0x00000000
84 #define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
85 #ifndef KERNEL
86 #define	INADDR_NONE		0xffffffff		/* -1 return */
87 #endif
88 
89 #define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
90 #define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */
91 #define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
92 
93 #define	IN_LOOPBACKNET		127			/* official! */
94 
95 /*
96  * Socket address, internet style.
97  */
98 struct sockaddr_in {
99 	u_char	sin_len;
100 	u_char	sin_family;
101 	u_short	sin_port;
102 	struct	in_addr sin_addr;
103 	char	sin_zero[8];
104 };
105 
106 /*
107  * Structure used to describe IP options.
108  * Used to store options internally, to pass them to a process,
109  * or to restore options retrieved earlier.
110  * The ip_dst is used for the first-hop gateway when using a source route
111  * (this gets put into the header proper).
112  */
113 struct ip_opts {
114 	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
115 	char	ip_opts[40];		/* actually variable in size */
116 };
117 
118 /*
119  * Options for use with [gs]etsockopt at the IP level.
120  * First word of comment is data type; bool is stored in int.
121  */
122 #define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
123 #define	IP_HDRINCL		2    /* int; header is included with data */
124 #define	IP_TOS			3    /* int; IP type of service and preced. */
125 #define	IP_TTL			4    /* int; IP time to live */
126 #define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
127 #define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
128 #define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
129 #define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
130 #define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
131 #define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
132 #define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
133 #define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
134 #define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
135 
136 /*
137  * Defaults and limits for options
138  */
139 #define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
140 #define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
141 #define	IP_MAX_MEMBERSHIPS	20	/* per socket; must fit in one mbuf */
142 
143 /*
144  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
145  */
146 struct ip_mreq {
147 	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
148 	struct	in_addr imr_interface;	/* local IP address of interface */
149 };
150 
151 /*
152  * Definitions for inet sysctl operations.
153  *
154  * Third level is protocol number.
155  * Fourth level is desired variable within that protocol.
156  */
157 #define	IPPROTO_MAXID	(IPPROTO_IDP + 1)	/* don't list to IPPROTO_MAX */
158 
159 #define	CTL_IPPROTO_NAMES { \
160 	{ "ip", CTLTYPE_NODE }, \
161 	{ "icmp", CTLTYPE_NODE }, \
162 	{ "igmp", CTLTYPE_NODE }, \
163 	{ "ggp", CTLTYPE_NODE }, \
164 	{ 0, 0 }, \
165 	{ 0, 0 }, \
166 	{ "tcp", CTLTYPE_NODE }, \
167 	{ 0, 0 }, \
168 	{ "egp", CTLTYPE_NODE }, \
169 	{ 0, 0 }, \
170 	{ 0, 0 }, \
171 	{ 0, 0 }, \
172 	{ "pup", CTLTYPE_NODE }, \
173 	{ 0, 0 }, \
174 	{ 0, 0 }, \
175 	{ 0, 0 }, \
176 	{ 0, 0 }, \
177 	{ "udp", CTLTYPE_NODE }, \
178 	{ 0, 0 }, \
179 	{ 0, 0 }, \
180 	{ 0, 0 }, \
181 	{ 0, 0 }, \
182 	{ "idp", CTLTYPE_NODE }, \
183 }
184 
185 /*
186  * Names for IP sysctl objects
187  */
188 #define	IPCTL_FORWARDING	1	/* act as router */
189 #define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
190 #define	IPCTL_DEFTTL		3	/* default TTL */
191 #ifdef notyet
192 #define	IPCTL_DEFMTU		4	/* default MTU */
193 #endif
194 #define	IPCTL_MAXID		5
195 
196 #define	IPCTL_NAMES { \
197 	{ 0, 0 }, \
198 	{ "forwarding", CTLTYPE_INT }, \
199 	{ "redirect", CTLTYPE_INT }, \
200 	{ "ttl", CTLTYPE_INT }, \
201 	{ "mtu", CTLTYPE_INT }, \
202 }
203 
204 
205 #ifdef KERNEL
206 int	 in_broadcast __P((struct in_addr, struct ifnet *));
207 int	 in_canforward __P((struct in_addr));
208 int	 in_cksum __P((struct mbuf *, int));
209 int	 in_localaddr __P((struct in_addr));
210 u_long	 in_netof __P((struct in_addr));
211 void	 in_socktrim __P((struct sockaddr_in *));
212 #endif
213