上善若水
qinzhong
全部博文(41)
2011年(1)
2009年(40)
格伯纳
我在远方
lobychin
sandy123
liuxu_gm
huaxu071
crazytom
gogoqiu
_雍正王
分类:
2009-04-10 19:42:55
#include <stdio.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <netinet/in.h> #include <net/if.h> #include <string.h> int main(int argc, char *argv[]){ struct ifreq ifreq; int sock; if(argc!=2) { printf("Usage : ethname\n"); return 1; } if((sock=socket(AF_INET,SOCK_STREAM,0))<0) { perror("socket"); return 2; } strcpy(ifreq.ifr_name,argv[1]); if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0) { perror("ioctl"); return 3; } printf("%02x:%02x:%02x:%02x:%02x:%02x\n", (unsigned char)ifreq.ifr_hwaddr.sa_data[0], (unsigned char)ifreq.ifr_hwaddr.sa_data[1], (unsigned char)ifreq.ifr_hwaddr.sa_data[2], (unsigned char)ifreq.ifr_hwaddr.sa_data[3], (unsigned char)ifreq.ifr_hwaddr.sa_data[4], (unsigned char)ifreq.ifr_hwaddr.sa_data[5]); unsigned char temp = (unsigned char)ifreq.ifr_hwaddr.sa_data[0]; int a = temp; printf("%02x",a); return 0; }
上一篇:《内核编译与模组管理》练习题
下一篇:Google Talk的几种玩法
登录 注册