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>
29 /* Standard well-defined IP protocols. */
32 IPPROTO_IP
= 0, /* Dummy protocol for TCP. */
33 IPPROTO_ICMP
= 1, /* Internet Control Message Protocol. */
34 IPPROTO_IGMP
= 2, /* Internet Group Management Protocol. */
35 IPPROTO_TCP
= 6, /* Transmission Control Protocol. */
36 IPPROTO_EGP
= 8, /* Exterior Gateway Protocol. */
37 IPPROTO_PUP
= 12, /* PUP protocol. */
38 IPPROTO_UDP
= 17, /* User Datagram Protocol. */
39 IPPROTO_IDP
= 22, /* XNS IDP protocol. */
41 IPPROTO_RAW
= 255, /* Raw IP packets. */
45 /* Standard well-known ports. */
48 IPPORT_ECHO
= 7, /* Echo service. */
49 IPPORT_DISCARD
= 9, /* Discard transmissions service. */
50 IPPORT_SYSTAT
= 11, /* System status service. */
51 IPPORT_DAYTIME
= 13, /* Time of day service. */
52 IPPORT_NETSTAT
= 15, /* Network status service. */
53 IPPORT_FTP
= 21, /* File Transfer Protocol. */
54 IPPORT_TELNET
= 23, /* Telnet protocol. */
55 IPPORT_SMTP
= 25, /* Simple Mail Transfer Protocol. */
56 IPPORT_TIMESERVER
= 37, /* Timeserver service. */
57 IPPORT_NAMESERVER
= 42, /* Domain Name Service. */
58 IPPORT_WHOIS
= 43, /* Internet Whois service. */
61 IPPORT_TFTP
= 69, /* Trivial File Transfer Protocol. */
63 IPPORT_FINGER
= 79, /* Finger service. */
65 IPPORT_SUPDUP
= 95, /* SUPDUP protocol. */
68 IPPORT_EXECSERVER
= 512, /* execd service. */
69 IPPORT_LOGINSERVER
= 513, /* rlogind service. */
70 IPPORT_CMDSERVER
= 514,
71 IPPORT_EFSSERVER
= 520,
75 IPPORT_WHOSERVER
= 513,
76 IPPORT_ROUTESERVER
= 520,
78 /* Ports less than this value are reserved for privileged processes. */
79 IPPORT_RESERVED
= 1024,
81 /* Ports greater this value are reserved for (non-privileged) servers. */
82 IPPORT_USERRESERVED
= 5000
87 #define IMPLINK_IP 155
88 #define IMPLINK_LOWEXPER 156
89 #define IMPLINK_HIGHEXPER 158
92 /* Internet address. */
99 /* Definitions of the bits in an Internet address integer.
101 On subnets, host and network parts are found according to
102 the subnet mask, not these masks. */
104 #define IN_CLASSA(a) ((((unsigned) (a)) & 0x80000000) == 0)
105 #define IN_CLASSA_NET 0xff000000
106 #define IN_CLASSA_NSHIFT 24
107 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
108 #define IN_CLASSA_MAX 128
110 #define IN_CLASSB(a) ((((unsigned) (a)) & 0xc0000000) == 0x80000000)
111 #define IN_CLASSB_NET 0xffff0000
112 #define IN_CLASSB_NSHIFT 16
113 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
114 #define IN_CLASSB_MAX 65536
116 #define IN_CLASSC(a) ((((unsigned) (a)) & 0xc0000000) == 0xc0000000)
117 #define IN_CLASSC_NET 0xffffff00
118 #define IN_CLASSC_NSHIFT 8
119 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
121 #define IN_CLASSD(a) ((((unsigned) (a)) & 0xf0000000) == 0xe0000000)
122 #define IN_MULTICAST(a) IN_CLASSD(a)
124 #define IN_EXPERIMENTAL(a) ((((unsigned) (a)) & 0xe0000000) == 0xe0000000)
125 #define IN_BADCLASS(a) ((((unsigned) (a)) & 0xf0000000) == 0xf0000000)
127 /* Address to accept any incoming messages. */
128 #define INADDR_ANY ((unsigned) 0x00000000)
129 /* Address to send to all hosts. */
130 #define INADDR_BROADCAST ((unsigned) 0xffffffff)
131 /* Address indicating an error return. */
132 #define INADDR_NONE ((unsigned) 0xffffffff)
134 /* Network number for local host loopback. */
135 #define IN_LOOPBACKNET 127
136 /* Address to loopback in software to local host. */
137 #ifndef INADDR_LOOPBACK
138 #define INADDR_LOOPBACK ((unsigned) 0x7f000001) /* Inet address 127.0.0.1. */
147 u_int8_t u6_addr8
[16];
148 u_int16_t u6_addr16
[8];
149 u_int32_t u6_addr32
[4];
150 #if (~0UL) > 0xffffffff
151 u_int64_t u6_addr64
[2];
154 #define s6_addr in6_u.u6_addr8
155 #define s6_addr16 in6_u.u6_addr16
156 #define s6_addr32 in6_u.u6_addr32
157 #define s6_addr64 in6_u.u6_addr64
160 extern const struct in6_addr in6addr_any
; /* :: */
161 extern const struct in6_addr in6addr_loopback
; /* ::1 */
162 #define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
163 #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
165 #define INET_ADDRSTRLEN 16
166 #define INET6_ADDRSTRLEN 46
170 /* Get the definition of the macro to define the common sockaddr members. */
171 #include <sockaddrcom.h>
174 /* Structure describing an Internet socket address. */
177 __SOCKADDR_COMMON (sin_
);
178 unsigned short int sin_port
; /* Port number. */
179 struct in_addr sin_addr
; /* Internet address. */
181 /* Pad to size of `struct sockaddr'. */
182 unsigned char sin_zero
[sizeof(struct sockaddr
) -
183 __SOCKADDR_COMMON_SIZE
-
184 sizeof(unsigned short int) -
185 sizeof(struct in_addr
)];
188 /* Ditto, for IPv6. */
191 __SOCKADDR_COMMON (sin6_
);
192 u_int16_t sin6_port
; /* Transport layer port # */
193 u_int32_t sin6_flowinfo
; /* IPv6 flow information */
194 struct in6_addr sin6_addr
; /* IPv6 address */
197 /* IPv6 multicast request. */
200 /* IPv6 multicast address of group */
201 struct in6_addr ipv6mr_multiaddr
;
203 /* local IPv6 address of interface */
207 /* Options for use with `getsockopt' and `setsockopt' at the IP level.
208 The first word in the comment at the right is the data type used;
209 "bool" means a boolean value stored in an `int'. */
210 #define IP_OPTIONS 1 /* ip_opts; IP per-packet options. */
211 #define IP_HDRINCL 2 /* int; Header is included with data. */
212 #define IP_TOS 3 /* int; IP type of service and precedence. */
213 #define IP_TTL 4 /* int; IP time to live. */
214 #define IP_RECVOPTS 5 /* bool; Receive all IP options w/datagram. */
215 #define IP_RECVRETOPTS 6 /* bool; Receive IP options for response. */
216 #define IP_RECVDSTADDR 7 /* bool; Receive IP dst addr w/datagram. */
217 #define IP_RETOPTS 8 /* ip_opts; Set/get IP per-packet options. */
218 #define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */
219 #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
220 #define IP_MULTICAST_LOOP 11 /* i_char; set/get IP multicast loopback */
221 #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
222 #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
224 /* Structure used to describe IP options for IP_OPTIONS and IP_RETOPTS.
225 The `ip_dst' field is used for the first-hop gateway when using a
226 source route (this gets put into the header proper). */
229 struct in_addr ip_dst
; /* First hop; zero without source route. */
230 char ip_opts
[40]; /* Actually variable in size. */
233 /* Structure used for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. */
236 struct in_addr imr_multiaddr
; /* IP multicast address of group */
237 struct in_addr imr_interface
; /* local IP address of interface */
240 /* Functions to convert between host and network byte order.
242 Please note that these functions normally take `unsigned long int' or
243 `unsigned short int' values as arguments and also return them. But
244 this was a short-sighted decision since on different systems the types
245 may have different representations but the values are always the same. */
247 extern u_int32_t ntohl
__P ((u_int32_t __netlong
));
248 extern u_int16_t ntohs
__P ((u_int16_t __netshort
));
249 extern u_int32_t htonl
__P ((u_int32_t __hostlong
));
250 extern u_int16_t htons
__P ((u_int16_t __hostshort
));
254 #if __BYTE_ORDER == __BIG_ENDIAN
255 /* The host byte order is the same as network byte order,
256 so these functions are all just identity. */
263 /* IPV6 socket options. */
264 #define IPV6_ADDRFORM 1
265 #define IPV6_RXINFO 2
266 #define IPV6_RXHOPOPTS 3
267 #define IPV6_RXDSTOPTS 4
268 #define IPV6_RXSRCRT 5
269 #define IPV6_PKTOPTIONS 6
270 #define IPV6_CHECKSUM 7
271 #define IPV6_HOPLIMIT 8
273 #define IPV6_TXINFO IPV6_RXINFO
274 #define SCM_SRCINFO IPV6_TXINFO
275 #define SCM_SRCRT IPV6_RXSRCRT
277 #define IPV6_UNICAST_HOPS 16
278 #define IPV6_MULTICAST_IF 17
279 #define IPV6_MULTICAST_HOPS 18
280 #define IPV6_MULTICAST_LOOP 19
281 #define IPV6_ADD_MEMBERSHIP 20
282 #define IPV6_DROP_MEMBERSHIP 21
284 #define IN6_IS_ADDR_UNSPECIFIED(a) \
285 ((((u_int32_t *)(a))[0] == 0) && ((u_int32_t *)(a))[1] == 0) && \
286 (((u_int32_t *)(a))[2] == 0) && ((u_int32_t *)(a))[3] == 0))
288 #define IN6_IS_ADDR_LOOPBACK(a) \
289 ((((u_int32_t *)(a))[0] == 0) && ((u_int32_t *)(a))[1] == 0) && \
290 (((u_int32_t *)(a))[2] == 0) && ((u_int32_t *)(a))[3] == htonl(1)))
292 #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *)(a))[0] == 0xff)
294 #define IN6_IS_ADDR_LINKLOCAL(a) \
295 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfe800000))
297 #define IN6_IS_ADDR_SITELOCAL(a) \
298 ((((u_int32_t *)(a))[0] & htonl(0xffc00000)) == htonl(0xfec00000))
300 #define IN6_IS_ADDR_V4MAPPED(a) \
301 ((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \
302 (((u_int32_t *)(a))[2] == htonl(0xffff)))
304 #define IN6_IS_ADDR_V4COMPAT(a) \
305 ((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \
306 (((u_int32_t *)(a))[2] == 0) && (ntohl(((u_int32_t *)(a))[3]) > 1))
311 #endif /* netinet/in.h */