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 ntohl(x) BELong(x)
129 #define ntohs(x) BEWord(x)
130 #define htonl(x) MakeBELong(x)
131 #define htons(x) MakeBEWord(x)
133 #define NTOHL(x) ((x) = ntohl(x))
134 #define NTOHS(x) ((x) = ntohs(x))
135 #define HTONL(x) ((x) = htonl(x))
136 #define HTONS(x) ((x) = htons(x))
140 * Constants and structures defined by the internet system,
141 * Per RFC 790, September 1981.
147 #define IPPROTO_IP 0 /* dummy for IP */
148 #define IPPROTO_ICMP 1 /* control message protocol */
149 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
150 #define IPPROTO_TCP 6 /* tcp */
151 #define IPPROTO_EGP 8 /* exterior gateway protocol */
152 #define IPPROTO_PUP 12 /* pup */
153 #define IPPROTO_UDP 17 /* user datagram protocol */
154 #define IPPROTO_IDP 22 /* xns idp */
155 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
156 #define IPPROTO_IPV6 41 /* IPv6 protocol */
157 #define IPPROTO_EON 80 /* ISO cnlp */
158 #define IPPROTO_UDPLITE 136 /* UDP Lite */
160 #define IPPROTO_RAW 255 /* raw IP packet */
161 #define IPPROTO_MAX 256
165 * Local port number conventions:
166 * Ports < IPPORT_RESERVED are reserved for
167 * privileged processes (e.g. root).
168 * Ports > IPPORT_USERRESERVED are reserved
169 * for servers, not necessarily privileged.
171 #define IPPORT_RESERVED 1024
172 #define IPPORT_USERRESERVED 5000
175 * Internet address (a structure for historical reasons)
182 * Definitions of bits in internet address integers.
183 * On subnets, the decomposition of addresses to host and net parts
184 * is done according to subnet mask, not the masks here.
186 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
187 #define IN_CLASSA_NET 0xff000000
188 #define IN_CLASSA_NSHIFT 24
189 #define IN_CLASSA_HOST 0x00ffffff
190 #define IN_CLASSA_MAX 128
192 #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
193 #define IN_CLASSB_NET 0xffff0000
194 #define IN_CLASSB_NSHIFT 16
195 #define IN_CLASSB_HOST 0x0000ffff
196 #define IN_CLASSB_MAX 65536
198 #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
199 #define IN_CLASSC_NET 0xffffff00
200 #define IN_CLASSC_NSHIFT 8
201 #define IN_CLASSC_HOST 0x000000ff
203 #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
204 #define IN_MULTICAST(i) IN_CLASSD(i)
206 #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000)
207 #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000)
209 #define INADDR_ANY (u_long)0x00000000
210 #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */
211 #define INADDR_LOOPBACK (u_long)0x7f000001 /* loopback address */
212 #if !defined(KERNEL) || defined(AMITCP)
213 #define INADDR_NONE 0xffffffff /* -1 return */
216 #define IN_LOOPBACKNET 127 /* official! */
219 * Socket address, internet style.
225 struct in_addr sin_addr
;
230 * Structure used to describe IP options.
231 * Used to store options internally, to pass them to a process,
232 * or to restore options retrieved earlier.
233 * The ip_dst is used for the first-hop gateway when using a source route
234 * (this gets put into the header proper).
237 struct in_addr ip_dst
; /* first hop, 0 w/o src rt */
238 char ip_opts
[40]; /* actually variable in size */
242 * Options for use with [gs]etsockopt at the IP level.
243 * First word of comment is data type; bool is stored in int.
245 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */
246 #define IP_HDRINCL 2 /* int; header is included with data (raw) */
247 #define IP_TOS 3 /* int; IP type of service and precedence */
248 #define IP_TTL 4 /* int; IP time to live */
249 #define IP_RECVOPTS 5 /* bool; receive all IP options w/datagram */
250 #define IP_RECVRETOPTS 6 /* bool; receive IP options for response */
251 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/datagram */
252 #define IP_RETOPTS 8 /* ip_opts; set/get IP per-packet options */
255 struct in_addr
in_makeaddr(u_long net
,
257 u_long
in_netof(struct in_addr in
);
258 u_long
in_lnaof(struct in_addr in
);
261 /* IPv6 structures */
265 uint16_t u16_addr
[8];
266 uint32_t u32_addr
[4];
268 #define s6_addr un.u8_addr
271 #define IN6ADDR_ANY_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}} /* :: */
272 #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}} /* ::1 */
274 struct sockaddr_in6
{
278 uint32_t sin6_flowinfo
;
279 struct in6_addr sin6_addr
;
280 uint32_t sin6_scope_id
;
283 /* IPv6 socket options */
284 #define IPV6_V6ONLY 26 /* Restrict AF_INET6 sockets to IPv6 only. */