libnm: add internal util function _nm_utils_hwaddr_length()

This commit is contained in:
Thomas Haller 2016-05-25 10:46:48 +02:00
parent 05ecb28436
commit fc527a237c
2 changed files with 29 additions and 0 deletions

View file

@ -124,6 +124,8 @@ guint32 _nm_setting_get_setting_priority (NMSetting *setting);
gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
guint _nm_utils_hwaddr_length (const char *asc);
GSList * _nm_utils_hash_values_to_slist (GHashTable *hash);
GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);

View file

@ -3114,6 +3114,33 @@ hwaddr_binary_len (const char *asc)
return octets;
}
/**
* _nm_utils_hwaddr_length:
* @asc: the ASCII representation of the hardware address
*
* Validates that @asc is a valid representation of a hardware
* address up to (including) %NM_UTILS_HWADDR_LEN_MAX bytes.
*
* Returns: binary length of the hardware address @asc or
* 0 on error.
*/
guint
_nm_utils_hwaddr_length (const char *asc)
{
int l;
if (!asc)
return 0;
l = hwaddr_binary_len (asc);
if (l <= 0 || l > NM_UTILS_HWADDR_LEN_MAX)
return 0;
if (!nm_utils_hwaddr_valid (asc, l))
return 0;
return l;
}
/**
* nm_utils_hwaddr_valid:
* @asc: the ASCII representation of a hardware address