标签:linux c
在PF_RING安装包中摘取的代码,,感觉比较不错。自己注释的
char* etheraddr_string(const u_char *ep, char *buf) {
u_int i, j;
char *cp;
cp = buf;
if((j = *ep >> 4) != 0) //ep[0]的高4位赋给j, 转换成十六进制,赋给cp[0]
*cp++ = hex[j];
else
*cp++ = ‘0‘;
*cp++ = hex[*ep++ & 0xf]; //ep[0]的低4位转换成十六进制,赋给cp[1]
for(i = 5; (int)--i >= 0;) { //重复上述过程
*cp++ = ‘:‘;
if((j = *ep >> 4) != 0)
*cp++ = hex[j];
else
*cp++ = ‘0‘;
*cp++ = hex[*ep++ & 0xf];
}
*cp = ‘\0‘;
return (buf);
}
标签:linux c
原文地址:http://yuzwei.blog.51cto.com/10126623/1719385