#include #include #include #include #include #include #include int main(int argc, char** argv) { unsigned int addr; struct hostent *hp; struct in_addr s; int i; if(argc != 2) { fprintf(stderr, "Usage: %s ip-address\n", argv[0]); return 1; } addr = inet_addr(argv[1]); if(addr == 0xffffffff && strcmp(argv[1], "255.255.255.255") != 0) { fprintf(stderr, "Invalid argument: %s\n", argv[1]); return 1; } hp = gethostbyaddr((char *)&addr, 4, AF_INET); if(hp == NULL) { fprintf(stderr, "Can't get a network host entry for %s\n", argv[1]); return 1; } printf("OfficialName: %s\n", hp->h_name); printf("Aliases:"); for(i = 0; hp->h_aliases[i]; i++) printf(" %s", hp->h_aliases[i]); printf("\n"); printf("HostAddressType: %d\n", hp->h_addrtype); printf("AddressLength: %d\n", hp->h_length); printf("Address:"); for(i = 0; hp->h_addr_list[i]; i++) { memcpy(&s, hp->h_addr_list[i], 4); printf(" %s", inet_ntoa(s)); } printf("\n"); return 0; }