#include
#include
#include
int main(int argc, char **argv)
{
char *ptr, **pptr;
struct hostent *hptr;
char str[32];
ptr = argv[1];
hptr = gethostbyname(ptr);
if(NULL == hptr)
{
printf(" gethostbyname error\n");
return 0;
}
printf("hostname:%s\n", hptr->h_name);
for(pptr = hptr->h_aliases; *pptr != NULL; pptr++)
printf(" pptr:%s\n",*pptr);
switch(hptr->h_addrtype)
{
case AF_INET:
case AF_INET6:
pptr=hptr->h_addr_list;
for(; *pptr!=NULL; pptr++)
{
inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str));
printf("address: %s\n", str);
}
break;
}
return 0;
}