summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nm-core-utils.c28
-rw-r--r--src/nm-core-utils.h2
2 files changed, 29 insertions, 1 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 188e4737af..0273f6994b 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -2586,7 +2586,33 @@ nm_utils_is_specific_hostname (const char *name)
return FALSE;
}
-/******************************************************************/
+/*****************************************************************************/
+
+char *
+nm_utils_binary_to_hex (gconstpointer addr, gsize length)
+{
+ const guint8 *in = addr;
+ char *out, *result;
+ const char *LOOKUP = "0123456789abcdef";
+ guint8 v;
+
+ if (length == 0)
+ return g_strdup ("");
+ if (!addr)
+ g_return_val_if_reached (g_strdup (""));
+
+ result = out = g_malloc (length * 2 + 1);
+ while (length--) {
+ v = *in++;
+ *out++ = LOOKUP[v >> 4];
+ *out++ = LOOKUP[v & 0x0F];
+ }
+
+ *out = 0;
+ return result;
+}
+
+/*****************************************************************************/
/* Returns the "u" (universal/local) bit value for a Modified EUI-64 */
static gboolean
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h
index 486942a22a..207cfae173 100644
--- a/src/nm-core-utils.h
+++ b/src/nm-core-utils.h
@@ -307,6 +307,8 @@ const char *nm_utils_ip4_property_path (const char *ifname, const char *property
gboolean nm_utils_is_specific_hostname (const char *name);
+char *nm_utils_binary_to_hex (gconstpointer addr, gsize length);
+
/* IPv6 Interface Identifer helpers */
/**