Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
net_linkaddr.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_NET_NET_LINKADDR_H_
13#define ZEPHYR_INCLUDE_NET_NET_LINKADDR_H_
14
15#include <zephyr/types.h>
16#include <stdbool.h>
17#include <errno.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31#ifdef CONFIG_NET_L2_IEEE802154
32#define NET_LINK_ADDR_MAX_LENGTH 8
33#else
34#ifdef CONFIG_NET_L2_PPP
35#define NET_LINK_ADDR_MAX_LENGTH 8
36#else
37#define NET_LINK_ADDR_MAX_LENGTH 6
38#endif
39#endif
40
62} __packed;
63
72
75
78};
79
93
96
99};
100
109static inline bool net_linkaddr_cmp(struct net_linkaddr *lladdr1,
110 struct net_linkaddr *lladdr2)
111{
112 if (!lladdr1 || !lladdr2) {
113 return false;
114 }
115
116 if (lladdr1->len != lladdr2->len) {
117 return false;
118 }
119
120 return !memcmp(lladdr1->addr, lladdr2->addr, lladdr1->len);
121}
122
132static inline int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store,
133 uint8_t *new_addr, uint8_t new_len)
134{
135 if (!lladdr_store || !new_addr) {
136 return -EINVAL;
137 }
138
139 if (new_len > NET_LINK_ADDR_MAX_LENGTH) {
140 return -EMSGSIZE;
141 }
142
143 lladdr_store->len = new_len;
144 memcpy(lladdr_store->addr, new_addr, new_len);
145
146 return 0;
147}
148
153#ifdef __cplusplus
154}
155#endif
156
157#endif /* ZEPHYR_INCLUDE_NET_NET_LINKADDR_H_ */
System error numbers.
net_link_type
Definition: net_linkaddr.h:47
static bool net_linkaddr_cmp(struct net_linkaddr *lladdr1, struct net_linkaddr *lladdr2)
Compare two link layer addresses.
Definition: net_linkaddr.h:109
#define NET_LINK_ADDR_MAX_LENGTH
Definition: net_linkaddr.h:37
static int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store, uint8_t *new_addr, uint8_t new_len)
Set the member data of a link layer address storage structure.
Definition: net_linkaddr.h:132
@ NET_LINK_CANBUS
Definition: net_linkaddr.h:61
@ NET_LINK_UNKNOWN
Definition: net_linkaddr.h:49
@ NET_LINK_IEEE802154
Definition: net_linkaddr.h:51
@ NET_LINK_DUMMY
Definition: net_linkaddr.h:57
@ NET_LINK_ETHERNET
Definition: net_linkaddr.h:55
@ NET_LINK_CANBUS_RAW
Definition: net_linkaddr.h:59
@ NET_LINK_BLUETOOTH
Definition: net_linkaddr.h:53
#define EINVAL
Definition: errno.h:61
#define EMSGSIZE
Definition: errno.h:107
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
void * memcpy(void *_MLIBC_RESTRICT d, const void *_MLIBC_RESTRICT s, size_t n)
int memcmp(const void *m1, const void *m2, size_t n)
Hardware link address structure.
Definition: net_linkaddr.h:90
uint8_t type
Definition: net_linkaddr.h:92
uint8_t len
Definition: net_linkaddr.h:95
uint8_t addr[6]
Definition: net_linkaddr.h:98
Hardware link address structure.
Definition: net_linkaddr.h:69
uint8_t * addr
Definition: net_linkaddr.h:71
uint8_t type
Definition: net_linkaddr.h:77
uint8_t len
Definition: net_linkaddr.h:74