Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
60} __packed;
61
69 uint8_t *addr; /* in big endian */
70
73
76};
77
91
94
97};
98
107static inline bool net_linkaddr_cmp(struct net_linkaddr *lladdr1,
108 struct net_linkaddr *lladdr2)
109{
110 if (!lladdr1 || !lladdr2) {
111 return false;
112 }
113
114 if (lladdr1->len != lladdr2->len) {
115 return false;
116 }
117
118 return !memcmp(lladdr1->addr, lladdr2->addr, lladdr1->len);
119}
120
130static inline int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store,
131 uint8_t *new_addr, uint8_t new_len)
132{
133 if (!lladdr_store || !new_addr) {
134 return -EINVAL;
135 }
136
137 if (new_len > NET_LINK_ADDR_MAX_LENGTH) {
138 return -EMSGSIZE;
139 }
140
141 lladdr_store->len = new_len;
142 memcpy(lladdr_store->addr, new_addr, new_len);
143
144 return 0;
145}
146
151#ifdef __cplusplus
152}
153#endif
154
155#endif /* ZEPHYR_INCLUDE_NET_NET_LINKADDR_H_ */
System error numbers.
net_link_type
Type of the link address.
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:107
#define NET_LINK_ADDR_MAX_LENGTH
Maximum length of the link address.
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:130
@ NET_LINK_UNKNOWN
Unknown link address type.
Definition: net_linkaddr.h:49
@ NET_LINK_IEEE802154
IEEE 802.15.4 link address.
Definition: net_linkaddr.h:51
@ NET_LINK_DUMMY
Dummy link address.
Definition: net_linkaddr.h:57
@ NET_LINK_ETHERNET
Ethernet link address.
Definition: net_linkaddr.h:55
@ NET_LINK_CANBUS_RAW
CANBUS link address.
Definition: net_linkaddr.h:59
@ NET_LINK_BLUETOOTH
Bluetooth IPSP link address.
Definition: net_linkaddr.h:53
#define EINVAL
Invalid argument.
Definition: errno.h:60
#define EMSGSIZE
Message size.
Definition: errno.h:106
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
int memcmp(const void *m1, const void *m2, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Hardware link address structure.
Definition: net_linkaddr.h:88
uint8_t type
What kind of address is this for.
Definition: net_linkaddr.h:90
uint8_t len
The real length of the ll address.
Definition: net_linkaddr.h:93
uint8_t addr[6]
The array of bytes representing the address.
Definition: net_linkaddr.h:96
Hardware link address structure.
Definition: net_linkaddr.h:67
uint8_t * addr
The array of byte representing the address.
Definition: net_linkaddr.h:69
uint8_t type
What kind of address is this for.
Definition: net_linkaddr.h:75
uint8_t len
Length of that address array.
Definition: net_linkaddr.h:72