#include #include #include /* 4 gethostbyname, hostent structure */ #include /* 4 exit */ #include /* 4 ntohn */ int main(int argc, char *argv[]) { int i,j; struct hostent *he; if (argc != 2) { fprintf(stderr,"usage: %s hostname\n", argv[0]); return 1; } if ((he = gethostbyname(argv[1])) == NULL) { fprintf(stderr, "gethostbyname error\n"); return 1; } /* host info: */ printf("\nHost name: %s", he->h_name); printf("\nAliases:"); for(i=0;he->h_aliases[i] != NULL;++i) printf("\n%d. %s", i+1, he->h_aliases[i]); if(he->h_addrtype == AF_INET) printf("\nAddres type: IPv4"); if(he->h_addrtype == AF_INET6) printf("\nAddres type: IPv6"); printf("\nAddress length: %d bytes", he->h_length); printf("\nAddresses:"); for(j=0;jh_length;++j) { printf("%d", (uint8_t)he->h_addr[j]); if(j < (he->h_length-1)) printf("."); } printf("\n"); return 0; }