utils.c: add helper function to format mac addresses as strings
[project/netifd.git] / utils.c
diff --git a/utils.c b/utils.c
index 986cee9..14e966a 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -129,3 +129,14 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask)
 
        return inet_pton(af, astr, addr);
 }
+
+char *
+format_macaddr(uint8_t *mac)
+{
+       static char str[sizeof("ff:ff:ff:ff:ff:ff ")];
+
+       snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
+                mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+       return str;
+}