////用户输入的是计算机名, 进行地址解析得到计算机IP//// structhostent *host; structin_addr *ptr;// To retrieve the IP Addresshost = gethostbyname(m_strComputerName); if (host!=NULL) { ptr = (struct in_addr *) host->h_addr_list[0];int a = ptr->S_un.S_un_b.s_b1; // Eg. 211.40.35.76 split up like this. int b = ptr->S_un.S_un_b.s_b2; // 40 int c = ptr->S_un.S_un_b.s_b3; // 35 int d = ptr->S_un.S_un_b.s_b4; // 76m_strComputerIP.Format("%d.25d.%d.%d",a,b,c,d); } else { m_strComputerIP.Format("Unresolved(%s)", m_strComputerName); }
structhostent *host;
structin_addr *ptr;// To retrieve the IP Addresshost = gethostbyname(m_strComputerName);
if (host!=NULL)
{
ptr = (struct in_addr *) host->h_addr_list[0];int a = ptr->S_un.S_un_b.s_b1; // Eg. 211.40.35.76 split up like this.
int b = ptr->S_un.S_un_b.s_b2; // 40
int c = ptr->S_un.S_un_b.s_b3; // 35
int d = ptr->S_un.S_un_b.s_b4; // 76m_strComputerIP.Format("%d.25d.%d.%d",a,b,c,d);
}
else
{
m_strComputerIP.Format("Unresolved(%s)", m_strComputerName);
}
#include "Winsock2.h"还有加入
mpr.lib ws2_32.lib