1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 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)
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.
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. */
21 #define _NETINET_IN_H 1
24 #include <sys/socket.h>
25 #include <sys/types.h>
30 /* Standard well-defined IP protocols. */
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. */
45 IPPROTO_RAW
= 255, /* Raw IP packets. */
49 /* Standard well-known ports. */
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. */
65 IPPORT_TFTP
= 69, /* Trivial File Transfer Protocol. */
67 IPPORT_FINGER
= 79, /* Finger service. */
69 IPPORT_SUPDUP
= 95, /* SUPDUP protocol. */
72 IPPORT_EXECSERVER
= 512, /* execd service. */
73 IPPORT_LOGINSERVER
= 513, /* rlogind service. */
74 IPPORT_CMDSERVER
= 514,
75 IPPORT_EFSSERVER
= 520,
79 IPPORT_WHOSERVER
= 513,
80 IPPORT_ROUTESERVER
= 520,
82 /* Ports less than this value are reserved for privileged processes. */
83 IPPORT_RESERVED
= 1024,
85 /* Ports greater this value are reserved for (non-privileged) servers. */
86 IPPORT_USERRESERVED
= 5000
90 /* Internet address. */
97 /* Definitions of the bits in an Internet address integer.
99 On subnets, host and network parts are found according to
100 the subnet mask, not these masks. */
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
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
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)
119 #define IN_CLASSD(a) ((((unsigned) (a)) & 0xf0000000) == 0xe0000000)
120 #define IN_MULTICAST(a) IN_CLASSD(a)
122 #define IN_EXPERIMENTAL(a) ((((unsigned) (a)) & 0xe0000000) == 0xe0000000)
123 #define IN_BADCLASS(a) ((((unsigned) (a)) & 0xf0000000) == 0xf0000000)
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)
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. */
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];
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
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 }
163 #define INET_ADDRSTRLEN 16
164 #define INET6_ADDRSTRLEN 46
166 /* Get the definition of the macro to define the common sockaddr members. */
167 #include <sockaddrcom.h>
170 /* Structure describing an Internet socket address. */
173 __SOCKADDR_COMMON (sin_
);
174 unsigned short int sin_port
; /* Port number. */
175 struct in_addr sin_addr
; /* Internet address. */
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
)];
184 /* Ditto, for IPv6. */
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 */
193 /* IPv6 multicast request. */
196 /* IPv6 multicast address of group */
197 struct in6_addr ipv6mr_multiaddr
;
199 /* local IPv6 address of interface */
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 */
217 /* To select the IP level. */
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). */
225 struct in_addr ip_dst
; /* First hop; zero without source route. */
226 char ip_opts
[40]; /* Actually variable in size. */
229 /* Structure used for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. */
232 struct in_addr imr_multiaddr
; /* IP multicast address of group */
233 struct in_addr imr_interface
; /* local IP address of interface */
236 /* Functions to convert between host and network byte order.
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. */
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
));
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. */
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
270 #define IPV6_TXINFO IPV6_RXINFO
271 #define SCM_SRCINFO IPV6_TXINFO
272 #define SCM_SRCRT IPV6_RXSRCRT
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
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))
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)))
289 #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *)(a))[0] == 0xff)
291 #define IN6_IS_ADDR_LINKLOCAL(a) \
292 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfe800000))
294 #define IN6_IS_ADDR_SITELOCAL(a) \
295 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfec00000))
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)))
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))
306 /* Bind socket to a priviledged IP port. */
307 extern int bindresvport
__P ((int __sockfd
, struct sockaddr_in
*__sin
));
311 #endif /* netinet/in.h */