Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1461344
  • 博文数量: 408
  • 博客积分: 10036
  • 博客等级: 上将
  • 技术积分: 4440
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-06 13:57
文章分类

全部博文(408)

文章存档

2011年(1)

2010年(2)

2009年(1)

2008年(3)

2007年(7)

2006年(394)

我的朋友

分类: C/C++

2006-07-24 17:53:35

获得网卡MAC地址
#include
#include
#include
#include
#include
#include

int main(int argc, char **argv)
{
        int nSocket;
        struct ifreq struReq;

        nSocket = socket(PF_INET,SOCK_STREAM,0);

        memset(&struReq,0,sizeof(struReq));
        if(argc < 2)
                strncpy(struReq.ifr_name, "eth0", sizeof(struReq.ifr_name));
        else
                strncpy(struReq.ifr_name, argv[1], sizeof(struReq.ifr_name));
        ioctl(nSocket,SIOCGIFHWADDR,&struReq);
        fprintf(stderr, "%d-%s\n", __LINE__, strerror(errno));

        printf("%s\n", ether_ntoa(struReq.ifr_hwaddr.sa_data));
        close(nSocket);
}
阅读(2495) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~