ether-addr-util: introduce parse_hw_addr()

This commit is contained in:
Yu Watanabe
2021-11-09 21:39:05 +09:00
parent 777c17b9d1
commit 76a5d3dee2
2 changed files with 152 additions and 0 deletions
+8
View File
@@ -6,6 +6,7 @@
#include <stdbool.h>
#include "hash-funcs.h"
#include "in-addr-util.h"
#include "macro.h"
#include "memory-util.h"
@@ -18,10 +19,17 @@ struct hw_addr_data {
union {
struct ether_addr ether;
uint8_t infiniband[INFINIBAND_ALEN];
struct in_addr in;
struct in6_addr in6;
uint8_t bytes[HW_ADDR_MAX_SIZE];
};
};
int parse_hw_addr_full(const char *s, size_t expected_len, struct hw_addr_data *ret);
static inline int parse_hw_addr(const char *s, struct hw_addr_data *ret) {
return parse_hw_addr_full(s, 0, ret);
}
#define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE)
char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]);