Created
June 13, 2014 03:44
-
-
Save wateroot/a70b2a33188d9c4f91f5 to your computer and use it in GitHub Desktop.
GetIpByHostName
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int GetIpByHostName(char szHost) | |
{ | |
struct hostent *rmtHost = NULL; | |
struct in_addr stAddr = {0}; | |
if (NULL == szHost) { | |
Log("GetIpByHostName input null.\n"); | |
return -1; | |
} | |
rmtHost = gethostbyname(szHost); | |
if (NULL == rmtHost) { | |
Log("gethostbyname fail. erron=[%d].\n", GetLastError()); | |
return -1; | |
} | |
if (AF_INET == remoteHost->h_addrtype) | |
{ | |
while (remoteHost->h_addr_list[i] != 0) { | |
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; | |
printf("\tIP Address #%d: %s\n", i, inet_ntoa(addr)); | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment