作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
ifr_hwaddr.sa_data[0], (unsigned-6ren">
获取方式:
printf(" %02x:%02x:%02x:%02x:%02x:%02x",
(unsigned char)item->ifr_hwaddr.sa_data[0],
(unsigned char)item->ifr_hwaddr.sa_data[1],
(unsigned char)item->ifr_hwaddr.sa_data[2],
(unsigned char)item->ifr_hwaddr.sa_data[3],
(unsigned char)item->ifr_hwaddr.sa_data[4],
(unsigned char)item->ifr_hwaddr.sa_data[5]);
进入这个(存储在变量中,不打印它):
char mac[18];
谢谢
最佳答案
使用
#include <stdio.h>
int main(int argc, char **argv)
{
char mac[19]; /* one extra for terminating '\0';
You may want to make it a little larger
still, just to be sure. */
sprintf(mac, " %02x:%02x:%02x:%02x:%02x:%02x",
(unsigned char)item->ifr_hwaddr.sa_data[0],
(unsigned char)item->ifr_hwaddr.sa_data[1],
(unsigned char)item->ifr_hwaddr.sa_data[2],
(unsigned char)item->ifr_hwaddr.sa_data[3],
(unsigned char)item->ifr_hwaddr.sa_data[4],
(unsigned char)item->ifr_hwaddr.sa_data[5]);
printf("%s\n", mac); // string was "printed" to mac array!
return 0;
}
关于c - 如何获取 ifr_hwaddr.sa_data 到 char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6791923/
获取方式: printf(" %02x:%02x:%02x:%02x:%02x:%02x", (unsigned char)item->ifr_hwaddr.sa_data[0], (unsigned
我需要从 ifr 结构给出的 buffer.ifr_hwaddr.sa_data[s] 格式获取 u_char[6] 格式的路由器 MAC 地址。 最佳答案 也许这就是你想要的 for( s = 0;
我是一名优秀的程序员,十分优秀!