#include <stdlib.h>
#include <stdio.h>
// 소켓 함수 오류 출력
void err_display(char *msg)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL);
printf("[%s] %s", msg, (LPCTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
}
int main(int argc, char* argv[])
{
HOSTENT *myhost;
IN_ADDR myinaddr;
int i;
WSADATA wsa;
if(WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
return -1;
myhost = gethostbyname("www.yahoo.co.kr");
if (myhost == NULL)
{
err_display("gethostbyname()");
exit(0);
}
printf("official host name : \t\t%s\n", myhost->h_name);
i = 0;
while(myhost->h_aliases[i] != NULL)
{
printf( "aliases name : \t\t\t%s\n", myhost->h_aliases[i] );
i++;
}
printf("host address type : \t\t%d\n", myhost->h_addrtype);
printf("length of host address : \t%d\n", myhost->h_length);
i = 0;
while(myhost->h_addr_list[i] != NULL)
{
myinaddr.s_addr = *( (u_long *)(myhost->h_addr_list[i]) ) ;
printf("IP address : \t\t\t%s\n", inet_ntoa(myinaddr)) ;
i++;
}
WSACleanup();
return 0;
}