From 1f8090fb58e614fb703835c023ebde95439299fd Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 18 Nov 2011 11:11:26 -0600 Subject: [PATCH] libnm-util: add nm_utils_hwaddr_type() Returns the address type given the length. --- libnm-util/libnm-util.ver | 1 + libnm-util/nm-utils.c | 21 +++++++++++++++++++++ libnm-util/nm-utils.h | 1 + 3 files changed, 23 insertions(+) diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index f3c0eb22ed..82b79d78b7 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -452,6 +452,7 @@ global: nm_utils_hwaddr_aton; nm_utils_hwaddr_len; nm_utils_hwaddr_ntoa; + nm_utils_hwaddr_type; nm_utils_init; nm_utils_ip4_addresses_from_gvalue; nm_utils_ip4_addresses_to_gvalue; diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index afce25593d..a8682217a3 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -2408,6 +2408,27 @@ nm_utils_hwaddr_len (int type) g_return_val_if_reached (-1); } +/** + * nm_utils_hwaddr_type: + * @len: the length of hardware address in bytes + * + * Returns the type (either %ARPHRD_ETHER or %ARPHRD_INFINIBAND) of the raw + * address given its length. + * + * Return value: the type, either %ARPHRD_ETHER or %ARPHRD_INFINIBAND, or -1 if + * the address length was not recognized + */ +int +nm_utils_hwaddr_type (int len) +{ + if (len == ETH_ALEN) + return ARPHRD_ETHER; + else if (len == INFINIBAND_ALEN) + return ARPHRD_INFINIBAND; + else + g_return_val_if_reached (-1); +} + #define HEXVAL(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10) /** diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h index d858d3fb21..7684ed6bc8 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -128,6 +128,7 @@ gboolean nm_utils_wifi_is_channel_valid (guint32 channel, const char *band); #define NM_UTILS_HWADDR_LEN_MAX 20 /* INFINIBAND_ALEN */ int nm_utils_hwaddr_len (int type) G_GNUC_PURE; +int nm_utils_hwaddr_type (int len) G_GNUC_PURE; char *nm_utils_hwaddr_ntoa (gconstpointer addr, int type); GByteArray *nm_utils_hwaddr_atoba (const char *asc, int type); guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);