Loading...
Searching...
No Matches
l2util.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 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
9#pragma once
10
27
28#include <stdint.h>
29
30#include "compiler_hints.h"
31#include "net/eui64.h"
32#include "net/ndp.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define L2UTIL_ADDR_MAX_LEN (8U)
39
58int l2util_eui64_from_addr(int dev_type, const uint8_t *addr, size_t addr_len,
59 eui64_t *eui64);
60
80 const uint8_t *addr, size_t addr_len,
81 eui64_t *iid);
82
107int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr);
108
135 const ndp_opt_t *opt);
136
153 const ipv6_addr_t *ipv6_group,
154 uint8_t *l2_group);
155
172char *l2util_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
173
193ACCESS(write_only, 2, 3)
194size_t l2util_addr_from_str_sized(const char *str, void *addr, size_t addr_size);
195
215size_t l2util_addr_from_str(const char *str, uint8_t out[L2UTIL_ADDR_MAX_LEN]);
216
227static inline bool l2util_addr_equal(const uint8_t *addr_a, uint8_t addr_a_len,
228 const uint8_t *addr_b, uint8_t addr_b_len)
229{
230 if (addr_a_len != addr_b_len) {
231 return false;
232 }
233
234 return memcmp(addr_a, addr_b, addr_a_len) == 0;
235}
236
237#ifdef __cplusplus
238}
239#endif
240
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
EUI-64 data type definition.
int l2util_eui64_from_addr(int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *eui64)
Converts a given hardware address to an EUI-64.
size_t l2util_addr_from_str_sized(const char *str, void *addr, size_t addr_size)
Parses a string of colon-separated hexadecimals to a hardware address.
int l2util_ndp_addr_len_from_l2ao(int dev_type, const ndp_opt_t *opt)
Derives the length of the link-layer address in an NDP link-layer address option from that option's l...
int l2util_ipv6_iid_from_addr(int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *iid)
Converts a given hardware address to an IPv6 IID.
size_t l2util_addr_from_str(const char *str, uint8_t out[L2UTIL_ADDR_MAX_LEN])
Parses a string of colon-separated hexadecimals to a hardware address.
#define L2UTIL_ADDR_MAX_LEN
maximum expected length for addresses
Definition l2util.h:38
int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr)
Converts an IPv6 IID to a hardware address.
int l2util_ipv6_group_to_l2_group(int dev_type, const ipv6_addr_t *ipv6_group, uint8_t *l2_group)
Converts an IPv6 multicast address to a multicast address of the respective link layer.
static bool l2util_addr_equal(const uint8_t *addr_a, uint8_t addr_a_len, const uint8_t *addr_b, uint8_t addr_b_len)
Checks if two l2 addresses are equal.
Definition l2util.h:227
char * l2util_addr_to_str(const uint8_t *addr, size_t addr_len, char *out)
Converts a hardware address to a human readable string.
IPv6 neighbor discovery message type definitions.
General NDP option format.
Definition ndp.h:298
Data type to represent an EUI-64.
Definition eui64.h:55
Data type to represent an IPv6 address.
Definition addr.h:67