Ai
1 Star 0 Fork 2

BuildOpenSource/busybox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
in_ether.c 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*/
//kbuild:lib-$(CONFIG_ARP) += in_ether.o
//kbuild:lib-$(CONFIG_IFCONFIG) += in_ether.o
//kbuild:lib-$(CONFIG_IFENSLAVE) += in_ether.o
#include "libbb.h"
#include <net/if_arp.h>
#include <net/ethernet.h>
/* Convert Ethernet address from "XX[:]XX[:]XX[:]XX[:]XX[:]XX" to sockaddr.
* Return nonzero on error.
*/
int FAST_FUNC in_ether(const char *bufp, struct sockaddr *sap)
{
char *ptr;
int i, j;
unsigned char val;
unsigned char c;
sap->sa_family = ARPHRD_ETHER;
ptr = (char *) sap->sa_data;
i = ETH_ALEN;
goto first;
do {
/* We might get a semicolon here */
if (*bufp == ':')
bufp++;
first:
j = val = 0;
do {
c = *bufp;
if (((unsigned char)(c - '0')) <= 9) {
c -= '0';
} else if ((unsigned char)((c|0x20) - 'a') <= 5) {
c = (unsigned char)((c|0x20) - 'a') + 10;
} else {
if (j && (c == ':' || c == '\0'))
/* One-digit byte: __:X:__ */
break;
return -1;
}
++bufp;
val <<= 4;
val += c;
j ^= 1;
} while (j);
*ptr++ = val;
} while (--i);
/* Error if we aren't at end of string */
return *bufp;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/build-open-source/busybox.git
git@gitee.com:build-open-source/busybox.git
build-open-source
busybox
busybox
master

搜索帮助