1 .\" $NetBSD: lwres_gethostent.3,v 1.5 2014/12/10 04:38:02 christos Exp $
3 .\" Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
4 .\" Copyright (C) 2001 Internet Software Consortium.
6 .\" Permission to use, copy, modify, and/or distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 .\" PERFORMANCE OF THIS SOFTWARE.
22 .\" Title: lwres_gethostent
24 .\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
25 .\" Date: June 18, 2007
29 .TH "LWRES_GETHOSTENT" "3" "June 18, 2007" "BIND9" "BIND9"
30 .\" disable hyphenation
32 .\" disable justification (adjust text to left margin only)
35 lwres_gethostbyname, lwres_gethostbyname2, lwres_gethostbyaddr, lwres_gethostent, lwres_sethostent, lwres_endhostent, lwres_gethostbyname_r, lwres_gethostbyaddr_r, lwres_gethostent_r, lwres_sethostent_r, lwres_endhostent_r \- lightweight resolver get network host entry
38 #include <lwres/netdb.h>
41 .BI "struct hostent * lwres_gethostbyname(const\ char\ *" "name" ");"
43 .BI "struct hostent * lwres_gethostbyname2(const\ char\ *" "name" ", int\ " "af" ");"
45 .BI "struct hostent * lwres_gethostbyaddr(const\ char\ *" "addr" ", int\ " "len" ", int\ " "type" ");"
47 .BI "struct hostent * lwres_gethostent(void);"
49 .BI "void lwres_sethostent(int\ " "stayopen" ");"
51 .BI "void lwres_endhostent(void);"
53 .BI "struct hostent * lwres_gethostbyname_r(const\ char\ *" "name" ", struct\ hostent\ *" "resbuf" ", char\ *" "buf" ", int\ " "buflen" ", int\ *" "error" ");"
55 .BI "struct hostent * lwres_gethostbyaddr_r(const\ char\ *" "addr" ", int\ " "len" ", int\ " "type" ", struct\ hostent\ *" "resbuf" ", char\ *" "buf" ", int\ " "buflen" ", int\ *" "error" ");"
57 .BI "struct hostent * lwres_gethostent_r(struct\ hostent\ *" "resbuf" ", char\ *" "buf" ", int\ " "buflen" ", int\ *" "error" ");"
59 .BI "void lwres_sethostent_r(int\ " "stayopen" ");"
61 .BI "void lwres_endhostent_r(void);"
64 These functions provide hostname\-to\-address and address\-to\-hostname lookups by means of the lightweight resolver. They are similar to the standard
66 functions provided by most operating systems. They use a
68 which is usually defined in
74 char *h_name; /* official name of host */
75 char **h_aliases; /* alias list */
76 int h_addrtype; /* host address type */
77 int h_length; /* length of address */
78 char **h_addr_list; /* list of addresses from name server */
80 #define h_addr h_addr_list[0] /* address, for backward compatibility */
85 The members of this structure are:
89 The official (canonical) name of the host.
94 A NULL\-terminated array of alternate names (nicknames) for the host.
99 The type of address being returned \(em
107 The length of the address in bytes.
114 terminated array of network addresses for the host. Host addresses are returned in network byte order.
117 For backward compatibility with very old software,
119 is the first address in
122 \fBlwres_gethostent()\fR,
123 \fBlwres_sethostent()\fR,
124 \fBlwres_endhostent()\fR,
125 \fBlwres_gethostent_r()\fR,
126 \fBlwres_sethostent_r()\fR
128 \fBlwres_endhostent_r()\fR
129 provide iteration over the known host entries on systems that provide such functionality through facilities like
131 or NIS. The lightweight resolver does not currently implement these functions; it only provides them as stub functions that always return failure.
133 \fBlwres_gethostbyname()\fR
135 \fBlwres_gethostbyname2()\fR
138 \fBlwres_gethostbyname()\fR
139 always looks for an IPv4 address while
140 \fBlwres_gethostbyname2()\fR
141 looks for an address of protocol family
146 \(em IPv4 or IPV6 addresses respectively. Successful calls of the functions return a
147 \fBstruct hostent\fRfor the name that was looked up.
149 is returned if the lookups by
150 \fBlwres_gethostbyname()\fR
152 \fBlwres_gethostbyname2()\fR
155 Reverse lookups of addresses are performed by
156 \fBlwres_gethostbyaddr()\fR.
158 is an address of length
160 bytes and protocol family
166 \fBlwres_gethostbyname_r()\fR
167 is a thread\-safe function for forward lookups. If an error occurs, an error code is returned in
172 which is initialised by a successful call to
173 \fBlwres_gethostbyname_r()\fR.
175 is a buffer of length
177 bytes which is used to store the
184 \fIresbuf\fR. Successful calls to
185 \fBlwres_gethostbyname_r()\fR
187 \fIresbuf\fR, which is a pointer to the
191 \fBlwres_gethostbyaddr_r()\fR
192 is a thread\-safe function that performs a reverse lookup of address
196 bytes long and is of protocol family
201 \fBPF_INET6\fR. If an error occurs, the error code is returned in
202 \fI*error\fR. The other function parameters are identical to those in
203 \fBlwres_gethostbyname_r()\fR.
207 which is initialised by a successful call to
208 \fBlwres_gethostbyaddr_r()\fR.
210 is a buffer of length
212 bytes which is used to store the
219 \fIresbuf\fR. Successful calls to
220 \fBlwres_gethostbyaddr_r()\fR
222 \fIresbuf\fR, which is a pointer to the
223 \fBstruct hostent()\fR
228 \fBlwres_gethostbyname()\fR,
229 \fBlwres_gethostbyname2()\fR,
230 \fBlwres_gethostbyaddr()\fR, and
231 \fBlwres_gethostent()\fR
232 return NULL to indicate an error. In this case the global variable
234 will contain one of the following error codes defined in
235 \fI<lwres/netdb.h>\fR:
239 The host or address was not found.
244 A recoverable error occurred, e.g., a timeout. Retrying the lookup may succeed.
249 A non\-recoverable error occurred.
254 The name exists, but has no address information associated with it (or vice versa in the case of a reverse lookup). The code NO_ADDRESS is accepted as a synonym for NO_DATA for backwards compatibility.
257 \fBlwres_hstrerror\fR(3)
258 translates these error codes to suitable error messages.
260 \fBlwres_gethostent()\fR
262 \fBlwres_gethostent_r()\fR
267 \fBlwres_gethostbyname_r()\fR
269 \fBlwres_gethostbyaddr_r()\fR
271 \fIresbuf\fR, a pointer to the
273 that was initialised by these functions. They return
275 if the lookups fail or if
277 was too small to hold the list of addresses and names referenced by the
282 \fBstruct hostent\fR. If
285 \fBlwres_gethostbyname_r()\fR
287 \fBlwres_gethostbyaddr_r()\fR
288 set the global variable
295 \fBlwres_getipnode\fR(3),
296 \fBlwres_hstrerror\fR(3)
299 \fBlwres_gethostbyname()\fR,
300 \fBlwres_gethostbyname2()\fR,
301 \fBlwres_gethostbyaddr()\fR
303 \fBlwres_endhostent()\fR
304 are not thread safe; they return pointers to static data and provide error codes through a global variable. Thread\-safe versions for name and address lookup are provided by
305 \fBlwres_gethostbyname_r()\fR, and
306 \fBlwres_gethostbyaddr_r()\fR
309 The resolver daemon does not currently support any non\-DNS name services such as
312 \fBNIS\fR, consequently the above functions don't, either.
314 Copyright \(co 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
316 Copyright \(co 2001 Internet Software Consortium.