BOOL GetRealIpByDomainName(char *szHost, char szIp[50][100], int *nCount)
{
WSADATA wsaData;
HOSTENT *pHostEnt;
int nAdapter = 0;
struct sockaddr_in sAddr;
if (WSAStartup(0x0101, &wsaData))
{
printf(" gethostbyname error for host:\n");
return FALSE;
}
pHostEnt = gethostbyname(szHost);
if (pHostEnt)
{
while (pHostEnt->h_addr_list[nAdapter])
{
memcpy(&sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter], pHostEnt->h_length);
sprintf_s(szIp[nAdapter], "%s", inet_ntoa(sAddr.sin_addr));
nAdapter++;
}
*nCount = nAdapter;
}
else
{
DWORD dwError = GetLastError();
*nCount = 0;
}
WSACleanup();
return TRUE;
}
来源:CSDN
作者:hu421160052
链接:https://blog.csdn.net/hu421160052/article/details/104791726