semtimedop implementation for Linux/m68k.
[glibc.git] / inet / netinet / in.h
bloba87f35e99a80a5d49f20e5d42d66717dcd571176
1 /* Copyright (C) 1991-1999, 2000, 2001, 2003 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
17 02111-1307 USA. */
19 #ifndef _NETINET_IN_H
20 #define _NETINET_IN_H 1
22 #include <features.h>
23 #include <stdint.h>
24 #include <bits/types.h>
27 __BEGIN_DECLS
29 /* Standard well-defined IP protocols. */
30 enum
32 IPPROTO_IP = 0, /* Dummy protocol for TCP. */
33 #define IPPROTO_IP IPPROTO_IP
34 IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options. */
35 #define IPPROTO_HOPOPTS IPPROTO_HOPOPTS
36 IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */
37 #define IPPROTO_ICMP IPPROTO_ICMP
38 IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */
39 #define IPPROTO_IGMP IPPROTO_IGMP
40 IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */
41 #define IPPROTO_IPIP IPPROTO_IPIP
42 IPPROTO_TCP = 6, /* Transmission Control Protocol. */
43 #define IPPROTO_TCP IPPROTO_TCP
44 IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */
45 #define IPPROTO_EGP IPPROTO_EGP
46 IPPROTO_PUP = 12, /* PUP protocol. */
47 #define IPPROTO_PUP IPPROTO_PUP
48 IPPROTO_UDP = 17, /* User Datagram Protocol. */
49 #define IPPROTO_UDP IPPROTO_UDP
50 IPPROTO_IDP = 22, /* XNS IDP protocol. */
51 #define IPPROTO_IDP IPPROTO_IDP
52 IPPROTO_TP = 29, /* SO Transport Protocol Class 4. */
53 #define IPPROTO_TP IPPROTO_TP
54 IPPROTO_IPV6 = 41, /* IPv6 header. */
55 #define IPPROTO_IPV6 IPPROTO_IPV6
56 IPPROTO_ROUTING = 43, /* IPv6 routing header. */
57 #define IPPROTO_ROUTING IPPROTO_ROUTING
58 IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header. */
59 #define IPPROTO_FRAGMENT IPPROTO_FRAGMENT
60 IPPROTO_RSVP = 46, /* Reservation Protocol. */
61 #define IPPROTO_RSVP IPPROTO_RSVP
62 IPPROTO_GRE = 47, /* General Routing Encapsulation. */
63 #define IPPROTO_GRE IPPROTO_GRE
64 IPPROTO_ESP = 50, /* encapsulating security payload. */
65 #define IPPROTO_ESP IPPROTO_ESP
66 IPPROTO_AH = 51, /* authentication header. */
67 #define IPPROTO_AH IPPROTO_AH
68 IPPROTO_ICMPV6 = 58, /* ICMPv6. */
69 #define IPPROTO_ICMPV6 IPPROTO_ICMPV6
70 IPPROTO_NONE = 59, /* IPv6 no next header. */
71 #define IPPROTO_NONE IPPROTO_NONE
72 IPPROTO_DSTOPTS = 60, /* IPv6 destination options. */
73 #define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
74 IPPROTO_MTP = 92, /* Multicast Transport Protocol. */
75 #define IPPROTO_MTP IPPROTO_MTP
76 IPPROTO_ENCAP = 98, /* Encapsulation Header. */
77 #define IPPROTO_ENCAP IPPROTO_ENCAP
78 IPPROTO_PIM = 103, /* Protocol Independent Multicast. */
79 #define IPPROTO_PIM IPPROTO_PIM
80 IPPROTO_COMP = 108, /* Compression Header Protocol. */
81 #define IPPROTO_COMP IPPROTO_COMP
82 IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol. */
83 #define IPPROTO_SCTP IPPROTO_SCTP
84 IPPROTO_RAW = 255, /* Raw IP packets. */
85 #define IPPROTO_RAW IPPROTO_RAW
86 IPPROTO_MAX
90 /* Type to represent a port. */
91 typedef uint16_t in_port_t;
93 /* Standard well-known ports. */
94 enum
96 IPPORT_ECHO = 7, /* Echo service. */
97 IPPORT_DISCARD = 9, /* Discard transmissions service. */
98 IPPORT_SYSTAT = 11, /* System status service. */
99 IPPORT_DAYTIME = 13, /* Time of day service. */
100 IPPORT_NETSTAT = 15, /* Network status service. */
101 IPPORT_FTP = 21, /* File Transfer Protocol. */
102 IPPORT_TELNET = 23, /* Telnet protocol. */
103 IPPORT_SMTP = 25, /* Simple Mail Transfer Protocol. */
104 IPPORT_TIMESERVER = 37, /* Timeserver service. */
105 IPPORT_NAMESERVER = 42, /* Domain Name Service. */
106 IPPORT_WHOIS = 43, /* Internet Whois service. */
107 IPPORT_MTP = 57,
109 IPPORT_TFTP = 69, /* Trivial File Transfer Protocol. */
110 IPPORT_RJE = 77,
111 IPPORT_FINGER = 79, /* Finger service. */
112 IPPORT_TTYLINK = 87,
113 IPPORT_SUPDUP = 95, /* SUPDUP protocol. */
116 IPPORT_EXECSERVER = 512, /* execd service. */
117 IPPORT_LOGINSERVER = 513, /* rlogind service. */
118 IPPORT_CMDSERVER = 514,
119 IPPORT_EFSSERVER = 520,
121 /* UDP ports. */
122 IPPORT_BIFFUDP = 512,
123 IPPORT_WHOSERVER = 513,
124 IPPORT_ROUTESERVER = 520,
126 /* Ports less than this value are reserved for privileged processes. */
127 IPPORT_RESERVED = 1024,
129 /* Ports greater this value are reserved for (non-privileged) servers. */
130 IPPORT_USERRESERVED = 5000
134 /* Internet address. */
135 typedef uint32_t in_addr_t;
136 struct in_addr
138 in_addr_t s_addr;
142 /* Definitions of the bits in an Internet address integer.
144 On subnets, host and network parts are found according to
145 the subnet mask, not these masks. */
147 #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
148 #define IN_CLASSA_NET 0xff000000
149 #define IN_CLASSA_NSHIFT 24
150 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
151 #define IN_CLASSA_MAX 128
153 #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
154 #define IN_CLASSB_NET 0xffff0000
155 #define IN_CLASSB_NSHIFT 16
156 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
157 #define IN_CLASSB_MAX 65536
159 #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
160 #define IN_CLASSC_NET 0xffffff00
161 #define IN_CLASSC_NSHIFT 8
162 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
164 #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
165 #define IN_MULTICAST(a) IN_CLASSD(a)
167 #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
168 #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
170 /* Address to accept any incoming messages. */
171 #define INADDR_ANY ((in_addr_t) 0x00000000)
172 /* Address to send to all hosts. */
173 #define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
174 /* Address indicating an error return. */
175 #define INADDR_NONE ((in_addr_t) 0xffffffff)
177 /* Network number for local host loopback. */
178 #define IN_LOOPBACKNET 127
179 /* Address to loopback in software to local host. */
180 #ifndef INADDR_LOOPBACK
181 # define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1. */
182 #endif
184 /* Defines for Multicast INADDR. */
185 #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
186 #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
187 #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
188 #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
191 /* IPv6 address */
192 struct in6_addr
194 union
196 uint8_t u6_addr8[16];
197 uint16_t u6_addr16[8];
198 uint32_t u6_addr32[4];
199 } in6_u;
200 #define s6_addr in6_u.u6_addr8
201 #define s6_addr16 in6_u.u6_addr16
202 #define s6_addr32 in6_u.u6_addr32
205 extern const struct in6_addr in6addr_any; /* :: */
206 extern const struct in6_addr in6addr_loopback; /* ::1 */
207 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
208 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
210 #define INET_ADDRSTRLEN 16
211 #define INET6_ADDRSTRLEN 46
213 /* Get the definition of the macro to define the common sockaddr members. */
214 #include <bits/socket.h>
217 /* Structure describing an Internet socket address. */
218 struct sockaddr_in
220 __SOCKADDR_COMMON (sin_);
221 in_port_t sin_port; /* Port number. */
222 struct in_addr sin_addr; /* Internet address. */
224 /* Pad to size of `struct sockaddr'. */
225 unsigned char sin_zero[sizeof (struct sockaddr) -
226 __SOCKADDR_COMMON_SIZE -
227 sizeof (in_port_t) -
228 sizeof (struct in_addr)];
231 /* Ditto, for IPv6. */
232 struct sockaddr_in6
234 __SOCKADDR_COMMON (sin6_);
235 in_port_t sin6_port; /* Transport layer port # */
236 uint32_t sin6_flowinfo; /* IPv6 flow information */
237 struct in6_addr sin6_addr; /* IPv6 address */
238 uint32_t sin6_scope_id; /* IPv6 scope-id */
241 /* IPv6 multicast request. */
242 struct ipv6_mreq
244 /* IPv6 multicast address of group */
245 struct in6_addr ipv6mr_multiaddr;
247 /* local interface */
248 unsigned int ipv6mr_interface;
251 /* Get system-specific definitions. */
252 #include <bits/in.h>
254 /* Functions to convert between host and network byte order.
256 Please note that these functions normally take `unsigned long int' or
257 `unsigned short int' values as arguments and also return them. But
258 this was a short-sighted decision since on different systems the types
259 may have different representations but the values are always the same. */
261 extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
262 extern uint16_t ntohs (uint16_t __netshort)
263 __THROW __attribute__ ((__const__));
264 extern uint32_t htonl (uint32_t __hostlong)
265 __THROW __attribute__ ((__const__));
266 extern uint16_t htons (uint16_t __hostshort)
267 __THROW __attribute__ ((__const__));
269 #include <endian.h>
271 /* Get machine dependent optimized versions of byte swapping functions. */
272 #include <bits/byteswap.h>
274 #ifdef __OPTIMIZE__
275 /* We can optimize calls to the conversion functions. Either nothing has
276 to be done or we are using directly the byte-swapping functions which
277 often can be inlined. */
278 # if __BYTE_ORDER == __BIG_ENDIAN
279 /* The host byte order is the same as network byte order,
280 so these functions are all just identity. */
281 # define ntohl(x) (x)
282 # define ntohs(x) (x)
283 # define htonl(x) (x)
284 # define htons(x) (x)
285 # else
286 # if __BYTE_ORDER == __LITTLE_ENDIAN
287 # define ntohl(x) __bswap_32 (x)
288 # define ntohs(x) __bswap_16 (x)
289 # define htonl(x) __bswap_32 (x)
290 # define htons(x) __bswap_16 (x)
291 # endif
292 # endif
293 #endif
295 #define IN6_IS_ADDR_UNSPECIFIED(a) \
296 (((__const uint32_t *) (a))[0] == 0 \
297 && ((__const uint32_t *) (a))[1] == 0 \
298 && ((__const uint32_t *) (a))[2] == 0 \
299 && ((__const uint32_t *) (a))[3] == 0)
301 #define IN6_IS_ADDR_LOOPBACK(a) \
302 (((__const uint32_t *) (a))[0] == 0 \
303 && ((__const uint32_t *) (a))[1] == 0 \
304 && ((__const uint32_t *) (a))[2] == 0 \
305 && ((__const uint32_t *) (a))[3] == htonl (1))
307 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
309 #define IN6_IS_ADDR_LINKLOCAL(a) \
310 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
311 == htonl (0xfe800000))
313 #define IN6_IS_ADDR_SITELOCAL(a) \
314 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
315 == htonl (0xfec00000))
317 #define IN6_IS_ADDR_V4MAPPED(a) \
318 ((((__const uint32_t *) (a))[0] == 0) \
319 && (((__const uint32_t *) (a))[1] == 0) \
320 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
322 #define IN6_IS_ADDR_V4COMPAT(a) \
323 ((((__const uint32_t *) (a))[0] == 0) \
324 && (((__const uint32_t *) (a))[1] == 0) \
325 && (((__const uint32_t *) (a))[2] == 0) \
326 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
328 #define IN6_ARE_ADDR_EQUAL(a,b) \
329 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
330 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
331 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
332 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
334 /* Bind socket to a privileged IP port. */
335 extern int bindresvport (int __sockfd, struct sockaddr_in *__sock_in) __THROW;
337 /* The IPv6 version of this function. */
338 extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
339 __THROW;
342 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
343 (IN6_IS_ADDR_MULTICAST(a) \
344 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
346 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
347 (IN6_IS_ADDR_MULTICAST(a) \
348 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
350 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
351 (IN6_IS_ADDR_MULTICAST(a) \
352 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
354 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
355 (IN6_IS_ADDR_MULTICAST(a) \
356 && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
358 #define IN6_IS_ADDR_MC_GLOBAL(a) \
359 (IN6_IS_ADDR_MULTICAST(a) \
360 && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
362 /* IPv6 packet information. */
363 struct in6_pktinfo
365 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
366 unsigned int ipi6_ifindex; /* send/recv interface index */
369 __END_DECLS
371 #endif /* netinet/in.h */