void getrealip(string& strSrc,string& strResult)
{
strResult = "";
if (strSrc.empty())
{
return;
}
char chIp[INET_ADDRSTRLEN];
struct hostent * phost = gethostbyname(strSrc.c_str());
if (NULL == phost)
{
return;
}
char ** pptemp = phost->h_addr_list;
if (NULL == pptemp)
{
return;
}
if ((phost->h_addrtype==AF_INET) && (*pptemp!=NULL))
{
//string为空时,不能使用printf函数,否则会崩溃
strResult = (NULL!=inet_ntop(phost->h_addrtype, *pptemp, chIp, sizeof(chIp)))?string(chIp):"";
}
}