Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缓冲区中u_字符[6]中的MAC地址。ifr_hwaddr.sa_数据[s]_C_Linux_Ethernet_Mac Address - Fatal编程技术网

缓冲区中u_字符[6]中的MAC地址。ifr_hwaddr.sa_数据[s]

缓冲区中u_字符[6]中的MAC地址。ifr_hwaddr.sa_数据[s],c,linux,ethernet,mac-address,C,Linux,Ethernet,Mac Address,我需要从缓冲区获取u_char[6]格式的路由器MAC地址。ifr结构给出的ifr_hwaddr.sa_数据[s]格式。也许这就是您想要的 for( s = 0; s < 5; s++ ) { printf("%.2X:", (unsigned char)buffer.ifr_hwaddr.sa_data[s]); } (s=0;s

我需要从缓冲区获取u_char[6]格式的路由器MAC地址。ifr结构给出的ifr_hwaddr.sa_数据[s]格式。

也许这就是您想要的

for( s = 0; s < 5; s++ )
  {
      printf("%.2X:", (unsigned char)buffer.ifr_hwaddr.sa_data[s]);
  }
(s=0;s<5;s++)的

{
printf(“%.2X:”,(无符号字符)缓冲区.ifr_hwaddr.sa_数据];
}

使用命令
cat/sys/class/net/ethX/address
,其中X=0,1,2

FILE * output= popen("cat /sys/class/net/ethX/address");
if(output)
{
    //Write your code here
    pclose(output);
}

您可能想要将6字节整数Macaddress转换为6字节字符字符串,您还必须注意网络字节顺序。

so
buffer.ifr\u hwaddr.sa\u data[s]
您的字符缓冲区是否正确?对于
printf()
1字节,转换说明符的前缀应该是适当的长度修饰符
“hh”
,成为
“hhX”