libnm-util: add nm_utils_hwaddr_type()

Returns the address type given the length.
This commit is contained in:
Dan Williams 2011-11-18 11:11:26 -06:00
parent 6e4eb4902e
commit 1f8090fb58
3 changed files with 23 additions and 0 deletions

View file

@ -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;

View file

@ -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)
/**

View file

@ -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);