1. std::string VengFuncConfig::GetLocalHostIp(void
  2.     vector vLocalIpList; 
  3.     string sLocalIP; 
  4.     sLocalIP.clear(); 
  5.     WSADATA wsaData; 
  6.     char name[155]={0}; 
  7.     if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 ) 
  8.     { 
  9.         if(gethostname(name,sizeof(name)) == 0) 
  10.         { 
  11.             struct hostent* pHost = gethostbyname(name); 
  12.             if (0 == pHost ) 
  13.             { 
  14.                 return sLocalIP; 
  15.             } 
  16.             for (int i = 0; pHost->h_addr_list[i] != 0; ++i) 
  17.             { 
  18.                 struct in_addr addr; 
  19.                 memcpy(&addr, pHost->h_addr_list[i], sizeof(struct in_addr)); 
  20.                 vLocalIpList.push_back(inet_ntoa(addr));     
  21.             } 
  22.         } 
  23.         WSACleanup( ); 
  24.     } 
  25.     //所有的IP地址都在vLocalIpList中 
  26.     int nLength = vLocalIpList.size(); 
  27.    //优先获取10.10.子网IP 
  28.     for(int i=0;i < nLength;i++)
  29.     { 
  30.         if (vLocalIpList[i].find("10.10.") != -1) 
  31.         { 
  32.             sLocalIP = vLocalIpList[i]; 
  33.         } 
  34.     } 
  35.   //如没有子网IP,则获取外网IP 
  36.     if (sLocalIP.empty()) 
  37.     { 
  38.         for(int i=0;i < nLength;i++)
  39.         { 
  40.             if (vLocalIpList[i].find("192.168.") == -1) 
  41.             { 
  42.                 sLocalIP = vLocalIpList[i]; 
  43.             } 
  44.         } 
  45.     } 
  46.  
  47.     return sLocalIP;