GETIPNODEBYNAME(3) FreeBSD Library Functions Manual GETIPNODEBYNAME(3) NNAAMMEE ggeettiippnnooddeebbyynnaammee, ggeettiippnnooddeebbyyaaddddrr -- get network host entry ffrreeeehhoosstteenntt -- free network host entry SSYYNNOOPPSSIISS ##iinncclluuddee <> _s_t_r_u_c_t _h_o_s_t_e_n_t _* ggeettiippnnooddeebbyynnaammee(_c_o_n_s_t _c_h_a_r _*_n_a_m_e, _i_n_t _a_f, _i_n_t _f_l_a_g_s, _i_n_t _*_e_r_r_o_r); _s_t_r_u_c_t _h_o_s_t_e_n_t _* ggeettiippnnooddeebbyyaaddddrr(_c_o_n_s_t _v_o_i_d _*_a_d_d_r, _s_i_z_e___t _l_e_n, _i_n_t _a_f, _i_n_t _*_e_r_r_o_r); _v_o_i_d ffrreeeehhoosstteenntt(_s_t_r_u_c_t _h_o_s_t_e_n_t _*_h_e); DDEESSCCRRIIPPTTIIOONN GGeettiippnnooddeebbyynnaammee(), and ggeettiippnnooddeebbyyaaddddrr() each return a pointer to a _h_o_s_t_e_n_t structure (see below) describing an internet host referenced by name or by address, as the function names indicate. This structure con- tains either the information obtained from the name server, or broken-out fields from a line in _/_e_t_c_/_h_o_s_t_s. If the local name server is not run- ning, these routines do a lookup in _/_e_t_c_/_h_o_s_t_s. struct hostent { 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. h_addrtype The type of address being returned. h_length The length, in bytes, of the address. h_addr_list A zero-terminated array of network addresses for the host. Host addresses are returned in network byte order. h_addr The first address in h_addr_list; this is for backward com- patibility. This structure should be freed after use by calling ffrreeeehhoosstteenntt(). When using the nameserver, ggeettiipphhoossttbbyyaaddddrr() will search for the named host in each parent domain given in the ``search'' directive of resolv.conf(5) unless the name contains a dot (``.''). If the name con- tains no dot, and if the environment variable HOSTALIASES contains the name of an alias file, the alias file will first be searched for an alias matching the input name. See hostname(7) for the domain search procedure and the alias file format. GGeettiipphhoossttbbyyaaddddrr() can be told to look for IPv4 addresses, IPv6 addresses or both IPv4 and IPv6. If IPv4 addresses only are to be looked up then _a_f should be set to AF_INET, otherwise it should be set to AF_INET6. There are three flags that can be set AI_V4MAPPED Return IPv4 addresses if no IPv6 addresses are found. This flag is ignored unless _a_f is AF_INET6. AI_ALL Return IPv4 addresses as well IPv6 addresses if AI_V4MAPPED is set. This flag is ignored unless _a_f is AF_INET6. AI_ADDRCONFIG Only return addresses of a given type if the system has an active interface with that type. Also AI_DEFAULT is defined to be (AI_V4MAPPED|AI_ADDRCONFIG). GGeettiippnnooddeebbyyaaddddrr() will lookup IPv4 mapped and compatible addresses in the IPv4 name space and IPv6 name space FFrreeeehhoosstteenntt() frees the hostent structure allocated be ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr(). The structures returned by ggeetthhoossttbbyynnaammee(), ggeetthhoossttbbyynnaammee22(), ggeetthhoossttbbyyaaddddrr() and ggeetthhoosstteenntt() should not be passed to ffrreeeehhoosstteenntt() as they are pointers to static areas. EENNVVIIRROONNMMEENNTT HOSTALIASES Name of file containing (_h_o_s_t _a_l_i_a_s, _f_u_l_l _h_o_s_t_n_a_m_e) pairs. FFIILLEESS /etc/hosts See hosts(5). DDIIAAGGNNOOSSTTIICCSS Error return status from ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() is indi- cated by return of a null pointer. In this case _e_r_r_o_r may then be checked to see whether this is a temporary failure or an invalid or unknown host. _e_r_r_n_o can have the following values: NETDB_INTERNAL This indicates an internal error in the library, unrelated to the network or name service. _e_r_r_n_o will be valid in this case; see perror. HOST_NOT_FOUND No such host is known. TRY_AGAIN This is usually a temporary error and means that the local server did not receive a response from an authoritative server. A retry at some later time may succeed. NO_RECOVERY Some unexpected server failure was encountered. This is a non-recoverable error, as one might expect. NO_ADDRESS The requested name is valid but does not have an IP address; this is not a temporary error. This means that the name is known to the name server but there is no address associated with this name. Another type of request to the name server using this domain name will result in an answer; for example, a mail-forwarder may be registered for this domain. SSEEEE AALLSSOO hosts(5), hostname(7), resolver(3), resolver(5), gethostbyname(3), RFC2553. 4th Berkeley Distribution September 17, 1999 4th Berkeley Distribution