3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

util: Add util_string_to_address

This commit is contained in:
Denis Kenzior 2016-08-24 21:31:54 -05:00
parent f05ed4683c
commit 63b5c60743
2 changed files with 35 additions and 0 deletions

View File

@ -97,6 +97,40 @@ const char *util_address_to_string(const uint8_t *addr)
return str; return str;
} }
bool util_string_to_address(const char *str, uint8_t *addr)
{
unsigned int i;
if (!str)
return false;
if (strlen(str) != 17)
return false;
for (i = 0; i < 15; i += 3) {
if (!l_ascii_isxdigit(str[i]))
return false;
if (!l_ascii_isxdigit(str[i + 1]))
return false;
if (str[i + 2] != ':')
return false;
}
if (!l_ascii_isxdigit(str[i]))
return false;
if (!l_ascii_isxdigit(str[i + 1]))
return false;
sscanf(str, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
&addr[0], &addr[1], &addr[2],
&addr[3], &addr[4], &addr[5]);
return true;
}
bool _msg_append_attr(struct l_genl_msg *msg, bool _msg_append_attr(struct l_genl_msg *msg,
uint16_t type, const char *type_str, uint16_t type, const char *type_str,
uint16_t len, const void *value) uint16_t len, const void *value)

View File

@ -29,6 +29,7 @@
const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid); const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid);
bool util_ssid_is_utf8(size_t len, const uint8_t *ssid); bool util_ssid_is_utf8(size_t len, const uint8_t *ssid);
const char *util_address_to_string(const uint8_t *addr); const char *util_address_to_string(const uint8_t *addr);
bool util_string_to_address(const char *str, uint8_t *addr);
static inline uint8_t util_bit_field(const uint8_t oct, int start, int num) static inline uint8_t util_bit_field(const uint8_t oct, int start, int num)
{ {