域名解析IP函数:
windows版本:
#include <winsock2.h>
struct hostent *gethostbyname(const char *name);
linux版本:
#include <netdb.h>
struct hostent *gethostbyname(const char *hostname);
返回值:非空指针——成功,空指针——出错
示例:
struct hostent *h;
if((h=gethostbyname(strDomain.data()))==NULL)
{
return false;
}
string strIP = inet_ntoa(*((struct in_addr *)h->h_addr));