获取主机名和主机IP

void CInterChatApp::GetHostInfo(CString &hostIP,CString &hostname)
{
   DWORD   dwsize   =   255;   
   char   username[255];  
   if(::GetComputerName(&username[0],   &dwsize))
   { 
      hostent   *pHost; 
      pHost=::gethostbyname(username); 
      LPCSTR   psz; 
      psz=inet_ntoa   (*(struct   in_addr   *)pHost-> h_addr_list[0]); 
      hostIP =  (CString)psz; 
      hostname = (CString)username;
   }
}
posted @ 2010-06-05 15:54  zhouli  阅读(192)  评论(0编辑  收藏  举报