1 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
2 .\" Copyright (c) 1996,1999 by Internet Software Consortium
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
11 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 .\" Copyright (c) 1983, 1987 The Regents of the University of California.
17 .\" All rights reserved.
19 .\" Redistribution and use in source and binary forms are permitted provided
20 .\" that: (1) source distributions retain this entire copyright notice and
21 .\" comment, and (2) distributions including binaries display the following
22 .\" acknowledgement: ``This product includes software developed by the
23 .\" University of California, Berkeley and its contributors'' in the
24 .\" documentation or other materials provided with the distribution and in
25 .\" all advertising materials mentioning features or use of this software.
26 .\" Neither the name of the University nor the names of its contributors may
27 .\" be used to endorse or promote products derived from this software without
28 .\" specific prior written permission.
29 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
30 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
31 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 .Dd September 17, 1999
39 .Nd get network host entry
42 .Nd free network host entry
44 .Fd #include <netdb.h>
47 .Fn getipnodebyname "const char *name" "int af" "int flags" "int *error"
49 .Fn getipnodebyaddr "const void *addr" "size_t len" "int af" "int *error"
51 .Fn freehostent "struct hostent *he"
56 each return a pointer to a
58 structure (see below) describing an internet host
59 referenced by name or by address, as the function names indicate.
60 This structure contains either the information obtained from the name server,
61 or broken-out fields from a line in
63 If the local name server is not running, these routines do a lookup in
65 .Bd -literal -offset indent
67 char *h_name; /* official name of host */
68 char **h_aliases; /* alias list */
69 int h_addrtype; /* host address type */
70 int h_length; /* length of address */
71 char **h_addr_list; /* list of addresses from name server */
74 #define h_addr h_addr_list[0] /* address, for backward compatibility */
77 The members of this structure are:
78 .Bl -tag -width "h_addr_list"
80 Official name of the host.
82 A zero-terminated array of alternate names for the host.
84 The type of address being returned.
86 The length, in bytes, of the address.
88 A zero-terminated array of network addresses for the host.
89 Host addresses are returned in network byte order.
93 this is for backward compatibility.
96 This structure should be freed after use by calling
99 When using the nameserver,
101 will search for the named host in each parent domain given in the
105 unless the name contains a dot
107 If the name contains no dot, and if the environment variable
109 contains the name of an alias file, the alias file will first be searched
110 for an alias matching the input name.
113 for the domain search procedure and the alias file format.
116 can be told to look for IPv4 addresses, IPv6 addresses or both IPv4 and IPv6.
117 If IPv4 addresses only are to be looked up then
121 otherwise it should be set to
124 There are three flags that can be set
125 .Bl -tag -width "AI_ADDRCONFIG"
127 Return IPv4 addresses if no IPv6 addresses are found.
128 This flag is ignored unless
133 Return IPv4 addresses as well IPv6 addresses if
136 This flag is ignored unless
141 Only return addresses of a given type if the system has an active interface
148 .Dv (AI_V4MAPPED|AI_ADDRCONFIG) .
151 will lookup IPv4 mapped and compatible addresses in the IPv4 name
152 space and IPv6 name space
155 frees the hostent structure allocated be
158 .Fn getipnodebyaddr .
159 The structures returned by
165 should not be passed to
167 as they are pointers to static areas.
169 .Bl -tag -width "HOSTALIASES " -compact
171 Name of file containing
172 .Pq Ar host alias , full hostname
176 .Bl -tag -width "HOSTALIASES " -compact
183 Error return status from
187 is indicated by return of a null pointer.
190 may then be checked to see whether this is a temporary failure
191 or an invalid or unknown host.
193 can have the following values:
194 .Bl -tag -width "HOST_NOT_FOUND " -offset indent
195 .It Dv NETDB_INTERNAL
196 This indicates an internal error in the library, unrelated to the network
199 will be valid in this case; see
201 .It Dv HOST_NOT_FOUND
202 No such host is known.
204 This is usually a temporary error
205 and means that the local server did not receive
206 a response from an authoritative server.
207 A retry at some later time may succeed.
209 Some unexpected server failure was encountered.
210 This is a non-recoverable error, as one might expect.
212 The requested name is valid but does not have an IP address;
213 this is not a temporary error.
214 This means that the name is known to the name server but there is no address
215 associated with this name.
216 Another type of request to the name server using this domain name
217 will result in an answer;
218 for example, a mail-forwarder may be registered for this domain.
225 .Xr gethostbyname 3 ,