@@ -47,3 +47,16 @@ void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
return;
}
+
+int hwaddr_cmp(uint8_t *hwaddr1, size_t hwaddr1_len, uint8_t *hwaddr2, size_t hwaddr2_len)
+{
+ /* emulate memcmp even though it's unnecessary */
+
+ if (hwaddr1_len > hwaddr2_len)
+ return 1;
+
+ if (hwaddr1_len < hwaddr2_len)
+ return -1;
+
+ return memcmp(hwaddr1, hwaddr2, hwaddr1_len);
+}
@@ -18,6 +18,7 @@
#ifndef UTIL_H
#define UTIL_H
+#include <stddef.h>
#include <stdint.h>
#ifndef container_of
@@ -51,5 +52,7 @@
void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen);
+int hwaddr_cmp(uint8_t *hwaddr1, size_t hwaddr1_len, uint8_t *hwaddr2, size_t hwaddr2_len);
+
#endif /* UTIL_H */
This simplifies comparing hardware address buffers when they may be of different lengths. Signed-off-by: Daniel M. Weeks <weeksd2@rpi.edu> --- lib/util/util.c | 13 +++++++++++++ lib/util/util.h | 3 +++ 2 files changed, 16 insertions(+)