[PATCH 08/11] New function to compare hardware addresses
Daniel M. Weeks
weeksd2 at rpi.edu
Fri Apr 17 03:55:41 AEST 2020
This simplifies comparing hardware address buffers when they may be of
different lengths.
Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
lib/util/util.c | 13 +++++++++++++
lib/util/util.h | 3 +++
2 files changed, 16 insertions(+)
diff --git a/lib/util/util.c b/lib/util/util.c
index a18926c..e672d19 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -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);
+}
diff --git a/lib/util/util.h b/lib/util/util.h
index 39966d0..416e1af 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -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 */
--
Daniel M. Weeks
--
Daniel M. Weeks
Lead HPC Developer
Center for Computational Innovations
Rensselaer Polytechnic Institute
Troy, NY 12180
518-276-4458
More information about the Petitboot
mailing list