summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-04-25 21:59:03 +0200
committerThomas Haller <thaller@redhat.com>2016-04-26 12:43:18 +0200
commit0c3e69dee346622f163c0b44836a3784508e4654 (patch)
tree62c03803917202b170f18f7f3af5e2b7b8a0210f
parentdd4d8b24da29abfc786ce0b3030c74559b93d034 (diff)
downloadNetworkManager-th/wip/util/nm-utils-binary-to-hex.tar.gz
nm_utils_hwaddr_ntoa() is not suitable, because it only allows up to NM_UTILS_HWADDR_LEN_MAX characters. Also, let's do lower-case and no separator character.
-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 */
/**