xref: /original-bsd/sys/netinet/in.h (revision 2f46dd9e)
1 /*
2  * Copyright (c) 1982,1986,1990,1993 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)in.h	7.14 (Berkeley) 04/18/93
8  */
9 
10 /*
11  * Constants and structures defined by the internet system,
12  * Per RFC 790, September 1981.
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 per-packet options */
123 
124 #define	IP_MULTICAST_IF		2 /* in_addr; set/get IP multicast interface */
125 #define	IP_MULTICAST_TTL	3 /* u_char; set/get IP multicast timetolive */
126 #define	IP_MULTICAST_LOOP	4 /* u_char; set/get IP multicast loopback */
127 #define	IP_ADD_MEMBERSHIP	5 /* ip_mreq; add an IP group membership */
128 #define	IP_DROP_MEMBERSHIP	6 /* ip_mreq; drop an IP group membership */
129 
130 
131 #define	IP_HDRINCL	7	/* int; header is included with data (raw) */
132 #define	IP_TOS		8	/* int; IP type of service and precedence */
133 #define	IP_TTL		9	/* int; IP time to live */
134 #define	IP_RECVOPTS	10	/* bool; receive all IP options w/datagram */
135 #define	IP_RECVRETOPTS	11	/* bool; receive IP options for response */
136 #define	IP_RECVDSTADDR	12	/* bool; receive IP dst addr w/datagram */
137 #define	IP_RETOPTS	13	/* ip_opts; set/get IP per-packet 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 */
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 struct	in_addr in_makeaddr();
207 u_long	in_netof(), in_lnaof();
208 #endif
209