bool fn_bGetIPLocation(string sDomainName, string& sIP) {
if(sDomainName.empty())
return false;
hostent* pHostent = NULL;
for(int i=0; (i<MAX_TRY_GETMSG-1)&&(pHostent == NULL); i++)
{
pHostent = gethostbyname(sDomainName.c_str());
if(pHostent == NULL)
Sleep(2000);
}
if(pHostent != NULL) {
hostent& he = *pHostent;
for(int iAdapter=0; he.h_addr_list[iAdapter]; iAdapter++) {
sIP = inet_ntoa(*(in_addr*)he.h_addr_list[iAdapter]); // 目前只保存IP列表的最后一个,也可全部都保存下来
}
}
return true;
}
1081

被折叠的 条评论
为什么被折叠?



