@@ -18,6 +18,7 @@
#include <string.h>
#include <assert.h>
+#include <log/log.h>
#include <util/util.h>
static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
@@ -60,3 +61,24 @@ int hwaddr_cmp(uint8_t *hwaddr1, size_t hwaddr1_len, uint8_t *hwaddr2, size_t hw
return memcmp(hwaddr1, hwaddr2, hwaddr1_len);
}
+
+/* takes a pretty hardware address and returns the point to begin processing
+ * and a length or NULL if the length is unrecognized */
+const char *hwaddr_preprocess(const char *mac, size_t *length)
+{
+ if (!mac)
+ return NULL;
+
+ if (strlen(mac) == 17) { /* a pretty MAC address */
+ if (length)
+ *length = 6;
+ return mac;
+ } else if (strlen(mac) == 59) { /* a pretty IB address */
+ if (length)
+ *length = 8;
+ return mac+36;
+ } else {
+ pb_debug("unsupported hwaddr format (length %ld)\n", strlen(mac));
+ return NULL;
+ }
+}
@@ -54,5 +54,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);
+const char *hwaddr_preprocess(const char *mac, size_t *length);
+
#endif /* UTIL_H */
This function will take a long hardware address, and identify the beginning of the local, usable hardware address and, optionally, its length. Since Infiniband IP over IB hardware addresses begin with 12 bytes of addressing data that can change and is not representative of the local hardware, it is removed. Signed-off-by: Daniel M. Weeks <weeksd2@rpi.edu> --- lib/util/util.c | 22 ++++++++++++++++++++++ lib/util/util.h | 2 ++ 2 files changed, 24 insertions(+)