GETHOSTBYADDR(3n,L) AIX Technical Reference GETHOSTBYADDR(3n,L) ------------------------------------------------------------------------------- gethostbyaddr, gethostbyname, sethostent, endhostent PURPOSE Get network host entry. LIBRARY Internet Library (libc.a) SYNTAX #include struct hostent *gethostbyaddr(addr, len, type) void sethostent(stayopen) char *addr; int stayopen; int len, type; void endhostent() struct hostent *gethostbyname(name) char *name; DESCRIPTION The gethostbyname and gethostbyaddr subroutines each return a pointer to an object. This object is a hostent structure, which contains information obtained from the name server program, or a field from a line in the /etc/hosts file (the network host data base). If the local name server is not running, these routines do a lookup in /etc/hosts. The hostent structure is defined in the netdb.h header file, and it contains the following members: char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses from name server */ #define h_addr h_addr_list[0] /* address, for backward compatibility */ The members of this structure are: h_name Official name of the host. h_aliases A zero terminated array of alternate names for the host. Processed July 12, 1991 GETHOSTBYADDR(3n,L) 1 GETHOSTBYADDR(3n,L) AIX Technical Reference GETHOSTBYADDR(3n,L) h_addrtype The type of address being returned. The subroutine always sets this value to AF_INET. h_length The length, in bytes, of the address. h_addr_list An array, terminated by 0, of pointers to the network addresses for the host. Host addresses are returned in network byte order. h_addr The first address in h_addr_list, provided for backward compatibility. The sethostent subroutine allows a request for the use of a connected socket using TCP for queries. If the stayopen parameter is nonzero, an option is set to send all queries to the name server using TCP and to retain the connection after each call to gethostbyname or gethostbyaddr. The endhostent subroutine closes the TCP connection. The gethostbyname and gethostbyaddr subroutines query the name server or search the file sequentially from its beginning until finding a matching host name or host address, or until encountering the end of the file. Host addresses are supplied in network order. RETURN VALUE The gethostbyname and gethostbyaddr subroutines return a pointer to a hostent structure on success. Note: The return value points to static data that is overwritten by subsequent calls. A NULL pointer (0) is returned if an error occurs or the end of the file is reached and the h_errno variable is set to indicate the error. ERROR CONDITIONS The gethostbyname and gethostbyaddr subroutines fail if one or more of the following are true: HOST_NOT_FOUND The host specified by the name parameter was not found. TRY_AGAIN The local server did not receive a response from an authoritative server. Try again later. NO_RECOVERY This error code indicates an unrecoverable error. Processed July 12, 1991 GETHOSTBYADDR(3n,L) 2 GETHOSTBYADDR(3n,L) AIX Technical Reference GETHOSTBYADDR(3n,L) NO_ADDRESS The requested name is valid but does not have an Internet address at the name server. FILES /etc/hosts Host name data base. /etc/resolv.conf Name server and domain name data base. RELATED INFORMATION In this book: "Related Network Publications." The discussion of host, named, and resolv.conf in AIX TCP/IP User's Guide. Processed July 12, 1991 GETHOSTBYADDR(3n,L) 3