1 /* Copyright (C) 1991-2001, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #define _NETINET_IN_H 1
24 #include <sys/socket.h>
25 #include <bits/types.h>
30 /* Standard well-defined IP protocols. */
33 IPPROTO_IP
= 0, /* Dummy protocol for TCP. */
34 #define IPPROTO_IP IPPROTO_IP
35 IPPROTO_HOPOPTS
= 0, /* IPv6 Hop-by-Hop options. */
36 #define IPPROTO_HOPOPTS IPPROTO_HOPOPTS
37 IPPROTO_ICMP
= 1, /* Internet Control Message Protocol. */
38 #define IPPROTO_ICMP IPPROTO_ICMP
39 IPPROTO_IGMP
= 2, /* Internet Group Management Protocol. */
40 #define IPPROTO_IGMP IPPROTO_IGMP
41 IPPROTO_IPIP
= 4, /* IPIP tunnels (older KA9Q tunnels use 94). */
42 #define IPPROTO_IPIP IPPROTO_IPIP
43 IPPROTO_TCP
= 6, /* Transmission Control Protocol. */
44 #define IPPROTO_TCP IPPROTO_TCP
45 IPPROTO_EGP
= 8, /* Exterior Gateway Protocol. */
46 #define IPPROTO_EGP IPPROTO_EGP
47 IPPROTO_PUP
= 12, /* PUP protocol. */
48 #define IPPROTO_PUP IPPROTO_PUP
49 IPPROTO_UDP
= 17, /* User Datagram Protocol. */
50 #define IPPROTO_UDP IPPROTO_UDP
51 IPPROTO_IDP
= 22, /* XNS IDP protocol. */
52 #define IPPROTO_IDP IPPROTO_IDP
53 IPPROTO_TP
= 29, /* SO Transport Protocol Class 4. */
54 #define IPPROTO_TP IPPROTO_TP
55 IPPROTO_IPV6
= 41, /* IPv6 header. */
56 #define IPPROTO_IPV6 IPPROTO_IPV6
57 IPPROTO_ROUTING
= 43, /* IPv6 routing header. */
58 #define IPPROTO_ROUTING IPPROTO_ROUTING
59 IPPROTO_FRAGMENT
= 44, /* IPv6 fragmentation header. */
60 #define IPPROTO_FRAGMENT IPPROTO_FRAGMENT
61 IPPROTO_RSVP
= 46, /* Reservation Protocol. */
62 #define IPPROTO_RSVP IPPROTO_RSVP
63 IPPROTO_GRE
= 47, /* General Routing Encapsulation. */
64 #define IPPROTO_GRE IPPROTO_GRE
65 IPPROTO_ESP
= 50, /* encapsulating security payload. */
66 #define IPPROTO_ESP IPPROTO_ESP
67 IPPROTO_AH
= 51, /* authentication header. */
68 #define IPPROTO_AH IPPROTO_AH
69 IPPROTO_ICMPV6
= 58, /* ICMPv6. */
70 #define IPPROTO_ICMPV6 IPPROTO_ICMPV6
71 IPPROTO_NONE
= 59, /* IPv6 no next header. */
72 #define IPPROTO_NONE IPPROTO_NONE
73 IPPROTO_DSTOPTS
= 60, /* IPv6 destination options. */
74 #define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
75 IPPROTO_MTP
= 92, /* Multicast Transport Protocol. */
76 #define IPPROTO_MTP IPPROTO_MTP
77 IPPROTO_ENCAP
= 98, /* Encapsulation Header. */
78 #define IPPROTO_ENCAP IPPROTO_ENCAP
79 IPPROTO_PIM
= 103, /* Protocol Independent Multicast. */
80 #define IPPROTO_PIM IPPROTO_PIM
81 IPPROTO_COMP
= 108, /* Compression Header Protocol. */
82 #define IPPROTO_COMP IPPROTO_COMP
83 IPPROTO_SCTP
= 132, /* Stream Control Transmission Protocol. */
84 #define IPPROTO_SCTP IPPROTO_SCTP
85 IPPROTO_RAW
= 255, /* Raw IP packets. */
86 #define IPPROTO_RAW IPPROTO_RAW
91 /* Type to represent a port. */
92 typedef uint16_t in_port_t
;
94 /* Standard well-known ports. */
97 IPPORT_ECHO
= 7, /* Echo service. */
98 IPPORT_DISCARD
= 9, /* Discard transmissions service. */
99 IPPORT_SYSTAT
= 11, /* System status service. */
100 IPPORT_DAYTIME
= 13, /* Time of day service. */
101 IPPORT_NETSTAT
= 15, /* Network status service. */
102 IPPORT_FTP
= 21, /* File Transfer Protocol. */
103 IPPORT_TELNET
= 23, /* Telnet protocol. */
104 IPPORT_SMTP
= 25, /* Simple Mail Transfer Protocol. */
105 IPPORT_TIMESERVER
= 37, /* Timeserver service. */
106 IPPORT_NAMESERVER
= 42, /* Domain Name Service. */
107 IPPORT_WHOIS
= 43, /* Internet Whois service. */
110 IPPORT_TFTP
= 69, /* Trivial File Transfer Protocol. */
112 IPPORT_FINGER
= 79, /* Finger service. */
114 IPPORT_SUPDUP
= 95, /* SUPDUP protocol. */
117 IPPORT_EXECSERVER
= 512, /* execd service. */
118 IPPORT_LOGINSERVER
= 513, /* rlogind service. */
119 IPPORT_CMDSERVER
= 514,
120 IPPORT_EFSSERVER
= 520,
123 IPPORT_BIFFUDP
= 512,
124 IPPORT_WHOSERVER
= 513,
125 IPPORT_ROUTESERVER
= 520,
127 /* Ports less than this value are reserved for privileged processes. */
128 IPPORT_RESERVED
= 1024,
130 /* Ports greater this value are reserved for (non-privileged) servers. */
131 IPPORT_USERRESERVED
= 5000
135 /* Internet address. */
136 typedef uint32_t in_addr_t
;
143 /* Definitions of the bits in an Internet address integer.
145 On subnets, host and network parts are found according to
146 the subnet mask, not these masks. */
148 #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
149 #define IN_CLASSA_NET 0xff000000
150 #define IN_CLASSA_NSHIFT 24
151 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
152 #define IN_CLASSA_MAX 128
154 #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
155 #define IN_CLASSB_NET 0xffff0000
156 #define IN_CLASSB_NSHIFT 16
157 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
158 #define IN_CLASSB_MAX 65536
160 #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
161 #define IN_CLASSC_NET 0xffffff00
162 #define IN_CLASSC_NSHIFT 8
163 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
165 #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
166 #define IN_MULTICAST(a) IN_CLASSD(a)
168 #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
169 #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
171 /* Address to accept any incoming messages. */
172 #define INADDR_ANY ((in_addr_t) 0x00000000)
173 /* Address to send to all hosts. */
174 #define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
175 /* Address indicating an error return. */
176 #define INADDR_NONE ((in_addr_t) 0xffffffff)
178 /* Network number for local host loopback. */
179 #define IN_LOOPBACKNET 127
180 /* Address to loopback in software to local host. */
181 #ifndef INADDR_LOOPBACK
182 # define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1. */
185 /* Defines for Multicast INADDR. */
186 #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
187 #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
188 #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
189 #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
197 uint8_t u6_addr8
[16];
198 uint16_t u6_addr16
[8];
199 uint32_t u6_addr32
[4];
201 #define s6_addr in6_u.u6_addr8
202 #define s6_addr16 in6_u.u6_addr16
203 #define s6_addr32 in6_u.u6_addr32
206 extern const struct in6_addr in6addr_any
; /* :: */
207 extern const struct in6_addr in6addr_loopback
; /* ::1 */
208 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
209 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
211 #define INET_ADDRSTRLEN 16
212 #define INET6_ADDRSTRLEN 46
214 /* Get the definition of the macro to define the common sockaddr members. */
215 #include <bits/socket.h>
218 /* Structure describing an Internet socket address. */
221 __SOCKADDR_COMMON (sin_
);
222 in_port_t sin_port
; /* Port number. */
223 struct in_addr sin_addr
; /* Internet address. */
225 /* Pad to size of `struct sockaddr'. */
226 unsigned char sin_zero
[sizeof (struct sockaddr
) -
227 __SOCKADDR_COMMON_SIZE
-
229 sizeof (struct in_addr
)];
232 /* Ditto, for IPv6. */
235 __SOCKADDR_COMMON (sin6_
);
236 in_port_t sin6_port
; /* Transport layer port # */
237 uint32_t sin6_flowinfo
; /* IPv6 flow information */
238 struct in6_addr sin6_addr
; /* IPv6 address */
239 uint32_t sin6_scope_id
; /* IPv6 scope-id */
243 /* IPv4 multicast request. */
246 /* IP multicast address of group. */
247 struct in_addr imr_multiaddr
;
249 /* Local IP address of interface. */
250 struct in_addr imr_interface
;
253 struct ip_mreq_source
255 /* IP multicast address of group. */
256 struct in_addr imr_multiaddr
;
258 /* IP address of source. */
259 struct in_addr imr_interface
;
261 /* IP address of interface. */
262 struct in_addr imr_sourceaddr
;
265 /* Likewise, for IPv6. */
268 /* IPv6 multicast address of group */
269 struct in6_addr ipv6mr_multiaddr
;
271 /* local interface */
272 unsigned int ipv6mr_interface
;
276 /* Multicast group request. */
279 /* Interface index. */
280 uint32_t gr_interface
;
283 struct sockaddr_storage gr_group
;
286 struct group_source_req
288 /* Interface index. */
289 uint32_t gsr_interface
;
292 struct sockaddr_storage gsr_group
;
294 /* Source address. */
295 struct sockaddr_storage gsr_source
;
299 /* Get system-specific definitions. */
302 /* Functions to convert between host and network byte order.
304 Please note that these functions normally take `unsigned long int' or
305 `unsigned short int' values as arguments and also return them. But
306 this was a short-sighted decision since on different systems the types
307 may have different representations but the values are always the same. */
309 extern uint32_t ntohl (uint32_t __netlong
) __THROW
__attribute__ ((__const__
));
310 extern uint16_t ntohs (uint16_t __netshort
)
311 __THROW
__attribute__ ((__const__
));
312 extern uint32_t htonl (uint32_t __hostlong
)
313 __THROW
__attribute__ ((__const__
));
314 extern uint16_t htons (uint16_t __hostshort
)
315 __THROW
__attribute__ ((__const__
));
319 /* Get machine dependent optimized versions of byte swapping functions. */
320 #include <bits/byteswap.h>
323 /* We can optimize calls to the conversion functions. Either nothing has
324 to be done or we are using directly the byte-swapping functions which
325 often can be inlined. */
326 # if __BYTE_ORDER == __BIG_ENDIAN
327 /* The host byte order is the same as network byte order,
328 so these functions are all just identity. */
329 # define ntohl(x) (x)
330 # define ntohs(x) (x)
331 # define htonl(x) (x)
332 # define htons(x) (x)
334 # if __BYTE_ORDER == __LITTLE_ENDIAN
335 # define ntohl(x) __bswap_32 (x)
336 # define ntohs(x) __bswap_16 (x)
337 # define htonl(x) __bswap_32 (x)
338 # define htons(x) __bswap_16 (x)
343 #define IN6_IS_ADDR_UNSPECIFIED(a) \
344 (((__const uint32_t *) (a))[0] == 0 \
345 && ((__const uint32_t *) (a))[1] == 0 \
346 && ((__const uint32_t *) (a))[2] == 0 \
347 && ((__const uint32_t *) (a))[3] == 0)
349 #define IN6_IS_ADDR_LOOPBACK(a) \
350 (((__const uint32_t *) (a))[0] == 0 \
351 && ((__const uint32_t *) (a))[1] == 0 \
352 && ((__const uint32_t *) (a))[2] == 0 \
353 && ((__const uint32_t *) (a))[3] == htonl (1))
355 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
357 #define IN6_IS_ADDR_LINKLOCAL(a) \
358 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
359 == htonl (0xfe800000))
361 #define IN6_IS_ADDR_SITELOCAL(a) \
362 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
363 == htonl (0xfec00000))
365 #define IN6_IS_ADDR_V4MAPPED(a) \
366 ((((__const uint32_t *) (a))[0] == 0) \
367 && (((__const uint32_t *) (a))[1] == 0) \
368 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
370 #define IN6_IS_ADDR_V4COMPAT(a) \
371 ((((__const uint32_t *) (a))[0] == 0) \
372 && (((__const uint32_t *) (a))[1] == 0) \
373 && (((__const uint32_t *) (a))[2] == 0) \
374 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
376 #define IN6_ARE_ADDR_EQUAL(a,b) \
377 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
378 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
379 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
380 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
382 /* Bind socket to a privileged IP port. */
383 extern int bindresvport (int __sockfd
, struct sockaddr_in
*__sock_in
) __THROW
;
385 /* The IPv6 version of this function. */
386 extern int bindresvport6 (int __sockfd
, struct sockaddr_in6
*__sock_in
)
390 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
391 (IN6_IS_ADDR_MULTICAST(a) \
392 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
394 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
395 (IN6_IS_ADDR_MULTICAST(a) \
396 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
398 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
399 (IN6_IS_ADDR_MULTICAST(a) \
400 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
402 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
403 (IN6_IS_ADDR_MULTICAST(a) \
404 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
406 #define IN6_IS_ADDR_MC_GLOBAL(a) \
407 (IN6_IS_ADDR_MULTICAST(a) \
408 && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
410 /* IPv6 packet information. */
413 struct in6_addr ipi6_addr
; /* src/dst IPv6 address */
414 unsigned int ipi6_ifindex
; /* send/recv interface index */
419 /* Hop-by-Hop and Destination Options Processing. */
420 extern int inet6_option_space (int __nbytes
) __THROW
;
421 extern int inet6_option_init (void *__bp
, struct cmsghdr
**__cmsgp
,
423 extern int inet6_option_append (struct cmsghdr
*__cmsg
,
424 __const
uint8_t *__typep
, int __multx
,
425 int __plusy
) __THROW
;
426 extern uint8_t *inet6_option_alloc (struct cmsghdr
*__cmsg
, int __datalen
,
427 int __multx
, int __plusy
) __THROW
;
428 extern int inet6_option_next (__const
struct cmsghdr
*__cmsg
,
429 uint8_t **__tptrp
) __THROW
;
430 extern int inet6_option_find (__const
struct cmsghdr
*__cmsg
,
431 uint8_t **__tptrp
, int __type
) __THROW
;
434 /* Multicast source filter support. */
436 /* Get IPv4 source filter. */
437 extern int getipv4sourcefilter (int __s
, struct in_addr __interface
,
438 struct in_addr __group
, uint32_t *__fmode
,
439 uint32_t *__numsrc
, struct in_addr
*__slist
)
442 /* Set IPv4 source filter. */
443 extern int setipv4sourcefilter (int __s
, struct in_addr __interface
,
444 struct in_addr __group
, uint32_t __fmode
,
445 uint32_t __numsrc
, struct in_addr
*__slist
)
449 /* Get source filter. */
450 extern int getsourcefilter (int __s
, uint32_t __interface
,
451 struct sockaddr
*__group
, socklen_t __grouplen
,
452 uint32_t *__fmode
, uint32_t *__numsrc
,
453 struct sockaddr_storage
*__slist
) __THROW
;
455 /* Set source filter. */
456 extern int setsourcefilter (int __s
, uint32_t __interface
,
457 struct sockaddr
*__group
, socklen_t __grouplen
,
458 uint32_t __fmode
, uint32_t __numsrc
,
459 struct sockaddr_storage
*__slist
) __THROW
;
464 #endif /* netinet/in.h */