diff options
Diffstat (limited to 'src/lib/libc/net/gethostbyname.3')
| -rw-r--r-- | src/lib/libc/net/gethostbyname.3 | 239 |
1 files changed, 141 insertions, 98 deletions
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 index bac0368296..1a05460da4 100644 --- a/src/lib/libc/net/gethostbyname.3 +++ b/src/lib/libc/net/gethostbyname.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $NetBSD: gethostbyname.3,v 1.6 1995/02/25 06:20:28 cgd Exp $ | 1 | .\" $OpenBSD: gethostbyname.3,v 1.25 2007/05/31 19:19:30 jmc Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
| 4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
| @@ -11,11 +11,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 21 | .\" | 17 | .\" |
| @@ -31,58 +27,66 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 33 | .\" | 29 | .\" |
| 34 | .\" @(#)gethostbyname.3 8.2 (Berkeley) 4/19/94 | 30 | .Dd $Mdocdate: May 31 2007 $ |
| 35 | .\" | ||
| 36 | .Dd April 19, 1994 | ||
| 37 | .Dt GETHOSTBYNAME 3 | 31 | .Dt GETHOSTBYNAME 3 |
| 38 | .Os BSD 4.2 | 32 | .Os |
| 39 | .Sh NAME | 33 | .Sh NAME |
| 40 | .Nm gethostbyname , | 34 | .Nm gethostbyname , |
| 35 | .Nm gethostbyname2 , | ||
| 41 | .Nm gethostbyaddr , | 36 | .Nm gethostbyaddr , |
| 42 | .Nm gethostent , | 37 | .Nm gethostent , |
| 43 | .Nm sethostent , | 38 | .Nm sethostent , |
| 44 | .Nm endhostent , | 39 | .Nm endhostent , |
| 40 | .Nm hstrerror , | ||
| 45 | .Nm herror | 41 | .Nm herror |
| 46 | .Nd get network host entry | 42 | .Nd get network host entry |
| 47 | .Sh SYNOPSIS | 43 | .Sh SYNOPSIS |
| 48 | .Fd #include <netdb.h> | 44 | .Fd #include <netdb.h> |
| 49 | .Fd extern int h_errno; | 45 | .Vt extern int h_errno ; |
| 50 | .Ft struct hostent * | 46 | .Ft struct hostent * |
| 51 | .Fn gethostbyname "const char *name" | 47 | .Fn gethostbyname "const char *name" |
| 52 | .Ft struct hostent * | 48 | .Ft struct hostent * |
| 53 | .Fn gethostbyaddr "const char *addr" "int len" "int type" | 49 | .Fn gethostbyname2 "const char *name" "int af" |
| 50 | .Ft struct hostent * | ||
| 51 | .Fn gethostbyaddr "const void *addr" "socklen_t len" "int af" | ||
| 54 | .Ft struct hostent * | 52 | .Ft struct hostent * |
| 55 | .Fn gethostent void | 53 | .Fn gethostent void |
| 54 | .Ft void | ||
| 56 | .Fn sethostent "int stayopen" | 55 | .Fn sethostent "int stayopen" |
| 56 | .Ft void | ||
| 57 | .Fn endhostent void | 57 | .Fn endhostent void |
| 58 | .Fn herror "char *string" | 58 | .Ft void |
| 59 | .Fn herror "const char *string" | ||
| 60 | .Ft const char * | ||
| 61 | .Fn hstrerror "int err" | ||
| 59 | .Sh DESCRIPTION | 62 | .Sh DESCRIPTION |
| 60 | The | 63 | The |
| 61 | .Fn gethostbyname | 64 | .Fn gethostbyname , |
| 65 | .Fn gethostbyname2 , | ||
| 62 | and | 66 | and |
| 63 | .Fn gethostbyaddr | 67 | .Fn gethostbyaddr |
| 64 | functions | 68 | functions each return a pointer to an object with the following structure |
| 65 | each return a pointer to an object with the | 69 | describing an Internet host referenced by name or by address, respectively. |
| 66 | following structure describing an internet host | 70 | This structure contains either information obtained from the name server (i.e., |
| 67 | referenced by name or by address, respectively. | 71 | .Xr resolver 3 |
| 68 | This structure contains either the information obtained from the name server, | 72 | and |
| 69 | .Xr named 8 , | 73 | .Xr named 8 ) , |
| 70 | broken-out fields from a line in | 74 | broken-out fields from a line in |
| 71 | .Pa /etc/hosts , | 75 | .Pa /etc/hosts , |
| 72 | or database entries supplied by the | 76 | or database entries supplied by the |
| 73 | .Xr yp 8 | 77 | .Xr yp 8 |
| 74 | system . | 78 | system. |
| 75 | If the local name server is not running these routines do a lookup in | 79 | .Xr resolv.conf 5 |
| 76 | .Pa /etc/hosts . | 80 | describes how the particular database is chosen. |
| 77 | .Bd -literal | 81 | .Bd -literal -offset indent |
| 78 | struct hostent { | 82 | struct hostent { |
| 79 | char *h_name; /* official name of host */ | 83 | char *h_name; /* official name of host */ |
| 80 | char **h_aliases; /* alias list */ | 84 | char **h_aliases; /* alias list */ |
| 81 | int h_addrtype; /* host address type */ | 85 | int h_addrtype; /* host address type */ |
| 82 | int h_length; /* length of address */ | 86 | int h_length; /* length of address */ |
| 83 | char **h_addr_list; /* list of addresses from name server */ | 87 | char **h_addr_list; /* list of returned addresses */ |
| 84 | }; | 88 | }; |
| 85 | #define h_addr h_addr_list[0] /* address, for backward compatibility */ | 89 | #define h_addr h_addr_list[0] /* address, for backward compat */ |
| 86 | .Ed | 90 | .Ed |
| 87 | .Pp | 91 | .Pp |
| 88 | The members of this structure are: | 92 | The members of this structure are: |
| @@ -90,36 +94,50 @@ The members of this structure are: | |||
| 90 | .It Fa h_name | 94 | .It Fa h_name |
| 91 | Official name of the host. | 95 | Official name of the host. |
| 92 | .It Fa h_aliases | 96 | .It Fa h_aliases |
| 93 | A zero terminated array of alternate names for the host. | 97 | A null-terminated array of alternate names for the host. |
| 94 | .It Fa h_addrtype | 98 | .It Fa h_addrtype |
| 95 | The type of address being returned; currently always | 99 | The type of address being returned. |
| 96 | .Dv AF_INET . | ||
| 97 | .It Fa h_length | 100 | .It Fa h_length |
| 98 | The length, in bytes, of the address. | 101 | The length, in bytes, of the address. |
| 99 | .It Fa h_addr_list | 102 | .It Fa h_addr_list |
| 100 | A zero terminated array of network addresses for the host. | 103 | A null-terminated array of network addresses for the host. |
| 101 | Host addresses are returned in network byte order. | 104 | Host addresses are returned in network byte order. |
| 102 | .It Fa h_addr | 105 | .It Fa h_addr |
| 103 | The first address in | 106 | The first address in |
| 104 | .Fa h_addr_list ; | 107 | .Fa h_addr_list ; |
| 105 | this is for backward compatibility. | 108 | this is for backward compatibility. |
| 109 | .El | ||
| 106 | .Pp | 110 | .Pp |
| 107 | When using the nameserver, | 111 | The function |
| 108 | .Fn gethostbyname | 112 | .Fn gethostbyname |
| 109 | will search for the named host in the current domain and its parents | 113 | will search for the named host in the current domain and its parents |
| 110 | unless the name ends in a dot. | 114 | using the search lookup semantics detailed in |
| 111 | If the name contains no dot, and if the environment variable | 115 | .Xr resolv.conf 5 |
| 112 | .Dq Ev HOSTALIASES | 116 | and |
| 113 | contains the name of an alias file, the alias file will first be searched | 117 | .Xr hostname 7 . |
| 114 | for an alias matching the input name. | 118 | .Pp |
| 115 | See | 119 | .Fn gethostbyname2 |
| 116 | .Xr hostname 7 | 120 | is an advanced form of |
| 117 | for the domain search procedure and the alias file format. | 121 | .Fn gethostbyname |
| 122 | which allows lookups in address families other than | ||
| 123 | .Dv AF_INET . | ||
| 124 | Currently, the only supported address family besides | ||
| 125 | .Dv AF_INET | ||
| 126 | is | ||
| 127 | .Dv AF_INET6 . | ||
| 128 | .Pp | ||
| 129 | The | ||
| 130 | .Fn gethostbyaddr | ||
| 131 | function will search for the specified address of length | ||
| 132 | .Fa len | ||
| 133 | in the address family | ||
| 134 | .Fa af . | ||
| 135 | The only address family currently supported is | ||
| 136 | .Dv AF_INET . | ||
| 118 | .Pp | 137 | .Pp |
| 119 | The | 138 | The |
| 120 | .Fn sethostent | 139 | .Fn sethostent |
| 121 | function | 140 | function may be used to request the use of a connected |
| 122 | may be used to request the use of a connected | ||
| 123 | .Tn TCP | 141 | .Tn TCP |
| 124 | socket for queries. | 142 | socket for queries. |
| 125 | If the | 143 | If the |
| @@ -127,7 +145,7 @@ If the | |||
| 127 | flag is non-zero, | 145 | flag is non-zero, |
| 128 | this sets the option to send all queries to the name server using | 146 | this sets the option to send all queries to the name server using |
| 129 | .Tn TCP | 147 | .Tn TCP |
| 130 | and to retain the connection after each call to | 148 | and to retain the connection after each call to |
| 131 | .Fn gethostbyname | 149 | .Fn gethostbyname |
| 132 | or | 150 | or |
| 133 | .Fn gethostbyaddr . | 151 | .Fn gethostbyaddr . |
| @@ -137,17 +155,46 @@ datagrams. | |||
| 137 | .Pp | 155 | .Pp |
| 138 | The | 156 | The |
| 139 | .Fn endhostent | 157 | .Fn endhostent |
| 140 | function | 158 | function closes the |
| 141 | closes the | ||
| 142 | .Tn TCP | 159 | .Tn TCP |
| 143 | connection. | 160 | connection. |
| 161 | .Pp | ||
| 162 | The | ||
| 163 | .Fn herror | ||
| 164 | function prints an error message describing the failure. | ||
| 165 | If its argument | ||
| 166 | .Fa string | ||
| 167 | is non-null, | ||
| 168 | it is prepended to the message string and separated from it by a colon | ||
| 169 | .Pq Ql \&: | ||
| 170 | and a space. | ||
| 171 | The error message is printed with a trailing newline. | ||
| 172 | The contents of the error message is the same as that returned by | ||
| 173 | .Fn hstrerror | ||
| 174 | with argument | ||
| 175 | .Fa h_errno . | ||
| 176 | .Sh ENVIRONMENT | ||
| 177 | .Bl -tag -width HOSTALIASES | ||
| 178 | .It HOSTALIASES | ||
| 179 | A file containing local host aliases. | ||
| 180 | See | ||
| 181 | .Xr hostname 7 | ||
| 182 | for more information. | ||
| 183 | .It RES_OPTIONS | ||
| 184 | A list of options to override the resolver's internal defaults. | ||
| 185 | See | ||
| 186 | .Xr resolver 3 | ||
| 187 | for more information. | ||
| 188 | .El | ||
| 144 | .Sh FILES | 189 | .Sh FILES |
| 145 | .Bl -tag -width /etc/hosts -compact | 190 | .Bl -tag -width /etc/resolv.conf -compact |
| 146 | .It Pa /etc/hosts | 191 | .It Pa /etc/hosts |
| 192 | .It Pa /etc/resolv.conf | ||
| 147 | .El | 193 | .El |
| 148 | .Sh DIAGNOSTICS | 194 | .Sh DIAGNOSTICS |
| 149 | Error return status from | 195 | Error return status from |
| 150 | .Fn gethostbyname | 196 | .Fn gethostbyname , |
| 197 | .Fn gethostbyname2 , | ||
| 151 | and | 198 | and |
| 152 | .Fn gethostbyaddr | 199 | .Fn gethostbyaddr |
| 153 | is indicated by return of a null pointer. | 200 | is indicated by return of a null pointer. |
| @@ -155,15 +202,6 @@ The external integer | |||
| 155 | .Va h_errno | 202 | .Va h_errno |
| 156 | may then be checked to see whether this is a temporary failure | 203 | may then be checked to see whether this is a temporary failure |
| 157 | or an invalid or unknown host. | 204 | or an invalid or unknown host. |
| 158 | The routine | ||
| 159 | .Fn herror | ||
| 160 | can be used to print an error message describing the failure. | ||
| 161 | If its argument | ||
| 162 | .Fa string | ||
| 163 | is | ||
| 164 | .Pf non Dv -NULL , | ||
| 165 | it is printed, followed by a colon and a space. | ||
| 166 | The error message is printed with a trailing newline. | ||
| 167 | .Pp | 205 | .Pp |
| 168 | The variable | 206 | The variable |
| 169 | .Va h_errno | 207 | .Va h_errno |
| @@ -180,75 +218,80 @@ A retry at some later time may succeed. | |||
| 180 | Some unexpected server failure was encountered. | 218 | Some unexpected server failure was encountered. |
| 181 | This is a non-recoverable error. | 219 | This is a non-recoverable error. |
| 182 | .It Dv NO_DATA | 220 | .It Dv NO_DATA |
| 183 | The requested name is valid but does not have an IP address; | 221 | The requested name is valid but does not have an IP address; |
| 184 | this is not a temporary error. | 222 | this is not a temporary error. |
| 185 | This means that the name is known to the name server but there is no address | 223 | This means that the name is known to the name server but there is no address |
| 186 | associated with this name. | 224 | associated with this name. |
| 187 | Another type of request to the name server using this domain name | 225 | Another type of request to the name server using this domain name |
| 188 | will result in an answer; | 226 | will result in an answer; |
| 189 | for example, a mail-forwarder may be registered for this domain. | 227 | for example, a mail-forwarder may be registered for this domain. |
| 228 | .It Dv NETDB_INTERNAL | ||
| 229 | An internal error occurred. | ||
| 230 | This may occur when an address family other than | ||
| 231 | .Dv AF_INET | ||
| 232 | or | ||
| 233 | .Dv AF_INET6 | ||
| 234 | is specified or when a resource is unable to be allocated. | ||
| 235 | .It Dv NETDB_SUCCESS | ||
| 236 | The function completed successfully. | ||
| 190 | .El | 237 | .El |
| 191 | .Sh SEE ALSO | 238 | .Sh SEE ALSO |
| 239 | .Xr getaddrinfo 3 , | ||
| 240 | .Xr getnameinfo 3 , | ||
| 192 | .Xr resolver 3 , | 241 | .Xr resolver 3 , |
| 193 | .Xr hosts 5 , | 242 | .Xr hosts 5 , |
| 243 | .Xr resolv.conf 5 , | ||
| 194 | .Xr hostname 7 , | 244 | .Xr hostname 7 , |
| 195 | .Xr named 8 | 245 | .Xr named 8 |
| 196 | .Sh CAVEAT | 246 | .Sh HISTORY |
| 197 | The | 247 | The |
| 198 | .Fn gethostent | 248 | .Fn herror |
| 199 | function | 249 | function appeared in |
| 200 | is defined, and | 250 | .Bx 4.3 . |
| 201 | .Fn sethostent | 251 | The |
| 252 | .Fn endhostent , | ||
| 253 | .Fn gethostbyaddr , | ||
| 254 | .Fn gethostbyname , | ||
| 255 | .Fn gethostent , | ||
| 202 | and | 256 | and |
| 203 | .Fn endhostent | 257 | .Fn sethostent |
| 204 | are redefined, | 258 | functions appeared in |
| 205 | when | 259 | .Bx 4.2 . |
| 206 | .Xr libc 3 | 260 | .Sh CAVEATS |
| 207 | is built to use only the routines to lookup in | 261 | If the search routines in |
| 262 | .Xr resolv.conf 5 | ||
| 263 | decide to read the | ||
| 208 | .Pa /etc/hosts | 264 | .Pa /etc/hosts |
| 209 | and not the name server. | 265 | file, |
| 210 | .Pp | ||
| 211 | The | ||
| 212 | .Fn gethostent | 266 | .Fn gethostent |
| 213 | function | 267 | and other functions will |
| 214 | reads the next line of | 268 | read the next line of the file, |
| 215 | .Pa /etc/hosts , | 269 | re-opening the file if necessary. |
| 216 | opening the file if necessary. | ||
| 217 | .Pp | 270 | .Pp |
| 218 | The | 271 | The |
| 219 | .Fn sethostent | 272 | .Fn sethostent |
| 220 | function | 273 | function opens and/or rewinds the file |
| 221 | opens and/or rewinds the file | ||
| 222 | .Pa /etc/hosts . | 274 | .Pa /etc/hosts . |
| 223 | If the | 275 | If the |
| 224 | .Fa stayopen | 276 | .Fa stayopen |
| 225 | argument is non-zero, | 277 | argument is non-zero, the file will not be closed after each call to |
| 226 | the file will not be closed after each call to | 278 | .Fn gethostbyname , |
| 227 | .Fn gethostbyname | 279 | .Fn gethostbyname2 , |
| 228 | or | 280 | or |
| 229 | .Fn gethostbyaddr . | 281 | .Fn gethostbyaddr . |
| 230 | .Pp | 282 | .Pp |
| 231 | The | 283 | The |
| 232 | .Fn endhostent | 284 | .Fn endhostent |
| 233 | function | 285 | function closes the file. |
| 234 | closes the file. | ||
| 235 | .Sh HISTORY | ||
| 236 | The | ||
| 237 | .Fn herror | ||
| 238 | function appeared in | ||
| 239 | .Bx 4.3 . | ||
| 240 | The | ||
| 241 | .Fn endhostent , | ||
| 242 | .Fn gethostbyaddr , | ||
| 243 | .Fn gethostbyname , | ||
| 244 | .Fn gethostent , | ||
| 245 | and | ||
| 246 | .Fn sethostent | ||
| 247 | functions appeared in | ||
| 248 | .Bx 4.2 . | ||
| 249 | .Sh BUGS | 286 | .Sh BUGS |
| 250 | These functions use static data storage; | 287 | These functions use static data storage; |
| 251 | if the data is needed for future use, it should be | 288 | if the data is needed for future use, it should be |
| 252 | copied before any subsequent calls overwrite it. | 289 | copied before any subsequent calls overwrite it. |
| 290 | .Pp | ||
| 253 | Only the Internet | 291 | Only the Internet |
| 254 | address format is currently understood. | 292 | address formats are currently understood. |
| 293 | .Pp | ||
| 294 | YP does not support any address families other than | ||
| 295 | .Dv AF_INET | ||
| 296 | and uses | ||
| 297 | the traditional database format. | ||
