DNS转IP地址

测试环境:VS2010SP1

void CFileTransferDlg::OnBnClickedDns2ip()
{
	//positive sample
	hostent* pHost = gethostbyname("www.sohu.com");
	if(pHost != NULL)
	{
		while(*pHost->h_addr_list != NULL)
		{
			TRACE("Positive Sample,IP:[%s]\n", inet_ntoa(*(struct in_addr *)*pHost->h_addr_list));
			//Positive Sample,IP:[202.55.12.17]
			*pHost->h_addr_list++;
		}
	}

	//negative sample
	{
		hostent* pHost = gethostbyname("202.55.12.17");
		if(pHost != NULL)
		{
			while(*pHost->h_addr_list != NULL)
			{
				TRACE("Negative Sample,IP:[%s]\n", inet_ntoa(*(struct in_addr *)*pHost->h_addr_list));
				//"Negative Sample,IP:[202.55.12.17]"
				*pHost->h_addr_list++;
			}
		}
	}
}


你可能感兴趣的:(DNS转IP地址)