summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMichael Scott <michael.scott@linaro.org>2017-01-11 15:18:05 -0800
committerJukka Rissanen <jukka.rissanen@linux.intel.com>2017-01-20 16:23:16 +0200
commit7b674cb287c1a34f4654fd41944a0e235633ae16 (patch)
treed64c3ca1081b97a6a18d6e0059986e721c9c088e /include
parent4aad7673280bf353b2ff39c1987185f9e6e067f6 (diff)
net: linkaddr: introduce net_linkaddr_set function
The net_linkaddr_storage structure contains an array of bytes used to store the link address. This array can be different sizes depending on the CONFIG options used when building. To facilitate consistency and error checking let's introduce a new helper function to copy the addr and len values to this structure. Also move all uses of memcpy related to net_link_storage structures to the new helper function. Change-Id: Ic547d86b07e62e5ac3bc330d4eaeb4508a143200 Signed-off-by: Michael Scott <michael.scott@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/net_linkaddr.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/net/net_linkaddr.h b/include/net/net_linkaddr.h
index e5b2e1b08..eb75430cc 100644
--- a/include/net/net_linkaddr.h
+++ b/include/net/net_linkaddr.h
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include <errno.h>
#ifdef __cplusplus
extern "C" {
@@ -78,6 +79,32 @@ static inline bool net_linkaddr_cmp(struct net_linkaddr *lladdr1,
return !memcmp(lladdr1->addr, lladdr2->addr, lladdr1->len);
}
+/**
+ *
+ * @brief Set the member data of a link layer address storage structure.
+ *
+ * @param lladdr_store The link address storage structure to change.
+ * @param new_addr Array of bytes containing the link address.
+ * @param new_len Length of the link address array.
+ * This value should always be <= NET_LINK_ADDR_MAX_LENGTH.
+ */
+static inline int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store,
+ uint8_t *new_addr, uint8_t new_len)
+{
+ if (!lladdr_store || !new_addr) {
+ return -EINVAL;
+ }
+
+ if (new_len > NET_LINK_ADDR_MAX_LENGTH) {
+ return -EMSGSIZE;
+ }
+
+ lladdr_store->len = new_len;
+ memcpy(lladdr_store->addr, new_addr, new_len);
+
+ return 0;
+}
+
#ifdef __cplusplus
}
#endif