# Include <stdlib. h> # include <stdio. h> # include <netdb. h> # include <sys/socket. h> # include <netinet/in. h> # include <ARPA/inet. h> int main (INT argc, char ** argv) {char * PTR, ** pptr; struct hostent * hptr; char STR [32]; char ipaddr [16]; struct in_addr * hipaddr = (struct in_addr *) malloc (sizeof (struct in_addr); PTR = argv [1]; printf ("0: % s \ n", PTR ); if (! Inet_aton (PTR, hipaddr) {printf ("error1 \ n"); return 1 ;}if (hptr = gethostbyaddr (hipaddr, 4, af_inet) = NULL) {h_errno; printf ("err2% s \ n", PTR); Switch (h_errno) {Case host_not_found: printf ("111 \ n"); break; // case no_address: // case no_data: printf ("112 \ n"); break; Case no_recovery: printf ("113 \ n"); break; Case try_again: printf ("115 \ n"); break;} return 1;} printf ("hostname: % s \ n", hptr-> h_name ); for (pptr = hptr-> h_alia SES; * pptr! = NULL; pptr ++) printf ("% s \ n", * pptr); Switch (hptr-> h_addrtype) {Case af_inet: Case af_inet6: pptr = hptr-> h_addr_list; For (; * pptr! = NULL; pptr ++) printf ("Address: % s \ n", inet_ntop (hptr-> h_addrtype, * pptr, STR, sizeof (STR); break; default: printf ("Default \ n"); break;} return 0;}/** // The gethostbyname () and gethostbyaddr () returned by the http://www.rosoo.net/a/201105/11535.html () the hostent structure or NULL pointer returned by the function. If an error occurs. When an error occurs, the variable h_errno stores the error code. The variable h_errno of an error may have the following values: the host specified by host_not_found is unknown. The no_address or no_data Request Name is valid, but there is no IP address. No_recovery the name server cannot be recovered. Try_again a temporary error occurs on the authoritative Domain Name Server. Please try again later. **/