2 * Copyright (C) 2005 Neil Cafferkey
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License
6 * version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this file; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
22 * All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the University of
35 * California, Berkeley and its contributors.
36 * 4. Neither the name of the University nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * @(#)in.h 7.11 (Berkeley) 4/20/91
58 #include <sys/types.h>
63 * Endianness conversion macros
67 uint16_t _FlipWord_A = (A); \
68 _FlipWord_A = (_FlipWord_A << 8) | (_FlipWord_A >> 8); \
73 uint32_t _FlipLong_A = (A); \
75 (FlipWord(_FlipLong_A) << 16) | FlipWord(_FlipLong_A >> 16); \
78 #if _BYTE_ORDER == _BIG_ENDIAN
92 #elif _BYTE_ORDER == _LITTLE_ENDIAN
108 #error <netinet/in.h> - Byte order for this architecture is unsupported!
112 #define MakeBEWord(A) \
115 #define MakeBELong(A) \
118 #define MakeLEWord(A) \
121 #define MakeLELong(A) \
125 * Macros for network/external number representation conversion.
128 #define INET_ADDRSTRLEN 16
131 #define ntohl(x) BELong(x)
132 #define ntohs(x) BEWord(x)
133 #define htonl(x) MakeBELong(x)
134 #define htons(x) MakeBEWord(x)
136 #define NTOHL(x) ((x) = ntohl(x))
137 #define NTOHS(x) ((x) = ntohs(x))
138 #define HTONL(x) ((x) = htonl(x))
139 #define HTONS(x) ((x) = htons(x))
143 * Constants and structures defined by the internet system,
144 * Per RFC 790, September 1981.
150 #define IPPROTO_IP 0 /* dummy for IP */
151 #define IPPROTO_ICMP 1 /* control message protocol */
152 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
153 #define IPPROTO_TCP 6 /* tcp */
154 #define IPPROTO_EGP 8 /* exterior gateway protocol */
155 #define IPPROTO_PUP 12 /* pup */
156 #define IPPROTO_UDP 17 /* user datagram protocol */
157 #define IPPROTO_IDP 22 /* xns idp */
158 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
159 #define IPPROTO_IPV6 41 /* IPv6 protocol */
160 #define IPPROTO_EON 80 /* ISO cnlp */
161 #define IPPROTO_UDPLITE 136 /* UDP Lite */
163 #define IPPROTO_RAW 255 /* raw IP packet */
164 #define IPPROTO_MAX 256
168 * Local port number conventions:
169 * Ports < IPPORT_RESERVED are reserved for
170 * privileged processes (e.g. root).
171 * Ports > IPPORT_USERRESERVED are reserved
172 * for servers, not necessarily privileged.
174 #define IPPORT_RESERVED 1024
175 #define IPPORT_USERRESERVED 5000
178 * Internet address (a structure for historical reasons)
180 typedef uint32_t in_addr_t
;
187 * Definitions of bits in internet address integers.
188 * On subnets, the decomposition of addresses to host and net parts
189 * is done according to subnet mask, not the masks here.
191 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
192 #define IN_CLASSA_NET 0xff000000
193 #define IN_CLASSA_NSHIFT 24
194 #define IN_CLASSA_HOST 0x00ffffff
195 #define IN_CLASSA_MAX 128
197 #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
198 #define IN_CLASSB_NET 0xffff0000
199 #define IN_CLASSB_NSHIFT 16
200 #define IN_CLASSB_HOST 0x0000ffff
201 #define IN_CLASSB_MAX 65536
203 #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
204 #define IN_CLASSC_NET 0xffffff00
205 #define IN_CLASSC_NSHIFT 8
206 #define IN_CLASSC_HOST 0x000000ff
208 #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
209 #define IN_MULTICAST(i) IN_CLASSD(i)
211 #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000)
212 #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000)
214 #define INADDR_ANY (u_long)0x00000000
215 #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */
216 #define INADDR_LOOPBACK (u_long)0x7f000001 /* loopback address */
217 #if !defined(KERNEL) || defined(AMITCP)
218 #define INADDR_NONE 0xffffffff /* -1 return */
221 #define IN_LOOPBACKNET 127 /* official! */
224 * Socket address, internet style.
230 struct in_addr sin_addr
;
235 * Structure used to describe IP options.
236 * Used to store options internally, to pass them to a process,
237 * or to restore options retrieved earlier.
238 * The ip_dst is used for the first-hop gateway when using a source route
239 * (this gets put into the header proper).
242 struct in_addr ip_dst
; /* first hop, 0 w/o src rt */
243 char ip_opts
[40]; /* actually variable in size */
247 * Options for use with [gs]etsockopt at the IP level.
248 * First word of comment is data type; bool is stored in int.
250 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */
251 #define IP_HDRINCL 2 /* int; header is included with data (raw) */
252 #define IP_TOS 3 /* int; IP type of service and precedence */
253 #define IP_TTL 4 /* int; IP time to live */
254 #define IP_RECVOPTS 5 /* bool; receive all IP options w/datagram */
255 #define IP_RECVRETOPTS 6 /* bool; receive IP options for response */
256 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/datagram */
257 #define IP_RETOPTS 8 /* ip_opts; set/get IP per-packet options */
260 struct in_addr
in_makeaddr(u_long net
,
262 u_long
in_netof(struct in_addr in
);
263 u_long
in_lnaof(struct in_addr in
);
266 /* IPv6 structures */
270 uint16_t u16_addr
[8];
271 uint32_t u32_addr
[4];
273 #define s6_addr un.u8_addr
276 #define IN6ADDR_ANY_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}} /* :: */
277 #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}} /* ::1 */
279 struct sockaddr_in6
{
283 uint32_t sin6_flowinfo
;
284 struct in6_addr sin6_addr
;
285 uint32_t sin6_scope_id
;
288 /* IPv6 socket options */
289 #define IPV6_V6ONLY 26 /* Restrict AF_INET6 sockets to IPv6 only. */