jingzhishen

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

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-06-12
  • 2021-10-30
  • 2021-10-14
  • 2022-02-18
  • 2021-10-21
  • 2022-02-23
猜你喜欢
  • 2021-10-09
  • 2021-05-20
  • 2021-09-25
  • 2021-12-24
  • 2021-09-13
  • 2022-12-23
相关资源
相似解决方案