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
25#ifndef NET_L2UTIL_H
26#define NET_L2UTIL_H
27
28#include <stdint.h>
29
30#include "net/eui64.h"
31#include "net/ndp.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#define L2UTIL_ADDR_MAX_LEN (8U)
57int l2util_eui64_from_addr(int dev_type, const uint8_t *addr, size_t addr_len,
58 eui64_t *eui64);
59
79 const uint8_t *addr, size_t addr_len,
80 eui64_t *iid);
81
106int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr);
107
134 const ndp_opt_t *opt);
135
152 const ipv6_addr_t *ipv6_group,
153 uint8_t *l2_group);
154
171char *l2util_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
172
191size_t l2util_addr_from_str(const char *str, uint8_t *out);
192
203static inline bool l2util_addr_equal(const uint8_t *addr_a, uint8_t addr_a_len,
204 const uint8_t *addr_b, uint8_t addr_b_len)
205{
206 if (addr_a_len != addr_b_len) {
207 return false;
208 }
209
210 return memcmp(addr_a, addr_b, addr_a_len) == 0;
211}
212
213#ifdef __cplusplus
214}
215#endif
216
217#endif /* NET_L2UTIL_H */
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.
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)
Parses a string of colon-separated hexadecimals to a hardware address.
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:203
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:72