Windows下获取本机IP地址方法介绍

Windows下获取本机IP地址方法介绍

            if((hostinfo = gethostbyname(name)) != NULL)
            {
#if 1
                int i=0;
                printf("IP COUNT: %d
",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
", 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
", ++nCount, ip);
                }
#endif
            }

aa

原文地址:https://www.cnblogs.com/jingzhishen/p/6219387.html