1GETHOSTBYNAME(3) 386BSD Programmer's Manual GETHOSTBYNAME(3) 2 3NNAAMMEE 4 ggeetthhoossttbbyynnaammee, ggeetthhoossttbbyyaaddddrr, ggeetthhoosstteenntt, sseetthhoosstteenntt, eennddhhoosstteenntt, hheerrrroorr 5 - get network host entry 6 7SSYYNNOOPPSSIISS 8 ##iinncclluuddee <<nneettddbb..hh>> 9 eexxtteerrnn ssttrruucctt hh__eerrrrnnoo;; 10 11 _s_t_r_u_c_t _h_o_s_t_e_n_t * 12 ggeetthhoossttbbyynnaammee(_c_h_a_r *_n_a_m_e) 13 14 _s_t_r_u_c_t _h_o_s_t_e_n_t * 15 ggeetthhoossttbbyyaaddddrr(_c_h_a_r *_a_d_d_r, _i_n_t _l_e_n, _i_n_t _t_y_p_e) 16 17 _s_t_r_u_c_t _h_o_s_t_e_n_t * 18 ggeetthhoosstteenntt(_v_o_i_d) 19 20 sseetthhoosstteenntt(_i_n_t _s_t_a_y_o_p_e_n) 21 22 eennddhhoosstteenntt(_v_o_i_d) 23 24 hheerrrroorr(_c_h_a_r *_s_t_r_i_n_g) 25 26DDEESSCCRRIIPPTTIIOONN 27 The ggeetthhoossttbbyynnaammee() and ggeetthhoossttbbyyaaddddrr() functions each return a pointer 28 to an object with the following structure describing an internet host 29 referenced by name or by address, respectively. This structure contains 30 either the information obtained from the name server, named(8), or 31 broken-out fields from a line in /_e_t_c/_h_o_s_t_s. If the local name server is 32 not running these routines do a lookup in /_e_t_c/_h_o_s_t_s. 33 34 struct hostent { 35 char *h_name; /* official name of host */ 36 char **h_aliases; /* alias list */ 37 int h_addrtype; /* host address type */ 38 int h_length; /* length of address */ 39 char **h_addr_list; /* list of addresses from name server */ 40 }; 41 #define h_addr h_addr_list[0] /* address, for backward compatibility */ 42 43 The members of this structure are: 44 45 _h__n_a_m_e Official name of the host. 46 47 _h__a_l_i_a_s_e_s A zero terminated array of alternate names for the host. 48 49 _h__a_d_d_r_t_y_p_e The type of address being returned; currently always 50 AF_INET. 51 52 _h__l_e_n_g_t_h The length, in bytes, of the address. 53 54 _h__a_d_d_r__l_i_s_t A zero terminated array of network addresses for the host. 55 Host addresses are returned in network byte order. 56 57 _h__a_d_d_r The first address in _h__a_d_d_r__l_i_s_t; this is for backward 58 compatiblity. 59 60 When using the nameserver, ggeetthhoossttbbyynnaammee() will search for 61 the named host in the current domain and its parents unless 62 the name ends in a dot. If the name contains no dot, and if 63 the environment variable ``HOSTALIASES'' contains the name 64 of an alias file, the alias file will first be searched for 65 an alias matching the input name. See hostname(7) for the 66 domain search procedure and the alias file format. 67 68 The sseetthhoosstteenntt() function may be used to request the use of 69 a connected TCP socket for queries. If the _s_t_a_y_o_p_e_n flag is 70 non-zero, this sets the option to send all queries to the 71 name server using TCP and to retain the connection after 72 each call to ggeetthhoossttbbyynnaammee() or ggeetthhoossttbbyyaaddddrr(). Otherwise, 73 queries are performed using UDP datagrams. 74 75 The eennddhhoosstteenntt() function closes the TCP connection. 76 77FFIILLEESS 78 /etc/hosts 79 80DDIIAAGGNNOOSSTTIICCSS 81 Error return status from ggeetthhoossttbbyynnaammee() and ggeetthhoossttbbyyaaddddrr() is indicated 82 by return of a null pointer. The external integer _h__e_r_r_n_o may then be 83 checked to see whether this is a temporary failure or an invalid or 84 unknown host. The routine hheerrrroorr() can be used to print an error message 85 describing the failure. If its argument _s_t_r_i_n_g is non-NULL, it is 86 printed, followed by a colon and a space. The error message is printed 87 with a trailing newline. 88 89 The variable _h__e_r_r_n_o can have the following values: 90 91 HOST_NOT_FOUND No such host is known. 92 93 TRY_AGAIN This is usually a temporary error and means that the 94 local server did not receive a response from an 95 authoritative server. A retry at some later time may 96 succeed. 97 98 NO_RECOVERY Some unexpected server failure was encountered. This is 99 a non-recoverable error. 100 101 NO_DATA The requested name is valid but does not have an IP 102 address; this is not a temporary error. This means that 103 the name is known to the name server but there is no 104 address associated with this name. Another type of 105 request to the name server using this domain name will 106 result in an answer; for example, a mail-forwarder may be 107 registered for this domain. 108 109SSEEEE AALLSSOO 110 resolver(3), hosts(5), hostname(7), named(8) 111 112CCAAVVEEAATT 113 The ggeetthhoosstteenntt() function is defined, and sseetthhoosstteenntt() and eennddhhoosstteenntt() 114 are redefined, when libc(3) is built to use only the routines to lookup 115 in /_e_t_c/_h_o_s_t_s and not the name server. 116 117 The ggeetthhoosstteenntt() function reads the next line of /_e_t_c/_h_o_s_t_s, opening the 118 file if necessary. 119 120 The sseetthhoosstteenntt() function is redefined to open and rewind the file. If 121 the _s_t_a_y_o_p_e_n argument is non-zero, the hosts data base will not be closed 122 after each call to ggeetthhoossttbbyynnaammee() or ggeetthhoossttbbyyaaddddrr(). The eennddhhoosstteenntt() 123 function is redefined to close the file. 124 125HHIISSTTOORRYY 126 The hheerrrroorr() function appeared in 4.3BSD. The eennddhhoosstteenntt(), 127 ggeetthhoossttbbyyaaddddrr(), ggeetthhoossttbbyynnaammee(), ggeetthhoosstteenntt(), and sseetthhoosstteenntt() 128 functions appeared in 4.2BSD. 129 130BBUUGGSS 131 These functions use static data storage; if the data is needed for future 132 use, it should be copied before any subsequent calls overwrite it. Only 133 the Internet address format is currently understood. 134 1354.2 Berkeley Distribution July 31, 1991 3 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199