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:
parent
f05ed4683c
commit
63b5c60743
34
src/util.c
34
src/util.c
@ -97,6 +97,40 @@ const char *util_address_to_string(const uint8_t *addr)
|
||||
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,
|
||||
uint16_t type, const char *type_str,
|
||||
uint16_t len, const void *value)
|
||||
|
@ -29,6 +29,7 @@
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user