But can individual call via ioctl be faster?
struct sockaddr_in *addr;
struct ifreq ifr;
char *address;
int sockfd;
char *name = "en0";
if(strlen(name)>=IFNAMSIZ)
printf("device name is error.\n"),exit(0);
strcpy(ifr.ifr_name,name);
sockfd=socket(AF_INET,SOCK_DGRAM,0);
//get inet addr
if(ioctl(sockfd,SIOCGIFADDR,&ifr)<0)
printf("ioctl error!!!\n"),exit(0);
addr = (struct sockaddr_in *)&(ifr.ifr_addr);
address=inet_ntoa(addr->sin_addr);
printf("inet addr:%s\n",address);