/* tstgethbn.c Test for gesthostbyname */ #include #include #include #include int main(int argc, char** argv) { char hostname[65]; struct hostent *he = NULL; struct hostent *he2 = NULL; extern int h_errno; strcpy(hostname, argv[1]); printf( " Looking up %s\n", hostname ); he = gethostbyname(hostname); if ( h_errno ) { printf(" error %d\n", h_errno); herror(hostname); } if ( he == NULL ){ printf("No hostname found\n"); exit(1); } printf( "\t Hostname: %s\n", he->h_name ); if ( he->h_addr_list[0] != NULL ) printf("\t Address: %s \n", inet_ntoa(*(struct in_addr *) he->h_addr_list[0])); he2 = gethostbyaddr( he->h_addr_list[0], he->h_length, he->h_addrtype ); printf( "\t Name: %s\n", he2->h_name ); exit(0); }