void CDebugDlg::OnBnClickedButton6()
{
// TODO: 在此添加控件通知处理程序代码
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD(2, 0);
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == SOCKET_ERROR)
{
MessageBox("error");
}
else
{
hostent* phostent = gethostbyname(name);//根据主机名获取本机的地址列表
hostent& he = *phostent;
sockaddr_in sa;
for (int i = 0; he.h_addr_list[i]; i++) //读取地址列表并显示出来
{
memcpy(&sa.sin_addr.s_addr, he.h_addr_list[i], he.h_length);
m_output = inet_ntoa(sa.sin_addr);//m_output为显示编辑框变量
UpdateData(FALSE);
}
}
WSACleanup();
}
}
08-15
08-15