KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
in.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 netinet/in.h
4 Copyright (C) 2006, 2007, 2010 Lawrence Sebald
5
6*/
7
8/** \file netinet/in.h
9 \brief Definitions for the Internet address family.
10 \ingroup networking_ip
11
12 This file contains the standard definitions (as directed by the POSIX 2008
13 standard) for internet-related functionality in the AF_INET address family.
14 This does is not guaranteed to have everything that one might have in a
15 fully-standard compliant implementation of the POSIX standard.
16
17 \author Lawrence Sebald
18*/
19
20#ifndef __NETINET_IN_H
21#define __NETINET_IN_H
22
23#include <sys/cdefs.h>
24
25__BEGIN_DECLS
26
27/* Bring in <inttypes.h> to grab the uint16_t and uint32_t types (for in_port_t
28 and in_addr_t below), along with uint8_t. Bring in <sys/socket.h> for the
29 sa_family_t type, as required. IEEE Std 1003.1-2008 specifically states that
30 <netinet/in.h> can make visible all symbols from both <inttypes.h> and
31 <sys/socket.h>. */
32#include <inttypes.h>
33#include <sys/socket.h>
34
35/** \brief 16-bit type used to store a value for an internet port.
36 \ingroup networking_ip
37*/
38typedef uint16_t in_port_t;
39
40/** \brief 32-bit value used to store an IPv4 address.
41 \ingroup networking_ipv4
42*/
43typedef uint32_t in_addr_t;
44
45/** \brief Structure used to store an IPv4 address.
46 \headerfile netinet/in.h
47 \ingroup networking_ipv4
48*/
52
53/** \brief Structure used to store an IPv6 address.
54 \headerfile netinet/in.h
55 \ingroup networking_ipv6
56*/
57struct in6_addr {
58 union {
59 uint8_t __s6_addr8[16];
60 uint16_t __s6_addr16[8];
61 uint32_t __s6_addr32[4];
62 uint64_t __s6_addr64[2];
64#define s6_addr __s6_addr.__s6_addr8
65};
66
67/* Bring in <arpa/inet.h> to make ntohl/ntohs/htonl/htons visible, as per IEEE
68 Std 1003.1-2008 (the standard specifically states that <netinet/in.h> may
69 make all symbols from <arpa/inet.h> visible. The <arpa/inet.h> header
70 actually needs the stuff above, so that's why we include it here. */
71#include <arpa/inet.h>
72
73/** \brief Structure used to store an IPv4 address for a socket.
74 \ingroup networking_ipv4
75
76 This structure is the standard way to set up addresses for sockets in the
77 AF_INET address family. Generally you will not send one of these directly
78 to a function, but rather will cast it to a struct sockaddr. Also, this
79 structure contains the old sin_zero member which is no longer required by
80 the standard (for compatibility with applications that expect it).
81
82 \headerfile netinet/in.h
83*/
85 /** \brief Family for the socket. Must be AF_INET. */
87
88 /** \brief Port for the socket. Must be in network byte order. */
90
91 /** \brief Address for the socket. Must be in network byte order. */
93
94 /** \brief Empty space, ignored for all intents and purposes. */
95 unsigned char sin_zero[8];
96};
97
98/** \brief Structure used to store an IPv6 address for a socket.
99 \ingroup networking_ipv6
100
101 This structure is the standard way to set up addresses for sockets in the
102 AF_INET6 address family. Generally you will not send one of these directly
103 to a function, but rather will cast it to a struct sockaddr.
104
105 \headerfile netinet/in.h
106 */
108 /** \brief Family for the socket. Must be AF_INET6. */
110
111 /** \brief Port for the socket. Must be in network byte order. */
113
114 /** \brief Traffic class and flow information. */
116
117 /** \brief Address for the socket. Must be in network byte order. */
119
120 /** \brief Set of interfaces for a scope. */
122};
123
124/** \brief Local IPv4 host address.
125 \ingroup networking_ipv4
126
127 This address can be used by many things if you prefer to not specify the
128 local address, and would rather it be detected automatically.
129*/
130#define INADDR_ANY 0x00000000
131
132/** \brief IPv4 broadcast address.
133 \ingroup networking_ipv4
134
135 This address is the normal IPv4 broadcast address (255.255.255.255).
136*/
137#define INADDR_BROADCAST 0xFFFFFFFF
138
139/** \brief IPv4 error address.
140 \ingroup networking_ipv4
141
142 This address is non-standard, but is available on many systems. It is used
143 to detect failure from some functions that normally return addresses (such
144 as the inet_addr function).
145*/
146#define INADDR_NONE 0xFFFFFFFF
147
148/** \brief Initialize an IPv6 local host address.
149 \ingroup networking_ipv6
150
151 This macro can be used to initialize a struct in6_addr to any local address.
152 It functions similarly to INADDR_ANY for IPv4.
153*/
154#define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, \
155 0, 0, 0, 0, 0, 0, 0, 0 }}}
156
157/** \brief Initialize an IPv6 loopback address.
158 \ingroup networking_ipv6
159
160 This macro can be used to initialize a struct in6_addr to the loopback
161 address.
162*/
163#define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, \
164 0, 0, 0, 0, 0, 0, 0, 1 }}}
165
166/** \brief IPv6 local host address.
167 \ingroup networking_ipv6
168
169 This constant variable contains the IPv6 local host address.
170*/
171extern const struct in6_addr in6addr_any;
172
173/** \brief IPv6 loopback address.
174 \ingroup networking_ipv6
175
176 This constant variable contains the IPv6 loopback address.
177*/
178extern const struct in6_addr in6addr_loopback;
179
180/** \brief Length of a string form of a maximal IPv4 address.
181 \ingroup networking_ipv4
182*/
183#define INET_ADDRSTRLEN 16
184
185/** \brief Length of a string form of a maximal IPv6 address.
186 \ingroup networking_ipv6
187*/
188#define INET6_ADDRSTRLEN 46
189
190/** \brief Internet Protocol Version 4.
191 \ingroup networking_ip
192*/
193#define IPPROTO_IP 0
194
195/** \brief Internet Control Message Protocol.
196 \ingroup networking_ip
197*/
198#define IPPROTO_ICMP 1
199
200/** \brief Transmission Control Protocol.
201 \ingroup networking_ip
202*/
203#define IPPROTO_TCP 6
204
205/** \brief User Datagram Protocol.
206 \ingroup networking_ip
207*/
208#define IPPROTO_UDP 17
209
210/** \brief Internet Protocol Version 6.
211 \ingroup networking_ip
212*/
213#define IPPROTO_IPV6 41
214
215/** \brief Lightweight User Datagram Protocol.
216 \ingroup networking_ip
217*/
218#define IPPROTO_UDPLITE 136
219
220/** \defgroup ipv4_opts Options
221 \brief Options for v4 of the Internet Protocol
222 \ingroup networking_ipv4
223
224 These are the various socket-level options that can be accessed with the
225 setsockopt() and getsockopt() functions for the IPPROTO_IP level value.
226
227 As there isn't really a full standard list of these defined in the SUS
228 (apparently), only ones that we support are listed here.
229
230 \see so_opts
231 \see ipv6_opts
232 \see udp_opts
233 \see udplite_opts
234 \see tcp_opts
235
236 @{
237*/
238
239#define IP_TTL 24 /**< \brief TTL for unicast (get/set) */
240
241/** @} */
242
243/** \defgroup ipv6_opts Options
244 \brief Options for v6 of the Internet Protocol
245 \ingroup networking_ipv6
246
247 These are the various socket-level options that can be accessed with the
248 setsockopt() and getsockopt() functions for the IPPROTO_IPV6 level value.
249
250 Not all of these are currently supported, but they are listed for
251 completeness.
252
253 \see so_opts
254 \see ipv4_opts
255 \see udp_opts
256 \see udplite_opts
257 \see tcp_opts
258
259 @{
260*/
261
262#define IPV6_JOIN_GROUP 17 /**< \brief Join a multicast group (set) */
263#define IPV6_LEAVE_GROUP 18 /**< \brief Leave a multicast group (set) */
264#define IPV6_MULTICAST_HOPS 19 /**< \brief Hop limit for multicast (get/set) */
265#define IPV6_MULTICAST_IF 20 /**< \brief Multicast interface (get/set) */
266#define IPV6_MULTICAST_LOOP 21 /**< \brief Multicasts loopback (get/set) */
267#define IPV6_UNICAST_HOPS 22 /**< \brief Hop limit for unicast (get/set) */
268#define IPV6_V6ONLY 23 /**< \brief IPv6 only -- no IPv4 (get/set) */
269
270/** @} */
271
272/** \brief Test if an IPv6 Address is unspecified.
273 \ingroup networking_ipv6
274
275 This macro tests whether an IPv6 address (struct in6_addr *) is an
276 unspecified address.
277
278 \param a The address to test (struct in6_addr *)
279
280 \return Nonzero if the address is unspecified, 0 otherwise.
281*/
282#define IN6_IS_ADDR_UNSPECIFIED(a) \
283 ((a)->__s6_addr.__s6_addr32[0] == 0 && \
284 (a)->__s6_addr.__s6_addr32[1] == 0 && \
285 (a)->__s6_addr.__s6_addr32[2] == 0 && \
286 (a)->__s6_addr.__s6_addr32[3] == 0)
287
288/** \brief Test if an IPv6 Address is a loopback address.
289 \ingroup networking_ipv6
290
291 This macro tests whether an IPv6 address (struct in6_addr *) is a
292 loopback address.
293
294 \param a The address to test (struct in6_addr *)
295
296 \return Nonzero if the address is a loopback, 0 otherwise.
297*/
298#define IN6_IS_ADDR_LOOPBACK(a) \
299 ((a)->__s6_addr.__s6_addr32[0] == 0 && \
300 (a)->__s6_addr.__s6_addr32[1] == 0 && \
301 (a)->__s6_addr.__s6_addr32[2] == 0 && \
302 (a)->__s6_addr.__s6_addr16[6] == 0 && \
303 (a)->__s6_addr.__s6_addr8[14] == 0 && \
304 (a)->__s6_addr.__s6_addr8[15] == 1)
305
306/** \brief Test if an IPv6 Address is an IPv4 mapped address.
307 \ingroup networking_ipv6
308
309 This macro tests whether an IPv6 address (struct in6_addr *) is an IPv4
310 mapped address.
311
312 \param a The address to test (struct in6_addr *)
313
314 \return Nonzero if the address is IPv4 mapped, 0 otherwise.
315*/
316#define IN6_IS_ADDR_V4MAPPED(a) \
317 ((a)->__s6_addr.__s6_addr32[0] == 0 && \
318 (a)->__s6_addr.__s6_addr32[1] == 0 && \
319 (a)->__s6_addr.__s6_addr16[4] == 0 && \
320 (a)->__s6_addr.__s6_addr16[5] == 0xFFFF)
321
322/** \brief Test if an IPv6 Address is an IPv4 compatibility address.
323 \ingroup networking_ipv6
324
325 This macro tests whether an IPv6 address (struct in6_addr *) is an IPv4
326 compatibility address.
327
328 \param a The address to test (struct in6_addr *)
329
330 \return Nonzero if the address is IPv4 compat, 0 otherwise.
331*/
332#define IN6_IS_ADDR_V4COMPAT(a) \
333 ((a)->__s6_addr.__s6_addr32[0] == 0 && \
334 (a)->__s6_addr.__s6_addr32[1] == 0 && \
335 (a)->__s6_addr.__s6_addr32[2] == 0 && \
336 (a)->__s6_addr.__s6_addr32[3] != 0 && \
337 (a)->__s6_addr.__s6_addr8[15] != 1)
338
339/** \brief Test if an IPv6 Address is a link-local address.
340 \ingroup networking_ipv6
341
342 This macro tests whether an IPv6 address (struct in6_addr *) is a link-local
343 address.
344
345 \param a The address to test (struct in6_addr *)
346
347 \return Nonzero if the address is link-local, 0 otherwise.
348*/
349#define IN6_IS_ADDR_LINKLOCAL(a) \
350 (((a)->__s6_addr.__s6_addr8[0] == 0xFE) && \
351 (((a)->__s6_addr.__s6_addr8[1] & 0xC0) == 0x80))
352
353/** \brief Test if an IPv6 Address is a site-local address.
354 \ingroup networking_ipv6
355
356 This macro tests whether an IPv6 address (struct in6_addr *) is a site-local
357 address.
358
359 \param a The address to test (struct in6_addr *)
360
361 \return Nonzero if the address is site-local, 0 otherwise.
362*/
363#define IN6_IS_ADDR_SITELOCAL(a) \
364 (((a)->__s6_addr.__s6_addr8[0] == 0xFE) && \
365 (((a)->__s6_addr.__s6_addr8[1] & 0xC0) == 0xC0))
366
367/** \brief Test if an IPv6 Address is a multicast address.
368 \ingroup networking_ipv6
369
370 This macro tests whether an IPv6 address (struct in6_addr *) is a multicast
371 address.
372
373 \param a The address to test (struct in6_addr *)
374
375 \return Nonzero if the address is multicast, 0 otherwise.
376*/
377#define IN6_IS_ADDR_MULTICAST(a) \
378 ((a)->__s6_addr.__s6_addr8[0] == 0xFF)
379
380/** \brief Test if an IPv6 Address is a node-local multicast address.
381 \ingroup networking_ipv6
382
383 This macro tests whether an IPv6 address (struct in6_addr *) is a node-local
384 multicast address.
385
386 \param a The address to test (struct in6_addr *)
387
388 \return Nonzero if the address is a node-local multicast
389 address, 0 otherwise.
390*/
391#define IN6_IS_ADDR_MC_NODELOCAL(a) \
392 (IN6_IS_ADDR_MULTICAST(a) && \
393 (((a)->__s6_addr.__s6_addr8[1] & 0x0F) == 0x01))
394
395/** \brief Test if an IPv6 Address is a link-local multicast address.
396 \ingroup networking_ipv6
397
398 This macro tests whether an IPv6 address (struct in6_addr *) is a link-local
399 multicast address.
400
401 \param a The address to test (struct in6_addr *)
402
403 \return Nonzero if the address is a link-local multicast
404 address, 0 otherwise.
405*/
406#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
407 (IN6_IS_ADDR_MULTICAST(a) && \
408 (((a)->__s6_addr.__s6_addr8[1] & 0x0F) == 0x02))
409
410/** \brief Test if an IPv6 Address is a site-local multicast address.
411 \ingroup networking_ipv6
412
413 This macro tests whether an IPv6 address (struct in6_addr *) is a site-local
414 multicast address.
415
416 \param a The address to test (struct in6_addr *)
417
418 \return Nonzero if the address is a site-local multicast
419 address, 0 otherwise.
420*/
421#define IN6_IS_ADDR_MC_SITELOCAL(a) \
422 (IN6_IS_ADDR_MULTICAST(a) && \
423 (((a)->__s6_addr.__s6_addr8[1] & 0x0F) == 0x05))
424
425/** \brief Test if an IPv6 Address is an organization-local multicast address.
426 \ingroup networking_ipv6
427
428 This macro tests whether an IPv6 address (struct in6_addr *) is an
429 organization-local multicast address.
430
431 \param a The address to test (struct in6_addr *)
432
433 \return Nonzero if the address is an organization-local
434 multicast address, 0 otherwise.
435*/
436#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
437 (IN6_IS_ADDR_MULTICAST(a) && \
438 (((a)->__s6_addr.__s6_addr8[1] & 0x0F) == 0x08))
439
440/** \brief Test if an IPv6 Address is a global multicast address.
441 \ingroup networking_ipv6
442
443 This macro tests whether an IPv6 address (struct in6_addr *) is a global
444 multicast address.
445
446 \param a The address to test (struct in6_addr *)
447
448 \return Nonzero if the address is a global multicast address,
449 0 otherwise.
450*/
451#define IN6_IS_ADDR_MC_GLOBAL(a) \
452 (IN6_IS_ADDR_MULTICAST(a) && \
453 (((a)->__s6_addr.__s6_addr8[1] & 0x0F) == 0x0E))
454
455__END_DECLS
456
457#endif /* __NETINET_IN_H */
uint16_t in_port_t
16-bit type used to store a value for an internet port.
Definition in.h:38
uint32_t in_addr_t
32-bit value used to store an IPv4 address.
Definition in.h:43
const struct in6_addr in6addr_loopback
IPv6 loopback address.
const struct in6_addr in6addr_any
IPv6 local host address.
__uint8_t sa_family_t
Socket address family type.
Definition socket.h:42
Definitions for internet operations.
Main sockets header.
Structure used to store an IPv6 address.
Definition in.h:57
union in6_addr::@1 __s6_addr
uint8_t __s6_addr8[16]
Definition in.h:59
uint16_t __s6_addr16[8]
Definition in.h:60
uint64_t __s6_addr64[2]
Definition in.h:62
uint32_t __s6_addr32[4]
Definition in.h:61
Structure used to store an IPv4 address.
Definition in.h:49
in_addr_t s_addr
Definition in.h:50
Structure used to store an IPv6 address for a socket.
Definition in.h:107
in_port_t sin6_port
Port for the socket.
Definition in.h:112
struct in6_addr sin6_addr
Address for the socket.
Definition in.h:118
uint32_t sin6_flowinfo
Traffic class and flow information.
Definition in.h:115
uint32_t sin6_scope_id
Set of interfaces for a scope.
Definition in.h:121
sa_family_t sin6_family
Family for the socket.
Definition in.h:109
Structure used to store an IPv4 address for a socket.
Definition in.h:84
unsigned char sin_zero[8]
Empty space, ignored for all intents and purposes.
Definition in.h:95
struct in_addr sin_addr
Address for the socket.
Definition in.h:92
sa_family_t sin_family
Family for the socket.
Definition in.h:86
in_port_t sin_port
Port for the socket.
Definition in.h:89