#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/ioctl.h> #include <net/if.h> #include <netinet/if_ether.h> #include <string.h> #include <netinet/ether.h> #include<unistd.h> int main(int argc, char **argv) { printf("helloworld/n"); 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( (const ether_addr*)(struReq.ifr_ifru.ifru_hwaddr.sa_data))); close(nSocket); } man reference http://linux.die.net/man/7/netdevice