• 首页
  • 小学语文
  • 中学语文
  • 中学英语
  • 免费论文
  • 教学随笔
  • 学生作文
  • 综合考试
  • 试题教案
  • 育儿话题
  • 教学资源
  • 编程技术
  • 博客
  • 获取本机的第一个IP(常用例程:1)

    日期:2002-08-05  地址:  作者:

    我只是收藏一下而已

    #include "winsock2.h"
    #pragma comment( lib, "ws2_32" )
    const char* get_first_ip(void)
    {
      char szHostName[128];
      const char* pszAddr = NULL;
      struct hostent * pHost;
      int i;
      WSADATA wsaData;
      WSAStartup(0x202, &wsaData );
      if( gethostname(szHostName, 128) == 0 )
      {
        pHost = gethostbyname(szHostName);
        for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )    
        {/*对每一个IP地址进行处理*/
           pszAddr = inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
        break;
        }
      }
      WSACleanup();
      return pszAddr;
    }

    对 获取本机的第一个IP(常用例程:1) 文章的评论    [查看网友评论]

    验证码:
    匿名发表: