]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/netinet/in.h
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / netinet / in.h
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
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
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
19 #ifndef _NETINET_IN_H
20
21 #define _NETINET_IN_H 1
22 #include <features.h>
23
24 #include <sys/socket.h>
25 #include <sys/types.h>
26
27
28 __BEGIN_DECLS
29
30 /* Standard well-defined IP protocols. */
31 enum
32 {
33 IPPROTO_IP = 0, /* Dummy protocol for TCP. */
34 IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */
35 IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */
36 IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */
37 IPPROTO_TCP = 6, /* Transmission Control Protocol. */
38 IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */
39 IPPROTO_PUP = 12, /* PUP protocol. */
40 IPPROTO_UDP = 17, /* User Datagram Protocol. */
41 IPPROTO_IDP = 22, /* XNS IDP protocol. */
42 IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling. */
43 IPPROTO_ICMPV6 = 58, /* ICMPv6. */
44
45 IPPROTO_RAW = 255, /* Raw IP packets. */
46 IPPROTO_MAX
47 };
48
49 /* Standard well-known ports. */
50 enum
51 {
52 IPPORT_ECHO = 7, /* Echo service. */
53 IPPORT_DISCARD = 9, /* Discard transmissions service. */
54 IPPORT_SYSTAT = 11, /* System status service. */
55 IPPORT_DAYTIME = 13, /* Time of day service. */
56 IPPORT_NETSTAT = 15, /* Network status service. */
57 IPPORT_FTP = 21, /* File Transfer Protocol. */
58 IPPORT_TELNET = 23, /* Telnet protocol. */
59 IPPORT_SMTP = 25, /* Simple Mail Transfer Protocol. */
60 IPPORT_TIMESERVER = 37, /* Timeserver service. */
61 IPPORT_NAMESERVER = 42, /* Domain Name Service. */
62 IPPORT_WHOIS = 43, /* Internet Whois service. */
63 IPPORT_MTP = 57,
64
65 IPPORT_TFTP = 69, /* Trivial File Transfer Protocol. */
66 IPPORT_RJE = 77,
67 IPPORT_FINGER = 79, /* Finger service. */
68 IPPORT_TTYLINK = 87,
69 IPPORT_SUPDUP = 95, /* SUPDUP protocol. */
70
71
72 IPPORT_EXECSERVER = 512, /* execd service. */
73 IPPORT_LOGINSERVER = 513, /* rlogind service. */
74 IPPORT_CMDSERVER = 514,
75 IPPORT_EFSSERVER = 520,
76
77 /* UDP ports. */
78 IPPORT_BIFFUDP = 512,
79 IPPORT_WHOSERVER = 513,
80 IPPORT_ROUTESERVER = 520,
81
82 /* Ports less than this value are reserved for privileged processes. */
83 IPPORT_RESERVED = 1024,
84
85 /* Ports greater this value are reserved for (non-privileged) servers. */
86 IPPORT_USERRESERVED = 5000
87 };
88
89
90 /* Internet address. */
91 struct in_addr
92 {
93 unsigned int s_addr;
94 };
95
96
97 /* Definitions of the bits in an Internet address integer.
98
99 On subnets, host and network parts are found according to
100 the subnet mask, not these masks. */
101
102 #define IN_CLASSA(a) ((((unsigned) (a)) & 0x80000000) == 0)
103 #define IN_CLASSA_NET 0xff000000
104 #define IN_CLASSA_NSHIFT 24
105 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
106 #define IN_CLASSA_MAX 128
107
108 #define IN_CLASSB(a) ((((unsigned) (a)) & 0xc0000000) == 0x80000000)
109 #define IN_CLASSB_NET 0xffff0000
110 #define IN_CLASSB_NSHIFT 16
111 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
112 #define IN_CLASSB_MAX 65536
113
114 #define IN_CLASSC(a) ((((unsigned) (a)) & 0xc0000000) == 0xc0000000)
115 #define IN_CLASSC_NET 0xffffff00
116 #define IN_CLASSC_NSHIFT 8
117 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
118
119 #define IN_CLASSD(a) ((((unsigned) (a)) & 0xf0000000) == 0xe0000000)
120 #define IN_MULTICAST(a) IN_CLASSD(a)
121
122 #define IN_EXPERIMENTAL(a) ((((unsigned) (a)) & 0xe0000000) == 0xe0000000)
123 #define IN_BADCLASS(a) ((((unsigned) (a)) & 0xf0000000) == 0xf0000000)
124
125 /* Address to accept any incoming messages. */
126 #define INADDR_ANY ((unsigned) 0x00000000)
127 /* Address to send to all hosts. */
128 #define INADDR_BROADCAST ((unsigned) 0xffffffff)
129 /* Address indicating an error return. */
130 #define INADDR_NONE ((unsigned) 0xffffffff)
131
132 /* Network number for local host loopback. */
133 #define IN_LOOPBACKNET 127
134 /* Address to loopback in software to local host. */
135 #ifndef INADDR_LOOPBACK
136 #define INADDR_LOOPBACK ((unsigned) 0x7f000001) /* Inet address 127.0.0.1. */
137 #endif
138
139
140 /* IPv6 address */
141 struct in6_addr
142 {
143 union
144 {
145 u_int8_t u6_addr8[16];
146 u_int16_t u6_addr16[8];
147 u_int32_t u6_addr32[4];
148 #if (~0UL) > 0xffffffff
149 u_int64_t u6_addr64[2];
150 #endif
151 } in6_u;
152 #define s6_addr in6_u.u6_addr8
153 #define s6_addr16 in6_u.u6_addr16
154 #define s6_addr32 in6_u.u6_addr32
155 #define s6_addr64 in6_u.u6_addr64
156 };
157
158 extern const struct in6_addr in6addr_any; /* :: */
159 extern const struct in6_addr in6addr_loopback; /* ::1 */
160 #define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
161 #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
162
163 #define INET_ADDRSTRLEN 16
164 #define INET6_ADDRSTRLEN 46
165
166 /* Get the definition of the macro to define the common sockaddr members. */
167 #include <sockaddrcom.h>
168
169
170 /* Structure describing an Internet socket address. */
171 struct sockaddr_in
172 {
173 __SOCKADDR_COMMON (sin_);
174 unsigned short int sin_port; /* Port number. */
175 struct in_addr sin_addr; /* Internet address. */
176
177 /* Pad to size of `struct sockaddr'. */
178 unsigned char sin_zero[sizeof(struct sockaddr) -
179 __SOCKADDR_COMMON_SIZE -
180 sizeof(unsigned short int) -
181 sizeof(struct in_addr)];
182 };
183
184 /* Ditto, for IPv6. */
185 struct sockaddr_in6
186 {
187 __SOCKADDR_COMMON (sin6_);
188 u_int16_t sin6_port; /* Transport layer port # */
189 u_int32_t sin6_flowinfo; /* IPv6 flow information */
190 struct in6_addr sin6_addr; /* IPv6 address */
191 };
192
193 /* IPv6 multicast request. */
194 struct ipv6_mreq
195 {
196 /* IPv6 multicast address of group */
197 struct in6_addr ipv6mr_multiaddr;
198
199 /* local IPv6 address of interface */
200 int ipv6mr_ifindex;
201 };
202
203
204 /* Options for use with `getsockopt' and `setsockopt' at the IP level.
205 The first word in the comment at the right is the data type used;
206 "bool" means a boolean value stored in an `int'. */
207 #define IP_TOS 1 /* int; IP type of service and precedence. */
208 #define IP_TTL 2 /* int; IP time to live. */
209 #define IP_HDRINCL 3 /* int; Header is included with data. */
210 #define IP_OPTIONS 4 /* ip_opts; IP per-packet options. */
211 #define IP_MULTICAST_IF 32 /* in_addr; set/get IP multicast i/f */
212 #define IP_MULTICAST_TTL 33 /* u_char; set/get IP multicast ttl */
213 #define IP_MULTICAST_LOOP 34 /* i_char; set/get IP multicast loopback */
214 #define IP_ADD_MEMBERSHIP 35 /* ip_mreq; add an IP group membership */
215 #define IP_DROP_MEMBERSHIP 36 /* ip_mreq; drop an IP group membership */
216
217 /* To select the IP level. */
218 #define SOL_IP 0
219
220 /* Structure used to describe IP options for IP_OPTIONS. The `ip_dst'
221 field is used for the first-hop gateway when using a source route
222 (this gets put into the header proper). */
223 struct ip_opts
224 {
225 struct in_addr ip_dst; /* First hop; zero without source route. */
226 char ip_opts[40]; /* Actually variable in size. */
227 };
228
229 /* Structure used for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. */
230 struct ip_mreq
231 {
232 struct in_addr imr_multiaddr; /* IP multicast address of group */
233 struct in_addr imr_interface; /* local IP address of interface */
234 };
235
236 /* Functions to convert between host and network byte order.
237
238 Please note that these functions normally take `unsigned long int' or
239 `unsigned short int' values as arguments and also return them. But
240 this was a short-sighted decision since on different systems the types
241 may have different representations but the values are always the same. */
242
243 extern u_int32_t ntohl __P ((u_int32_t __netlong));
244 extern u_int16_t ntohs __P ((u_int16_t __netshort));
245 extern u_int32_t htonl __P ((u_int32_t __hostlong));
246 extern u_int16_t htons __P ((u_int16_t __hostshort));
247
248 #include <endian.h>
249
250 #if __BYTE_ORDER == __BIG_ENDIAN
251 /* The host byte order is the same as network byte order,
252 so these functions are all just identity. */
253 #define ntohl(x) (x)
254 #define ntohs(x) (x)
255 #define htonl(x) (x)
256 #define htons(x) (x)
257 #endif
258
259
260 /* IPV6 socket options. */
261 #define IPV6_ADDRFORM 1
262 #define IPV6_RXINFO 2
263 #define IPV6_RXHOPOPTS 3
264 #define IPV6_RXDSTOPTS 4
265 #define IPV6_RXSRCRT 5
266 #define IPV6_PKTOPTIONS 6
267 #define IPV6_CHECKSUM 7
268 #define IPV6_HOPLIMIT 8
269
270 #define IPV6_TXINFO IPV6_RXINFO
271 #define SCM_SRCINFO IPV6_TXINFO
272 #define SCM_SRCRT IPV6_RXSRCRT
273
274 #define IPV6_UNICAST_HOPS 16
275 #define IPV6_MULTICAST_IF 17
276 #define IPV6_MULTICAST_HOPS 18
277 #define IPV6_MULTICAST_LOOP 19
278 #define IPV6_ADD_MEMBERSHIP 20
279 #define IPV6_DROP_MEMBERSHIP 21
280
281 #define IN6_IS_ADDR_UNSPECIFIED(a) \
282 ((((u_int32_t *)(a))[0] == 0) && ((u_int32_t *)(a))[1] == 0) && \
283 (((u_int32_t *)(a))[2] == 0) && ((u_int32_t *)(a))[3] == 0))
284
285 #define IN6_IS_ADDR_LOOPBACK(a) \
286 ((((u_int32_t *)(a))[0] == 0) && ((u_int32_t *)(a))[1] == 0) && \
287 (((u_int32_t *)(a))[2] == 0) && ((u_int32_t *)(a))[3] == htonl(1)))
288
289 #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *)(a))[0] == 0xff)
290
291 #define IN6_IS_ADDR_LINKLOCAL(a) \
292 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfe800000))
293
294 #define IN6_IS_ADDR_SITELOCAL(a) \
295 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfec00000))
296
297 #define IN6_IS_ADDR_V4MAPPED(a) \
298 ((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \
299 (((u_int32_t *)(a))[2] == htonl(0xffff)))
300
301 #define IN6_IS_ADDR_V4COMPAT(a) \
302 ((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \
303 (((u_int32_t *)(a))[2] == 0) && (ntohl(((u_int32_t *)(a))[3]) > 1))
304
305
306 /* Bind socket to a priviledged IP port. */
307 extern int bindresvport __P ((int __sockfd, struct sockaddr_in *__sin));
308
309 __END_DECLS
310
311 #endif /* netinet/in.h */