Blame view
lib/net_utils.c
640 Bytes
b24413180
|
1 |
// SPDX-License-Identifier: GPL-2.0 |
4cd5773a2
|
2 3 4 5 |
#include <linux/string.h> #include <linux/if_ether.h> #include <linux/ctype.h> #include <linux/kernel.h> |
a69f5edb8
|
6 |
bool mac_pton(const char *s, u8 *mac) |
4cd5773a2
|
7 8 9 10 11 |
{ int i; /* XX:XX:XX:XX:XX:XX */ if (strlen(s) < 3 * ETH_ALEN - 1) |
a69f5edb8
|
12 |
return false; |
4cd5773a2
|
13 14 15 16 |
/* Don't dirty result unless string is valid MAC. */ for (i = 0; i < ETH_ALEN; i++) { if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1])) |
a69f5edb8
|
17 |
return false; |
4cd5773a2
|
18 |
if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':') |
a69f5edb8
|
19 |
return false; |
4cd5773a2
|
20 21 22 23 |
} for (i = 0; i < ETH_ALEN; i++) { mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]); } |
a69f5edb8
|
24 |
return true; |
4cd5773a2
|
25 26 |
} EXPORT_SYMBOL(mac_pton); |