in.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-15 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
23 #ifndef NETINET_IN_H
24 #define NETINET_IN_H
25 
26 #include <inttypes.h>
27 #include <sys/socket.h>
28 
29 #include "net/protnum.h"
30 #include "net/ipv6/addr.h"
31 #include "sys/bytes.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define INET_ADDRSTRLEN (16)
38 #define INET6_ADDRSTRLEN (46)
43 #define INADDR_ANY ((in_addr_t)0x00000000)
44 
48 #define INADDR_BROADCAST ((in_addr_t)0xffffffff)
49 
53 #define IN6ADDR_ANY_INIT IPV6_ADDR_UNSPECIFIED
54 
58 #define IN6ADDR_LOOPBACK_INIT IPV6_ADDR_LOOPBACK
59 
72 #define IN6_IS_ADDR_UNSPECIFIED(addr) ((int)(ipv6_addr_is_unspecified((const ipv6_addr_t *)(addr))))
73 
82 #define IN6_IS_ADDR_LOOPBACK(addr) ((int)(ipv6_addr_is_loopback((const ipv6_addr_t *)(addr))))
83 
92 #define IN6_IS_ADDR_MULTICAST(addr) ((int)(ipv6_addr_is_multicast((const ipv6_addr_t *)(addr))))
93 
102 #define IN6_IS_ADDR_LINKLOCAL(addr) ((int)(ipv6_addr_is_link_local((const ipv6_addr_t *)addr)))
103 
112 #define IN6_IS_ADDR_SITELOCAL(addr) ((int)(ipv6_addr_is_site_local((const ipv6_addr_t *)addr)))
113 
122 #define IN6_IS_ADDR_V4MAPPED(addr) ((int)(ipv6_addr_is_ipv4_mapped((const ipv6_addr_t *)addr)))
123 
132 #define IN6_IS_ADDR_V4COMPAT(addr) ((int)(ipv6_addr_is_ipv4_compat((const ipv6_addr_t *)addr)))
133 
142 #define IN6_IS_ADDR_MC_NODELOCAL(addr) (IN6_IS_ADDR_MULTICAST(addr) && \
143  (int)((addr->s6_addr[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_IF_LOCAL))
144 
153 #define IN6_IS_ADDR_MC_LINKLOCAL(addr) (IN6_IS_ADDR_MULTICAST(addr) && \
154  (int)((addr->s6_addr[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_LINK_LOCAL))
155 
164 #define IN6_IS_ADDR_MC_SITELOCAL(addr) (IN6_IS_ADDR_MULTICAST(addr) && \
165  (int)((addr->s6_addr[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_SITE_LOCAL))
166 
175 #define IN6_IS_ADDR_MC_ORGLOCAL(addr) (IN6_IS_ADDR_MULTICAST(addr) && \
176  (int)((addr->s6_addr[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_ORG_LOCAL))
177 
186 #define IN6_IS_ADDR_MC_GLOBAL(addr) (IN6_IS_ADDR_MULTICAST(addr) && \
187  (int)((addr->s6_addr[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_GLOBAL))
188 
194 #define IPPROTO_IP (PROTNUM_IPV4)
195 #define IPPROTO_IPV6 (PROTNUM_IPV6)
196 #define IPPROTO_ICMP (PROTNUM_ICMP)
197 #define IPPROTO_ICMPV6 (PROTNUM_ICMPV6)
198 #define IPPROTO_RAW (PROTNUM_RESERVED)
199 #define IPPROTO_TCP (PROTNUM_TCP)
200 #define IPPROTO_UDP (PROTNUM_UDP)
207 typedef uint16_t in_port_t;
208 typedef uint32_t in_addr_t;
213 struct in_addr {
215 };
216 
220 struct in6_addr {
221  uint8_t s6_addr[16];
222 };
223 
228 struct sockaddr_in {
231  struct in_addr sin_addr;
232 };
233 
238 struct sockaddr_in6 {
244  uint32_t sin6_flowinfo;
246  uint32_t sin6_scope_id;
247 };
248 
252 struct ipv6_mreq {
254  unsigned ipv6mr_interface;
255 };
256 
260 extern const struct in6_addr in6addr_any;
261 
265 extern const struct in6_addr in6addr_loopback;
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
274 #endif /* NETINET_IN_H */
in_addr_t
uint32_t in_addr_t
IPv4 address type.
Definition: in.h:208
protnum.h
Protocol number definitions.
in_port_t
uint16_t in_port_t
Internet port type.
Definition: in.h:207
sockaddr_in6::sin6_port
in_port_t sin6_port
Port number.
Definition: in.h:243
addr.h
Definitions for IPv6 addresses.
in6addr_any
const struct in6_addr in6addr_any
IPv6 socket address for the wildcard address.
sockaddr_in
IPv4 socket address type.
Definition: in.h:228
in6_addr
IPv6 address structure type.
Definition: in.h:220
sockaddr_in6::sin6_family
sa_family_t sin6_family
Protocol family, always AF_INET6.
Definition: in.h:242
ipv6_mreq::ipv6mr_interface
unsigned ipv6mr_interface
interface index, leave 0 for default
Definition: in.h:254
sockaddr_in6
IPv6 socket address type.
Definition: in.h:238
in6addr_loopback
const struct in6_addr in6addr_loopback
IPv6 socket address for the loopback address.
in_addr
IPv4 address structure type.
Definition: in.h:213
in_addr::s_addr
in_addr_t s_addr
an IPv4 address
Definition: in.h:214
sockaddr_in6::sin6_scope_id
uint32_t sin6_scope_id
Set of interfaces for a scope.
Definition: in.h:246
sockaddr_in6::sin6_flowinfo
uint32_t sin6_flowinfo
IPv6 traffic class and flow information.
Definition: in.h:244
sa_family_t
unsigned short sa_family_t
address family type
Definition: socket.h:120
in6_addr::s6_addr
uint8_t s6_addr[16]
unsigned 8-bit integer array
Definition: in.h:221
socket.h
Main socket header.
bytes.h
System-internal byte operations.
sockaddr_in6::sin6_addr
struct in6_addr sin6_addr
IPv6 address.
Definition: in.h:245
sockaddr_in::sin_port
in_port_t sin_port
Port number.
Definition: in.h:230
sockaddr_in::sin_addr
struct in_addr sin_addr
IPv4 address.
Definition: in.h:231
ipv6_mreq
IPv6 multicast request.
Definition: in.h:252
inttypes.h
Adds include for missing inttype definitions.
sockaddr_in::sin_family
sa_family_t sin_family
Protocol family, always AF_INET.
Definition: in.h:229
ipv6_mreq::ipv6mr_multiaddr
struct in6_addr ipv6mr_multiaddr
an IPv6 multicast address
Definition: in.h:253