26#ifndef NET_IPV6_ADDR_H
27#define NET_IPV6_ADDR_H
42#define IPV6_ADDR_BIT_LEN (128)
44#ifdef MODULE_IPV4_ADDR
48#define IPV6_ADDR_MAX_STR_LEN (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))
53#define IPV6_ADDR_MAX_STR_LEN (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"))
67#define IPV6_ADDR_SITE_LOCAL_PREFIX (0xfec0)
86#define IPV6_ADDR_UNSPECIFIED {{ 0x00, 0x00, 0x00, 0x00, \
87 0x00, 0x00, 0x00, 0x00, \
88 0x00, 0x00, 0x00, 0x00, \
89 0x00, 0x00, 0x00, 0x00 }}
98#define IPV6_ADDR_LOOPBACK {{ 0x00, 0x00, 0x00, 0x00, \
99 0x00, 0x00, 0x00, 0x00, \
100 0x00, 0x00, 0x00, 0x00, \
101 0x00, 0x00, 0x00, 0x01 }}
109#define IPV6_ADDR_LINK_LOCAL_PREFIX {{ 0xfe, 0x80, 0x00, 0x00, \
110 0x00, 0x00, 0x00, 0x00, \
111 0x00, 0x00, 0x00, 0x00, \
112 0x00, 0x00, 0x00, 0x00 }}
122#define IPV6_ADDR_ALL_NODES_IF_LOCAL {{ 0xff, 0x01, 0x00, 0x00, \
123 0x00, 0x00, 0x00, 0x00, \
124 0x00, 0x00, 0x00, 0x00, \
125 0x00, 0x00, 0x00, 0x01 }}
135#define IPV6_ADDR_ALL_NODES_LINK_LOCAL {{ 0xff, 0x02, 0x00, 0x00, \
136 0x00, 0x00, 0x00, 0x00, \
137 0x00, 0x00, 0x00, 0x00, \
138 0x00, 0x00, 0x00, 0x01 }}
148#define IPV6_ADDR_ALL_ROUTERS_IF_LOCAL {{ 0xff, 0x01, 0x00, 0x00, \
149 0x00, 0x00, 0x00, 0x00, \
150 0x00, 0x00, 0x00, 0x00, \
151 0x00, 0x00, 0x00, 0x02 }}
161#define IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL {{ 0xff, 0x02, 0x00, 0x00, \
162 0x00, 0x00, 0x00, 0x00, \
163 0x00, 0x00, 0x00, 0x00, \
164 0x00, 0x00, 0x00, 0x02 }}
174#define IPV6_ADDR_ALL_ROUTERS_SITE_LOCAL {{ 0xff, 0x05, 0x00, 0x00, \
175 0x00, 0x00, 0x00, 0x00, \
176 0x00, 0x00, 0x00, 0x00, \
177 0x00, 0x00, 0x00, 0x02 }}
187#define IPV6_ADDR_SOLICITED_NODE_PREFIX {{ 0xff, 0x02, 0x00, 0x00, \
188 0x00, 0x00, 0x00, 0x00, \
189 0x00, 0x00, 0x00, 0x01, \
190 0xff, 0x00, 0x00, 0x00 }}
205#define IPV6_ADDR_MCAST_FLAG_TRANSIENT (0x01)
214#define IPV6_ADDR_MCAST_FLAG_PREFIX_BASED (0x02)
223#define IPV6_ADDR_MCAST_FLAG_EMBED_ON_RP (0x04)
235#define IPV6_ADDR_MCAST_SCP_IF_LOCAL (0x1)
236#define IPV6_ADDR_MCAST_SCP_LINK_LOCAL (0x2)
248#define IPV6_ADDR_MCAST_SCP_REALM_LOCAL (0x3)
249#define IPV6_ADDR_MCAST_SCP_ADMIN_LOCAL (0x4)
250#define IPV6_ADDR_MCAST_SCP_SITE_LOCAL (0x5)
251#define IPV6_ADDR_MCAST_SCP_ORG_LOCAL (0x8)
252#define IPV6_ADDR_MCAST_SCP_GLOBAL (0xe)
375 (addr->
u16[5].
u16 == 0xffff));
392 return (addr->
u8[0] == 0xff);
455 return ((addr->
u8[0] == 0xfc) || (addr->
u8[0] == 0xfd));
630 memcpy(&addr->
u64[1], iid,
sizeof(addr->
u64[1]));
648 addr->
u8[1] = (((uint8_t)flags) << 4) | (((uint8_t) scope) & 0x0f);
665 addr->
u8[1] = (uint8_t)scope;
682 addr->
u8[1] = (uint8_t)scope;
701 out->
u8[13] = in->
u8[13];
847 const char *separator);
Functions to work with different byte orders.
static network_uint64_t byteorder_htonll(uint64_t v)
Convert from host byte order to network byte order, 64 bit.
static uint16_t byteorder_ntohs(network_uint16_t v)
Convert from network byte order to host byte order, 16 bit.
static network_uint32_t byteorder_htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
static void ipv6_addr_set_unspecified(ipv6_addr_t *addr)
Sets addr dynamically to the unspecified IPv6 address (::).
static bool ipv6_addr_is_multicast(const ipv6_addr_t *addr)
Check if addr is a multicast address.
const ipv6_addr_t ipv6_addr_all_routers_link_local
static void ipv6_addr_set_loopback(ipv6_addr_t *addr)
Sets addr dynamically to the loopback IPv6 address (::1).
static bool ipv6_addr_is_loopback(const ipv6_addr_t *addr)
Checks if addr is a loopback address.
static bool ipv6_addr_is_global(const ipv6_addr_t *addr)
Check if addr is global unicast address.
char * ipv6_addr_to_str(char *result, const ipv6_addr_t *addr, uint8_t result_len)
Converts an IPv6 address to its string representation.
void ipv6_addrs_print(const ipv6_addr_t *addrs, size_t num, const char *separator)
Print IPv6 addresses to stdout.
#define IPV6_ADDR_MCAST_SCP_SITE_LOCAL
site-local scope
const ipv6_addr_t ipv6_addr_all_nodes_link_local
ipv6_addr_t * ipv6_addr_from_buf(ipv6_addr_t *result, const char *addr, size_t addr_len)
Converts an IPv6 address from a buffer of characters to a byte-represented IPv6 address.
static void ipv6_addr_set_solicited_nodes(ipv6_addr_t *out, const ipv6_addr_t *in)
Set out to the solicited-node multicast address computed from in.
static void ipv6_addr_set_link_local_prefix(ipv6_addr_t *addr)
Sets the first 64 bit of addr to link local prefix (fe08::/64).
#define IPV6_ADDR_MCAST_SCP_LINK_LOCAL
link-local scope
static void ipv6_addr_set_aiid(ipv6_addr_t *addr, uint8_t *iid)
Sets the 64-bit interface ID (as array) of a unicast or anycast IPv6 address.
#define IPV6_ADDR_SITE_LOCAL_PREFIX
The first 10 bits of a site-local IPv6 unicast address.
static int ipv6_addr_split_prefix(char *addr_str)
split IPv6 prefix string representation
const ipv6_addr_t ipv6_addr_all_routers_site_local
void ipv6_addr_print(const ipv6_addr_t *addr)
Print IPv6 address to stdout.
const ipv6_addr_t ipv6_addr_all_nodes_if_local
const ipv6_addr_t ipv6_addr_loopback
void ipv6_addr_init_iid(ipv6_addr_t *out, const uint8_t *iid, uint8_t bits)
Sets the last bits of IPv6 address out to iid.
#define IPV6_ADDR_MCAST_SCP_GLOBAL
global scope
static bool ipv6_addr_is_link_local(const ipv6_addr_t *addr)
Check if addr is a link-local address.
static bool ipv6_addr_is_site_local(const ipv6_addr_t *addr)
Checks if addr is a site-local address.
char * ipv6_addr_split_str(char *addr_str, char separator)
split IPv6 address string representation and return remaining string
static void ipv6_addr_set_all_nodes_multicast(ipv6_addr_t *addr, unsigned int scope)
Sets addr dynamically to an all nodes multicast IPv6 address (ff0S::1, where S is the scope).
static void ipv6_addr_init(ipv6_addr_t *out, uint64_t prefix, uint64_t iid)
Sets IPv6 address out with a given prefix and interface ID.
bool ipv6_addr_equal(const ipv6_addr_t *a, const ipv6_addr_t *b)
Checks if two IPv6 addresses are equal.
ipv6_addr_t * ipv6_addr_from_str(ipv6_addr_t *result, const char *addr)
Converts an IPv6 address string representation to a byte-represented IPv6 address.
const ipv6_addr_t ipv6_addr_link_local_prefix
static bool ipv6_addr_is_ipv4_compat(const ipv6_addr_t *addr)
Checks if addr is a IPv4-compatible IPv6 address.
int ipv6_prefix_from_str(ipv6_addr_t *result, const char *prefix)
Converts an IPv6 prefix string representation to a byte-represented IPv6 address.
static void ipv6_addr_set_all_routers_multicast(ipv6_addr_t *addr, unsigned int scope)
Sets addr dynamically to an all routers multicast IPv6 address (ff0S::2, where S is the scope).
static bool ipv6_addr_is_unique_local_unicast(const ipv6_addr_t *addr)
Check if addr is unique local unicast address.
static char * ipv6_addr_split_iface(char *addr_str)
split IPv6 address + interface specifier
void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix, uint8_t bits)
Sets IPv6 address out with the first bits taken from prefix and leaves the remaining bits untouched.
const ipv6_addr_t ipv6_addr_unspecified
In-memory constants of defined addresses and prefixes.
static bool ipv6_addr_is_solicited_node(const ipv6_addr_t *addr)
Check if addr is solicited-node multicast address.
const ipv6_addr_t ipv6_addr_solicited_node_prefix
int ipv6_addr_split_int(char *addr_str, char separator, int _default)
split IPv6 address string representation
static bool ipv6_addr_is_ipv4_mapped(const ipv6_addr_t *addr)
Checks if addr is a IPv4-mapped IPv6 address.
static void ipv6_addr_set_multicast(ipv6_addr_t *addr, unsigned int flags, unsigned int scope)
Sets the bits for an address required to be a multicast address.
uint8_t ipv6_addr_match_prefix(const ipv6_addr_t *a, const ipv6_addr_t *b)
Checks up to which bit-count two IPv6 addresses match in their prefix.
static void ipv6_addr_set_iid(ipv6_addr_t *addr, uint64_t iid)
Sets the 64-bit interface ID (as integer) of a unicast or anycast IPv6 address.
static bool ipv6_addr_is_unspecified(const ipv6_addr_t *addr)
Checks if addr is unspecified (all zero).
const ipv6_addr_t ipv6_addr_all_routers_if_local
IPv4 address type and helper functions definitions.
A 16 bit integer in big endian aka network byte order.
uint16_t u16
16 bit representation
A 32 bit integer in big endian aka network byte order.
A 64 bit integer in big endian aka network byte order.
Data type to represent an IPv4 address.
Data type to represent an IPv6 address.
uint8_t u8[16]
divided by 16 8-bit words.
network_uint64_t u64[2]
divided by 2 64-bit words.
network_uint32_t u32[4]
divided by 4 32-bit words.
network_uint16_t u16[8]
divided by 8 16-bit words.