文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>获取主机MAC地址

获取主机MAC地址

时间:2006-10-18  来源:fytzzh

获取主机MAC地址的代码:   #include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <linux/if_ether.h>

int main()
{
    struct ifreq ifr;
    int sock;
    unsigned char *ptr;
    int status;
    strcpy (ifr.ifr_name , "eth0");     sock = socket (PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
    if (sock == -1)
    {
        perror ("socket error ");
        return -1;
    }
    status = ioctl (sock, SIOCGIFHWADDR, &ifr);
    if (status < 0)
    {
        perror ("ioctl error ");
        close (sock);
        return -2;
    }
    ptr = ifr.ifr_hwaddr.sa_data;
    printf("%02x.%02x.%02x.%02x.%02x.%02x\n",
            ptr[0], ptr[1],ptr[2],ptr[3],ptr[4],ptr[5]);
}
相关阅读 更多 +
排行榜 更多 +
我是汪汪小画家

我是汪汪小画家

休闲益智 下载
中厦全供

中厦全供

购物比价 下载
越砍越低价

越砍越低价

购物比价 下载