mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
libnm-util: add nm_utils_hwaddr_valid()
This commit is contained in:
parent
bc1a764e1a
commit
9a73db17d5
|
@ -546,6 +546,7 @@ global:
|
|||
nm_utils_hwaddr_ntoa;
|
||||
nm_utils_hwaddr_ntoa_len;
|
||||
nm_utils_hwaddr_type;
|
||||
nm_utils_hwaddr_valid;
|
||||
nm_utils_iface_valid_name;
|
||||
nm_utils_init;
|
||||
nm_utils_ip4_addresses_from_gvalue;
|
||||
|
|
|
@ -2063,6 +2063,31 @@ nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length)
|
|||
return g_string_free (out, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_valid:
|
||||
* @asc: the ASCII representation of a hardware address
|
||||
*
|
||||
* Parses @asc to see if it is a valid hardware address of some type.
|
||||
*
|
||||
* Return value: %TRUE if @asc appears to be a valid hardware address
|
||||
* of some type, %FALSE if not.
|
||||
*
|
||||
* Since: 0.9.10
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_hwaddr_valid (const char *asc)
|
||||
{
|
||||
guint8 buf[NM_UTILS_HWADDR_LEN_MAX];
|
||||
int in_len = strlen (asc), out_len;
|
||||
|
||||
if ((in_len + 1) % 3 != 0)
|
||||
return FALSE;
|
||||
out_len = (in_len + 1) / 3;
|
||||
if (out_len > NM_UTILS_HWADDR_LEN_MAX)
|
||||
return FALSE;
|
||||
return nm_utils_hwaddr_aton_len (asc, buf, out_len) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_bin2hexstr:
|
||||
* @bytes: an array of bytes
|
||||
|
|
|
@ -144,6 +144,8 @@ guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);
|
|||
char *nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length);
|
||||
guint8 *nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length);
|
||||
|
||||
gboolean nm_utils_hwaddr_valid (const char *asc);
|
||||
|
||||
char *nm_utils_bin2hexstr (const char *bytes, int len, int final_len);
|
||||
int nm_utils_hex2byte (const char *hex);
|
||||
char *nm_utils_hexstr2bin (const char *hex, size_t len);
|
||||
|
|
Loading…
Reference in a new issue