universal_address.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2014 Martin Landsmann <Martin.Landsmann@HAW-Hamburg.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include "net/ipv6/addr.h"
27 
29 /* determine the widest possible address type */
30 #ifndef UNIVERSAL_ADDRESS_SIZE
31 #define UNIVERSAL_ADDRESS_SIZE (0) /* rather senseless default, should
32  trigger warnings */
33 #endif
34 
35 /* IPv6 address has 128 bit -> 16 bytes */
36 #if defined(MODULE_IPV6_ADDR) && ((IPV6_ADDR_BIT_LEN >> 3) > UNIVERSAL_ADDRESS_SIZE)
37 #undef UNIVERSAL_ADDRESS_SIZE
38 #define UNIVERSAL_ADDRESS_SIZE (IPV6_ADDR_BIT_LEN >> 3)
39 #endif
40 
42 #define UNIVERSAL_ADDRESS_EQUAL (0)
43 
45 #define UNIVERSAL_ADDRESS_MATCHING_PREFIX (1)
46 
50 #define UNIVERSAL_ADDRESS_IS_ALL_ZERO_ADDRESS (2)
51 
55 typedef struct {
56  uint8_t use_count;
57  uint8_t address_size;
58  uint8_t address[UNIVERSAL_ADDRESS_SIZE];
60 
64 void universal_address_init(void);
65 
69 void universal_address_reset(void);
70 
81 universal_address_container_t *universal_address_add(uint8_t *addr, size_t addr_size);
82 
90 
103  uint8_t *addr, size_t *addr_size);
104 
125  uint8_t *addr, size_t *addr_size_in_bits);
126 
146  uint8_t *prefix, size_t prefix_size_in_bits);
147 
154 
159 
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
void universal_address_print_entry(universal_address_container_t *entry)
Print the content of the given entry.
void universal_address_init(void)
Initialize the data structure for the entries.
void universal_address_reset(void)
Resets the universal_address_container_t::use_count for all entries.
int universal_address_get_num_used_entries(void)
Return the number of used entries.
#define UNIVERSAL_ADDRESS_SIZE
size of the used addresses in bytes
void universal_address_rem(universal_address_container_t *entry)
Add a given container from the universal address entries.
int universal_address_compare_prefix(universal_address_container_t *entry, uint8_t *prefix, size_t prefix_size_in_bits)
Determine if the entry equals the provided prefix This function requires to be provided with the full...
void universal_address_print_table(void)
Print the content of the generic address table up to the used element.
uint8_t * universal_address_get_address(universal_address_container_t *entry, uint8_t *addr, size_t *addr_size)
Copy the address from the given container to the provided pointer.
int universal_address_compare(universal_address_container_t *entry, uint8_t *addr, size_t *addr_size_in_bits)
Determine if the entry equals the provided address This function requires to be provided with the ful...
universal_address_container_t * universal_address_add(uint8_t *addr, size_t addr_size)
Add a given address to the universal address entries.
Definitions for IPv6 addresses.
The container descriptor used to identify a universal address entry.