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
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library 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. */
20 #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 <bits/sockaddr.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 */
203 /* Get system-specific definitions. */
204 #include <netinet/inbits.h>
206 /* Functions to convert between host and network byte order.
208 Please note that these functions normally take `unsigned long int' or
209 `unsigned short int' values as arguments and also return them. But
210 this was a short-sighted decision since on different systems the types
211 may have different representations but the values are always the same. */
213 extern u_int32_t ntohl __P ((u_int32_t __netlong));
214 extern u_int16_t ntohs __P ((u_int16_t __netshort));
215 extern u_int32_t htonl __P ((u_int32_t __hostlong));
216 extern u_int16_t htons __P ((u_int16_t __hostshort));
220 #if __BYTE_ORDER == __BIG_ENDIAN
221 /* The host byte order is the same as network byte order,
222 so these functions are all just identity. */
229 #define IN6_IS_ADDR_UNSPECIFIED(a) \
230 ((((u_int32_t *) (a))[0] == 0) && ((u_int32_t *) (a))[1] == 0) && \
231 (((u_int32_t *) (a))[2] == 0) && ((u_int32_t *) (a))[3] == 0))
233 #define IN6_IS_ADDR_LOOPBACK(a) \
234 ((((u_int32_t *) (a))[0] == 0) && ((u_int32_t *) (a))[1] == 0) && \
235 (((u_int32_t *) (a))[2] == 0) && ((u_int32_t *) (a))[3] == htonl (1)))
237 #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
239 #define IN6_IS_ADDR_LINKLOCAL(a) \
240 ((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
242 #define IN6_IS_ADDR_SITELOCAL(a) \
243 ((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfec00000))
245 #define IN6_IS_ADDR_V4MAPPED(a) \
246 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
247 (((u_int32_t *) (a))[2] == htonl (0xffff)))
249 #define IN6_IS_ADDR_V4COMPAT(a) \
250 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
251 (((u_int32_t *) (a))[2] == 0) && (ntohl (((u_int32_t *) (a))[3]) > 1))
254 /* Bind socket to a privileged IP port. */
255 extern int bindresvport __P ((int __sockfd, struct sockaddr_in *__sin));
258 /* IPv6 packet information. */
261 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
262 int ipi6_ifindex; /* send/recv interface index */
267 #endif /* netinet/in.h */