1GETIPNODEBYNAME(3) FreeBSD Library Functions Manual GETIPNODEBYNAME(3) 2 3NNAAMMEE 4 ggeettiippnnooddeebbyynnaammee, ggeettiippnnooddeebbyyaaddddrr -- get network host entry 5 ffrreeeehhoosstteenntt -- free network host entry 6 7SSYYNNOOPPSSIISS 8 ##iinncclluuddee <<nneettddbb..hh>> 9 10 _s_t_r_u_c_t _h_o_s_t_e_n_t _* 11 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); 12 13 _s_t_r_u_c_t _h_o_s_t_e_n_t _* 14 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); 15 16 _v_o_i_d 17 ffrreeeehhoosstteenntt(_s_t_r_u_c_t _h_o_s_t_e_n_t _*_h_e); 18 19DDEESSCCRRIIPPTTIIOONN 20 GGeettiippnnooddeebbyynnaammee(), and ggeettiippnnooddeebbyyaaddddrr() each return a pointer to a 21 _h_o_s_t_e_n_t structure (see below) describing an internet host referenced by 22 name or by address, as the function names indicate. This structure con- 23 tains either the information obtained from the name server, or broken-out 24 fields from a line in _/_e_t_c_/_h_o_s_t_s. If the local name server is not run- 25 ning, these routines do a lookup in _/_e_t_c_/_h_o_s_t_s. 26 27 struct hostent { 28 char *h_name; /* official name of host */ 29 char **h_aliases; /* alias list */ 30 int h_addrtype; /* host address type */ 31 int h_length; /* length of address */ 32 char **h_addr_list; /* list of addresses from name server */ 33 }; 34 35 #define h_addr h_addr_list[0] /* address, for backward compatibility */ 36 37 The members of this structure are: 38 39 h_name Official name of the host. 40 41 h_aliases A zero-terminated array of alternate names for the host. 42 43 h_addrtype The type of address being returned. 44 45 h_length The length, in bytes, of the address. 46 47 h_addr_list A zero-terminated array of network addresses for the host. 48 Host addresses are returned in network byte order. 49 50 h_addr The first address in h_addr_list; this is for backward com- 51 patibility. 52 53 This structure should be freed after use by calling ffrreeeehhoosstteenntt(). 54 55 When using the nameserver, ggeettiipphhoossttbbyyaaddddrr() will search for the named 56 host in each parent domain given in the ``search'' directive of 57 resolv.conf(5) unless the name contains a dot (``.''). If the name con- 58 tains no dot, and if the environment variable HOSTALIASES contains the 59 name of an alias file, the alias file will first be searched for an alias 60 matching the input name. See hostname(7) for the domain search procedure 61 and the alias file format. 62 63 GGeettiipphhoossttbbyyaaddddrr() can be told to look for IPv4 addresses, IPv6 addresses 64 or both IPv4 and IPv6. If IPv4 addresses only are to be looked up then 65 _a_f should be set to AF_INET, otherwise it should be set to AF_INET6. 66 67 There are three flags that can be set 68 69 AI_V4MAPPED Return IPv4 addresses if no IPv6 addresses are found. 70 This flag is ignored unless _a_f is AF_INET6. 71 72 AI_ALL Return IPv4 addresses as well IPv6 addresses if 73 AI_V4MAPPED is set. This flag is ignored unless _a_f is 74 AF_INET6. 75 76 AI_ADDRCONFIG Only return addresses of a given type if the system has an 77 active interface with that type. 78 79 Also AI_DEFAULT is defined to be (AI_V4MAPPED|AI_ADDRCONFIG). 80 81 GGeettiippnnooddeebbyyaaddddrr() will lookup IPv4 mapped and compatible addresses in the 82 IPv4 name space and IPv6 name space 83 84 FFrreeeehhoosstteenntt() frees the hostent structure allocated be ggeettiippnnooddeebbyynnaammee() 85 and ggeettiippnnooddeebbyyaaddddrr(). The structures returned by ggeetthhoossttbbyynnaammee(), 86 ggeetthhoossttbbyynnaammee22(), ggeetthhoossttbbyyaaddddrr() and ggeetthhoosstteenntt() should not be passed 87 to ffrreeeehhoosstteenntt() as they are pointers to static areas. 88 89EENNVVIIRROONNMMEENNTT 90 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. 91 92FFIILLEESS 93 /etc/hosts See hosts(5). 94 95DDIIAAGGNNOOSSTTIICCSS 96 Error return status from ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() is indi- 97 cated by return of a null pointer. In this case _e_r_r_o_r may then be 98 checked to see whether this is a temporary failure or an invalid or 99 unknown host. _e_r_r_n_o can have the following values: 100 101 NETDB_INTERNAL This indicates an internal error in the library, 102 unrelated to the network or name service. _e_r_r_n_o 103 will be valid in this case; see perror. 104 105 HOST_NOT_FOUND No such host is known. 106 107 TRY_AGAIN This is usually a temporary error and means that 108 the local server did not receive a response from 109 an authoritative server. A retry at some later 110 time may succeed. 111 112 NO_RECOVERY Some unexpected server failure was encountered. 113 This is a non-recoverable error, as one might 114 expect. 115 116 NO_ADDRESS The requested name is valid but does not have an 117 IP address; this is not a temporary error. This 118 means that the name is known to the name server 119 but there is no address associated with this 120 name. Another type of request to the name server 121 using this domain name will result in an answer; 122 for example, a mail-forwarder may be registered 123 for this domain. 124 125SSEEEE AALLSSOO 126 hosts(5), hostname(7), resolver(3), resolver(5), gethostbyname(3), 127 RFC2553. 128 1294th Berkeley Distribution September 17, 1999 4th Berkeley Distribution 130