1 /* 2 * gethostbyaddr tester. compile with: 3 * 4 * cc -o gethostbyaddr gethostbyaddr.c (SunOS 4.x) 5 * 6 * cc -o gethostbyaddr gethostbyaddr.c -lnsl (SunOS 5.x) 7 * 8 * run as: gethostbyaddr address 9 * 10 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 11 */ 12 13#include <sys/types.h> 14#include <sys/socket.h> 15#include <netinet/in.h> 16#include <arpa/inet.h> 17#include <netdb.h> 18#include <stdio.h> 19 20main(argc, argv) 21int argc; 22char **argv; 23{ 24 struct hostent *hp; 25 long addr; 26 27 if (argc != 2) { 28 fprintf(stderr, "usage: %s i.p.addres\n", argv[0]); 29 exit(1); 30 } 31 addr = inet_addr(argv[1]); 32 if (hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) { 33 printf("Hostname:\t%s\n", hp->h_name); 34 printf("Aliases:\t"); 35 while (hp->h_aliases[0]) 36 printf("%s ", *hp->h_aliases++); 37 printf("\n"); 38 printf("Addresses:\t"); 39 while (hp->h_addr_list[0]) 40 printf("%s ", inet_ntoa(*(struct in_addr *) * hp->h_addr_list++)); 41 printf("\n"); 42 exit(0); 43 } 44 fprintf(stderr, "host %s not found\n", argv[1]); 45 exit(1); 46} 47