获取主机IP地址
void CIPControlDlg::OnBnClickedButtonGetipc()
{
// TODO: 在此添加控件通知处理程序代码
WORD wVersionRequested;
WSADATA wsaData;
char name[256]; //当前主机名
CString ip; //主机ip
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD(2, 0);
if (0 == WSAStartup(wVersionRequested, &wsaData))
{
if (0 == gethostname(name, sizeof(name)))
{
if (NULL != (hostinfo = gethostbyname(name)))
{
ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup();
}
m_IpAddress.SetWindowText(ip);
}