Watt-32 tcp/ip  2.2 dev-rel.10
in.h
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 1982, 1986, 1990, 1993
7  * The Regents of the University of California. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  * must display the following acknowledgement:
19  * This product includes software developed by the University of
20  * California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  * may be used to endorse or promote products derived from this software
23  * without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * @(#)in.h 8.3 (Berkeley) 1/3/94
38  * $Id: in.h,v 1.22.2.1 1996/11/11 23:40:37 phk Exp $
39  */
40 
41 #ifndef __NETINET_IN_H
42 #define __NETINET_IN_H
43 
44 #ifndef __SYS_SOCKET_H
45 #include <sys/socket.h>
46 #endif
47 
48 /*
49  * Constants and structures defined by the internet system,
50  * Per RFC 790, September 1981, and numerous additions.
51  */
52 
53 /*
54  * Protocols
55  */
56 #define IPPROTO_IP 0 /* dummy for IP */
57 #define IPPROTO_ICMP 1 /* control message protocol */
58 #define IPPROTO_IGMP 2 /* group mgmt protocol */
59 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
60 #define IPPROTO_IPIP 4 /* IP encapsulation in IP */
61 #define IPPROTO_TCP 6 /* tcp */
62 #define IPPROTO_EGP 8 /* exterior gateway protocol */
63 #define IPPROTO_IGRP 9 /* interior gw routing protocol */
64 #define IPPROTO_PUP 12 /* pup */
65 #define IPPROTO_UDP 17 /* user datagram protocol */
66 #define IPPROTO_IDP 22 /* xns idp */
67 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
68 #define IPPROTO_XTP 36 /* eXpress Transfer Protocol */
69 #define IPPROTO_RSVP 46 /* resource reservation */
70 #define IPPROTO_ESP 50
71 #define IPPROTO_AH 51 /* authenticate header */
72 #define IPPROTO_ICMPV6 58 /* ICMP v6 */
73 #define IPPROTO_NONE 59
74 #define IPPROTO_EON 80 /* ISO cnlp */
75 #define IPPROTO_ENCAP 98 /* encapsulation header */
76 #define IPPROTO_PIM 103
77 #define IPPROTO_VRRP 112
78 #define IPPROTO_SCTP 132
79 
80 #define IPPROTO_DIVERT 254 /* divert pseudo-protocol */
81 #define IPPROTO_RAW 255 /* raw IP packet */
82 #define IPPROTO_MAX 256
83 
84 
85 /*
86  * Local port number conventions:
87  *
88  * When a user does a bind(2) or connect(2) with a port number of zero,
89  * a non-conflicting local port address is chosen.
90  * The default range is IPPORT_RESERVED through
91  * IPPORT_USERRESERVED, although that is settable by sysctl.
92  *
93  * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
94  * default assignment range.
95  *
96  * The value IP_PORTRANGE_DEFAULT causes the default behavior.
97  *
98  * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
99  * into the "high" range. These are reserved for client outbound connections
100  * which do not want to be filtered by any firewalls.
101  *
102  * The value IP_PORTRANGE_LOW changes the range to the "low" are
103  * that is (by convention) restricted to privileged processes. This
104  * convention is based on "vouchsafe" principles only. It is only secure
105  * if you trust the remote host to restrict these ports.
106  *
107  * The default range of ports and the high range can be changed by
108  * sysctl(3). (net.inet.ip.port{hi,low}{first,last}_auto)
109  *
110  * Changing those values has bad security implications if you are
111  * using a a stateless firewall that is allowing packets outside of that
112  * range in order to allow transparent outgoing connections.
113  *
114  * Such a firewall configuration will generally depend on the use of these
115  * default values. If you change them, you may find your Security
116  * Administrator looking for you with a heavy object.
117  */
118 
119 /*
120  * Ports < IPPORT_RESERVED are reserved for
121  * privileged processes (e.g. root). (IP_PORTRANGE_LOW)
122  * Ports > IPPORT_USERRESERVED are reserved
123  * for servers, not necessarily privileged. (IP_PORTRANGE_DEFAULT)
124  */
125 #define IPPORT_RESERVED 1024
126 #define IPPORT_USERRESERVED 5000
127 
128 /*
129  * Default local port range to use by setting IP_PORTRANGE_HIGH
130  */
131 #define IPPORT_HIFIRSTAUTO 40000
132 #define IPPORT_HILASTAUTO 44999
133 
134 /*
135  * Scanning for a free reserved port return a value below IPPORT_RESERVED,
136  * but higher than IPPORT_RESERVEDSTART. Traditionally the start value was
137  * 512, but that conflicts with some well-known-services that firewalls may
138  * have a fit if we use.
139  */
140 #define IPPORT_RESERVEDSTART 600
141 
142 
143 /*
144  * Internet address (a structure for historical reasons)
145  */
146 struct in_addr {
147  u_long s_addr;
148  };
149 /*
150  * For IPv6 from RFC2133
151  */
152 #if 1
153 struct in6_addr {
154  u_int8_t s6_addr[16];
155  };
156 #else
157 struct in6_addr {
158  union {
159  u_char _S6_u8[16];
160  u_short _S6_u16[8];
161  u_long _S6_u32[4];
162  } _S6_un;
163  };
164  /* s6_addr is the standard name */
165  #define s6_addr _S6_un._S6_u8
166 #endif
167 
168 /*
169  * Definitions of bits in internet address integers.
170  * On subnets, the decomposition of addresses to host and net parts
171  * is done according to subnet mask, not the masks here.
172  */
173 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
174 #define IN_CLASSA_NET 0xff000000
175 #define IN_CLASSA_NSHIFT 24
176 #define IN_CLASSA_HOST 0x00ffffff
177 #define IN_CLASSA_MAX 128
178 
179 #define IN_CLASSB(i) (((long)(i) & 0xC0000000) == 0x80000000)
180 #define IN_CLASSB_NET 0xffff0000
181 #define IN_CLASSB_NSHIFT 16
182 #define IN_CLASSB_HOST 0x0000ffff
183 #define IN_CLASSB_MAX 65536
184 
185 #define IN_CLASSC(i) (((long)(i) & 0xE0000000) == 0xC0000000)
186 #define IN_CLASSC_NET 0xffffff00
187 #define IN_CLASSC_NSHIFT 8
188 #define IN_CLASSC_HOST 0x000000ff
189 
190 #define IN_CLASSD(i) (((long)(i) & 0xF0000000) == 0xE0000000)
191 #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
192 #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
193 #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
194 #define IN_MULTICAST(i) IN_CLASSD(i)
195 
196 #define IN_EXPERIMENTAL(i) (((long)(i) & 0xF0000000) == 0xF0000000)
197 #define IN_BADCLASS(i) (((long)(i) & 0xF0000000) == 0xF0000000)
198 
199 #define INADDR_ANY (u_long)0x00000000
200 #define INADDR_BROADCAST (u_long)0xFFFFFFFF /* must be masked */
201 #define INADDR_LOOPBACK (u_long)0x7F000001 /* 127.0.0.1 */
202 #define INADDR_NONE 0xFFFFFFFF /* -1 return */
203 
204 #define INADDR_UNSPEC_GROUP (u_long)0xE0000000 /* 224.0.0.0 */
205 #define INADDR_ALLHOSTS_GROUP (u_long)0xE0000001 /* 224.0.0.1 */
206 #define INADDR_ALLRTRS_GROUP (u_long)0xE0000002 /* 224.0.0.2 */
207 #define INADDR_MAX_LOCAL_GROUP (u_long)0xE00000FF /* 224.0.0.255 */
208 
209 #define IN_LOOPBACKNET 127 /* official! */
210 
211 W32_DATA const struct in6_addr in6addr_any; /* :: */
212 W32_DATA const struct in6_addr in6addr_loopback; /* ::1 */
213 
214 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
215 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
216 
217 #define INET_ADDRSTRLEN 16
218 #define INET6_ADDRSTRLEN 46
219 
220 
221 /*
222  * Socket address, internet style.
223  */
224 struct sockaddr_in {
225  u_short sin_family;
226  u_short sin_port;
227  struct in_addr sin_addr;
228  char sin_zero[8];
229  };
230 
231 struct sockaddr_in6 {
232  u_int16_t sin6_family;
233  u_int16_t sin6_port;
234  u_int32_t sin6_flowinfo;
235  struct in6_addr sin6_addr;
236  u_int32_t sin6_scope_id; /* IPv6 scope-id */
237  };
238 
239 /*
240  * Stolen from winsock2.h (hope this is portable)
241  * Portable IPv6/IPv4 version of sockaddr.
242  * Uses padding to force 8 byte alignment
243  * and maximum size of 128 bytes
244  */
246  u_short ss_family;
247  u_short ss_len; /* !! added for BSD progs, gv Nov-2003 */
248  char __ss_pad1[6]; /* pad to 8 */
249  long __ss_align1, __ssalign2; /* force alignment */
250  char __ss_pad2[110]; /* pad to 128 */
251  };
252 
253 
254 /* IPv6 multicast request. */
255 struct ipv6_mreq {
256  /* IPv6 multicast address of group */
257  struct in6_addr ipv6mr_multiaddr;
258 
259  /* local interface */
260  unsigned long ipv6mr_interface;
261  };
262 
263 /*
264  * Structure used to describe IP options.
265  * Used to store options internally, to pass them to a process,
266  * or to restore options retrieved earlier.
267  * The ip_dst is used for the first-hop gateway when using a source route
268  * (this gets put into the header proper).
269  */
270 struct ip_opts {
271  struct in_addr ip_dst; /* first hop, 0 w/o src rt */
272  char IP_opts[40]; /* actually variable in size */
273  };
274 
275 /*
276  * Options for use with [gs]etsockopt at the IP level.
277  * First word of comment is data type; bool is stored in int.
278  */
279 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */
280 #define IP_HDRINCL 2 /* int; header is included with data */
281 #define IP_TOS 3 /* int; IP type of service and preced. */
282 #define IP_TTL 4 /* int; IP time to live */
283 #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */
284 #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */
285 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */
286 #define IP_RETOPTS 8 /* ip_opts; set/get IP options */
287 #define IP_MULTICAST_IF 9 /* u_char; set/get IP multicast i/f */
288 #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
289 #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */
290 #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
291 #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
292 #define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */
293 #define IP_RSVP_ON 15 /* enable RSVP in kernel */
294 #define IP_RSVP_OFF 16 /* disable RSVP in kernel */
295 #define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */
296 #define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */
297 #define IP_PORTRANGE 19 /* int; range to choose for unspec port */
298 #define IP_RECVIF 20 /* bool; receive reception if w/dgram */
299 
300 #define IP_FW_ADD 50 /* add a firewall rule to chain */
301 #define IP_FW_DEL 51 /* delete a firewall rule from chain */
302 #define IP_FW_FLUSH 52 /* flush firewall rule chain */
303 #define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */
304 #define IP_FW_GET 54 /* get entire firewall rule chain */
305 #define IP_NAT 55 /* set/get NAT opts */
306 
307 /*
308  * Defaults and limits for options
309  */
310 #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
311 #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
312 #define IP_MAX_MEMBERSHIPS 20 /* per socket */
313 
314 /*
315  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
316  */
317 struct ip_mreq {
318  struct in_addr imr_multiaddr; /* IP multicast address of group */
319  struct in_addr imr_interface; /* local IP address of interface */
320 };
321 
322 /*
323  * Argument for IP_PORTRANGE:
324  * - which range to search when port is unspecified at bind() or connect()
325  */
326 #define IP_PORTRANGE_DEFAULT 0 /* default range */
327 #define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
328 #define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
329 
330 /*
331  * Definitions for inet sysctl operations.
332  *
333  * Third level is protocol number.
334  * Fourth level is desired variable within that protocol.
335  */
336 #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */
337 
338 #define CTL_IPPROTO_NAMES { \
339  { "ip", CTLTYPE_NODE }, \
340  { "icmp", CTLTYPE_NODE }, \
341  { "igmp", CTLTYPE_NODE }, \
342  { "ggp", CTLTYPE_NODE }, \
343  { 0, 0 }, \
344  { 0, 0 }, \
345  { "tcp", CTLTYPE_NODE }, \
346  { 0, 0 }, \
347  { "egp", CTLTYPE_NODE }, \
348  { 0, 0 }, \
349  { 0, 0 }, \
350  { 0, 0 }, \
351  { "pup", CTLTYPE_NODE }, \
352  { 0, 0 }, \
353  { 0, 0 }, \
354  { 0, 0 }, \
355  { 0, 0 }, \
356  { "udp", CTLTYPE_NODE }, \
357  { 0, 0 }, \
358  { 0, 0 }, \
359  { 0, 0 }, \
360  { 0, 0 }, \
361  { "idp", CTLTYPE_NODE }, \
362 }
363 
364 /*
365  * Names for IP sysctl objects
366  */
367 #define IPCTL_FORWARDING 1 /* act as router */
368 #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */
369 #define IPCTL_DEFTTL 3 /* default TTL */
370 #define IPCTL_DEFMTU 4 /* default MTU */
371 #define IPCTL_RTEXPIRE 5 /* cloned route expiration time */
372 #define IPCTL_RTMINEXPIRE 6 /* min value for expiration time */
373 #define IPCTL_RTMAXCACHE 7 /* trigger level for dynamic expire */
374 #define IPCTL_SOURCEROUTE 8 /* may perform source routes */
375 #define IPCTL_DIRECTEDBROADCAST 9 /* may re-broadcast received packets */
376 #define IPCTL_INTRQMAXLEN 10 /* max length of netisr queue */
377 #define IPCTL_INTRQDROPS 11 /* number of netisr q drops */
378 #define IPCTL_MAXID 12
379 
380 #define IPCTL_NAMES { \
381  { 0, 0 }, \
382  { "forwarding", CTLTYPE_INT }, \
383  { "redirect", CTLTYPE_INT }, \
384  { "ttl", CTLTYPE_INT }, \
385  { "mtu", CTLTYPE_INT }, \
386  { "rtexpire", CTLTYPE_INT }, \
387  { "rtminexpire", CTLTYPE_INT }, \
388  { "rtmaxcache", CTLTYPE_INT }, \
389  { "sourceroute", CTLTYPE_INT }, \
390  { "directed-broadcast", CTLTYPE_INT }, \
391  { "intr-queue-maxlen", CTLTYPE_INT }, \
392  { "intr-queue-drops", CTLTYPE_INT }, \
393 }
394 
395 
396 /*
397  * IPv6 address macros
398  */
399 #define IN6_IS_ADDR_UNSPECIFIED(a) \
400  (((u_int32_t*)(a))[0] == 0 \
401  && ((u_int32_t*)(a))[1] == 0 \
402  && ((u_int32_t*)(a))[2] == 0 \
403  && ((u_int32_t*)(a))[3] == 0)
404 
405 #define IN6_IS_ADDR_LOOPBACK(a) \
406  (((u_int32_t*)(a))[0] == 0 \
407  && ((u_int32_t*)(a))[1] == 0 \
408  && ((u_int32_t*)(a))[2] == 0 \
409  && ((u_int32_t*)(a))[3] == htonl (1))
410 
411 #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t*) (a))[0] == 0xff)
412 
413 #define IN6_IS_ADDR_LINKLOCAL(a) \
414  ((((u_int32_t*)(a))[0] & htonl(0xffc00000)) == htonl(0xfe800000))
415 
416 #define IN6_IS_ADDR_SITELOCAL(a) \
417  ((((u_int32_t*)(a))[0] & htonl(0xffc00000)) == htonl(0xfec00000))
418 
419 #define IN6_IS_ADDR_V4MAPPED(a) \
420  ((((u_int32_t*)(a))[0] == 0) \
421  && (((u_int32_t*)(a))[1] == 0) \
422  && (((u_int32_t*)(a))[2] == htonl(0xffff)))
423 
424 #define IN6_IS_ADDR_V4COMPAT(a) \
425  ((((u_int32_t*)(a))[0] == 0) \
426  && (((u_int32_t*)(a))[1] == 0) \
427  && (((u_int32_t*)(a))[2] == 0) \
428  && (ntohl(((u_int32_t*)(a))[3]) > 1))
429 
430 #define IN6_ARE_ADDR_EQUAL(a,b) \
431  (memcmp ((void*)a, (void*)b, sizeof(struct in6_addr)) == 0)
432 
433 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
434  (IN6_IS_ADDR_MULTICAST(a) && ((((u_int8_t*)(a))[1] & 0xf) == 0x1))
435 
436 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
437  (IN6_IS_ADDR_MULTICAST(a) && ((((u_int8_t*)(a))[1] & 0xf) == 0x2))
438 
439 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
440  (IN6_IS_ADDR_MULTICAST(a) && ((((u_int8_t*)(a))[1] & 0xf) == 0x5))
441 
442 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
443  (IN6_IS_ADDR_MULTICAST(a) && ((((u_int8_t*)(a))[1] & 0xf) == 0x8))
444 
445 #define IN6_IS_ADDR_MC_GLOBAL(a) \
446  (IN6_IS_ADDR_MULTICAST(a) && ((((u_int8_t*)(a))[1] & 0xf) == 0xe))
447 
448 #endif /* __NETINET_IN_H */
449 
Definition: in.h:270
Definition: in.h:317
Definition: in.h:153
Definition: in.h:146
Definition: in.h:255