aboutsummaryrefslogtreecommitdiffstats
path: root/lib/net_utils.c
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-03-08 22:04:20 +0800
committerWe-unite <3205135446@qq.com>2025-03-08 22:04:20 +0800
commita07bb8fd1299070229f0e8f3dcb57ffd5ef9870a (patch)
tree84f21bd0bf7071bc5fc7dd989e77d7ceb5476682 /lib/net_utils.c
downloadohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.tar.gz
ohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.zip
Initial commit: OpenHarmony-v4.0-ReleaseOpenHarmony-v4.0-Release
Diffstat (limited to 'lib/net_utils.c')
-rw-r--r--lib/net_utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/net_utils.c b/lib/net_utils.c
new file mode 100644
index 000000000..af5253533
--- /dev/null
+++ b/lib/net_utils.c
@@ -0,0 +1,27 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/string.h>
3#include <linux/if_ether.h>
4#include <linux/ctype.h>
5#include <linux/kernel.h>
6
7bool mac_pton(const char *s, u8 *mac)
8{
9 int i;
10
11 /* XX:XX:XX:XX:XX:XX */
12 if (strlen(s) < 3 * ETH_ALEN - 1)
13 return false;
14
15 /* Don't dirty result unless string is valid MAC. */
16 for (i = 0; i < ETH_ALEN; i++) {
17 if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
18 return false;
19 if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
20 return false;
21 }
22 for (i = 0; i < ETH_ALEN; i++) {
23 mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
24 }
25 return true;
26}
27EXPORT_SYMBOL(mac_pton);