/* This is a program written by Mike Dilger, and prettied up a bit by Sam Lantinga: In case you ever have an internet address and want to know the machine name, or the other way around, use hostinfo: */ #include <errno.h> #include <signal.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <ctype.h> struct hostent *server_info; /* server name/address info */ int herror(); void main(argc, argv) int argc; char *argv[]; { struct in_addr addr; int scan; if ( argc < 2 ) { printf("Usage: %s [address|hostname]\n", argv[0]); exit(1); } printf("[ %s ]\n", argv[1]); fflush(stdout); if ( isdigit(argv[1][0]) ) /* get by address */ { addr.s_addr=inet_addr(argv[1]); if ( (server_info=gethostbyaddr(&(addr.s_addr), sizeof(int), AF_INET)) == NULL ) { fprintf(stderr, "host name error: "); herror(argv[1]); exit(1); } } else { if ( (server_info=gethostbyname(argv[1])) == NULL ) { fprintf(stderr, "host name error: "); herror(argv[1]); exit(1); } } printf("\nHostname: %s\n", server_info->h_name); if ( server_info->h_aliases != NULL ) { printf("Aliases: "); scan=0; while( server_info->h_aliases[scan] != NULL ) printf("%s\n ", server_info->h_aliases[scan++]); printf("\n"); } if (server_info->h_addr_list!=NULL) { printf("Addresses: "); scan=0; while( server_info->h_addr_list[scan] != NULL ) { bcopy(server_info->h_addr_list[scan++], &(addr.s_addr), 4); printf("%s\n ", inet_ntoa(addr)); } printf("\n"); } } extern int h_errno; int herror(str) char *str; { printf("%s: ",str); switch(h_errno) { case 0: printf("No error.\n"); break; case HOST_NOT_FOUND: printf("Host not found.\n"); break; case TRY_AGAIN: printf("Try again.\n"); break; case NO_RECOVERY: printf("No recovery.\n"); break; case NO_DATA: printf("No data or no addresss.\n"); break; default: printf("Unknown error.\n"); } } /* -------------------------------------------------------------------- _/ _/ _/_/_/ _/ _/ _/_/_/_/ Jesus Saves _/_/ _/_/ _/ _/_/_/ _/_/ ... but Hernando gets _/ _/ _/ _/ _/ _/ _/ the rebound... he shoots, _/ _/ _/_/_/ _/ _/ _/_/_/_/ he scores!!! Michael Dilger dilger@toadflax.cs.ucdavis.edu -------------------------------------------------------------------- */