CString GetLocalIP()
{
  WORD wVersionRequested;
  WSADATA wsaData;
  char name[255];
  CString ip; // 여기에 lcoal ip가 저장됩니다.
  PHOSTENT hostinfo;
  wVersionRequested = MAKEWORD( 2, 0 );
        
  if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
  {
        
        if( gethostname ( name, sizeof(name)) == 0)
        {
                if((hostinfo = gethostbyname(name)) != NULL)
                {
                  ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
                }
        }      
        WSACleanup( );
  }
  return ip;
}

+ Recent posts