Windows下获取本机IP地址方法介绍
if((hostinfo = gethostbyname(name)) != NULL) { #if 1 int i=0; printf("IP COUNT: %d\r\n",hostinfo->h_length); for(i=0;i<hostinfo->h_length;i++) { ip = inet_ntoa (*(struct in_addr *)hostinfo->h_addr_list[i]); printf("IP #%d: %s\n", i+1, ip); } #else int nCount = 0; while(hostinfo->h_addr_list[nCount]) { ip = inet_ntoa (*(struct in_addr *)hostinfo->h_addr_list[nCount]); printf("IP #%d: %s\n", ++nCount, ip); } #endif }
aa