分类: C/C++
2006-10-04 21:07:21
#include #include #include #include int main(int argc,char **argv) { struct hostent * hostp; struct in_addr addr; char **pp; if (argc != 2) { fprintf(stderr, "usage: %s exit(0); } if(inet_aton(argv[1],&addr) != 0) { hostp = gethostbyaddr((const char *)&addr,sizeof(addr),0); } else hostp = gethostbyname(argv[1]); printf("Name: %s\n",hostp->h_name); for(pp=hostp->h_aliases;*pp!=NULL;pp++) printf("Aliases: %s\n",*pp); for(pp=hostp->h_addr_list;*pp!=NULL;pp++) { addr.s_addr = (*(unsigned int *)*pp); printf("Address: %s\n",inet_ntoa(addr)); } return 0; } |