获得本机的多个IP地址
时间:2011-05-29 来源:宇智波Q
现在的电脑可能有多个网卡,存在多个IP地址,需要将IP地址都读取出来
CStringArray strIPList;
WSADATA wsd;
if (WSAStartup(MAKEWORD(2, 2), &wsd) == 0)
{
CHAR pHostName[256] = {0};
if(gethostname(pHostName, 256) != SOCKET_ERROR)
{
struct hostent *psHost = gethostbyname(pHostName);
if(psHost)
{
CString strIP;
for (int i = 0; psHost->h_addr_list[i]; ++i)
{
strIP = inet_ntoa (*(struct in_addr *)psHost->h_addr_list[i]);
strIPList.Add(strIP);
}
}
}
}
WSACleanup();
相关阅读 更多 +
排行榜 更多 +