获取主机名和主机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;
}
}
{
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;
}
}