3 Star 1 Fork 1.7K

ci-robot/kernel

forked from openEuler/kernel 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
net_utils.c 697 Bytes
一键复制 编辑 原始数据 按行查看 历史
// SPDX-License-Identifier: GPL-2.0
#include <linux/string.h>
#include <linux/if_ether.h>
#include <linux/ctype.h>
#include <linux/export.h>
#include <linux/hex.h>
bool mac_pton(const char *s, u8 *mac)
{
size_t maxlen = 3 * ETH_ALEN - 1;
int i;
/* XX:XX:XX:XX:XX:XX */
if (strnlen(s, maxlen) < maxlen)
return false;
/* 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]))
return false;
if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
return false;
}
for (i = 0; i < ETH_ALEN; i++) {
mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
}
return true;
}
EXPORT_SYMBOL(mac_pton);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ci-robot/kernel.git
git@gitee.com:ci-robot/kernel.git
ci-robot
kernel
kernel
patch-1706000765

搜索帮助