bo_00
全部博文(88)
2017年(3)
2016年(1)
2012年(4)
2011年(4)
2010年(57)
2009年(19)
songtao0
a1503123
zangleng
along819
Phyllis6
cgl520cn
sdhh_zha
xujinchn
兰尼福步
炯炯大王
分类: LINUX
2009-12-24 14:01:55
#include <stdio.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> //for struct ifreq void main(int argc, char *argv[]){ //void类型 argv参数就是 "eth0" "eth1" struct ifreq ifreq; int sock;
#include <stdio.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> //for struct ifreq void main(int argc, char *argv[]){ //void类型
argv参数就是 "eth0"
"eth1"
struct ifreq ifreq; int sock;
if(argc!=2){ printf("Usage : ethname\n"); return ; }
if((sock=socket(AF_INET,SOCK_STREAM,0))<0){ perror("socket"); return ; } strcpy(ifreq.ifr_name,argv[1]); //也可将argv[1]直接写成"eth0",
if((sock=socket(AF_INET,SOCK_STREAM,0))<0){ perror("socket"); return ; } strcpy(ifreq.ifr_name,
); //也可将argv[1]直接写成"eth0",
//变成 void main(void) if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0) { perror("ioctl"); return ; } 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]); //打印结果 return ; }
上一篇:gdb 调试 启动 使用 备忘
下一篇:gtags 中文man
登录 注册