1 .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
2 .\" Copyright (C) 2001 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 WITH
9 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 .\" PERFORMANCE OF THIS SOFTWARE.
16 .\" $Id: lwres_gethostent.3,v 1.16.2.2 2004/03/15 04:45:02 marka Exp $
18 .TH "LWRES_GETHOSTENT" "3" "Jun 30, 2000" "BIND9" ""
20 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
22 \fB#include <lwres/netdb.h>
26 lwres_gethostbyname(const char *name);
31 lwres_gethostbyname2(const char *name, int af);
36 lwres_gethostbyaddr(const char *addr, int len, int type);
41 lwres_gethostent(void);
46 lwres_sethostent(int stayopen);
51 lwres_endhostent(void);
56 lwres_gethostbyname_r(const char *name, struct hostent *resbuf, char *buf, int buflen, int *error);
61 lwres_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *resbuf, char *buf, int buflen, int *error);
66 lwres_gethostent_r(struct hostent *resbuf, char *buf, int buflen, int *error);
71 lwres_sethostent_r(int stayopen);
76 lwres_endhostent_r(void);
81 These functions provide hostname-to-address and
82 address-to-hostname lookups by means of the lightweight resolver.
83 They are similar to the standard
85 functions provided by most operating systems.
88 which is usually defined in
93 char *h_name; /* official name of host */
94 char **h_aliases; /* alias list */
95 int h_addrtype; /* host address type */
96 int h_length; /* length of address */
97 char **h_addr_list; /* list of addresses from name server */
99 #define h_addr h_addr_list[0] /* address, for backward compatibility */
103 The members of this structure are:
106 The official (canonical) name of the host.
109 A NULL-terminated array of alternate names (nicknames) for the host.
112 The type of address being returned \(em
118 The length of the address in bytes.
122 terminated array of network addresses for the host.
123 Host addresses are returned in network byte order.
125 For backward compatibility with very old software,
127 is the first address in
130 \fBlwres_gethostent()\fR,
131 \fBlwres_sethostent()\fR,
132 \fBlwres_endhostent()\fR,
133 \fBlwres_gethostent_r()\fR,
134 \fBlwres_sethostent_r()\fR
136 \fBlwres_endhostent_r()\fR
137 provide iteration over the known host entries on systems that
138 provide such functionality through facilities like
140 or NIS. The lightweight resolver does not currently implement
141 these functions; it only provides them as stub functions that always
144 \fBlwres_gethostbyname()\fR and
145 \fBlwres_gethostbyname2()\fR look up the hostname
147 \fBlwres_gethostbyname()\fR always looks for an IPv4
148 address while \fBlwres_gethostbyname2()\fR looks for an
149 address of protocol family \fIaf\fR: either
150 \fBPF_INET\fR or \fBPF_INET6\fR \(em IPv4 or IPV6
151 addresses respectively. Successful calls of the functions return a
152 \fBstruct hostent\fRfor the name that was looked up.
153 \fBNULL\fR is returned if the lookups by
154 \fBlwres_gethostbyname()\fR or
155 \fBlwres_gethostbyname2()\fR fail.
157 Reverse lookups of addresses are performed by
158 \fBlwres_gethostbyaddr()\fR.
159 \fIaddr\fR is an address of length
160 \fIlen\fR bytes and protocol family
161 \fItype\fR \(em \fBPF_INET\fR or
163 \fBlwres_gethostbyname_r()\fR is a thread-safe function
164 for forward lookups. If an error occurs, an error code is returned in
166 \fIresbuf\fR is a pointer to a \fBstruct
167 hostent\fR which is initialised by a successful call to
168 \fBlwres_gethostbyname_r()\fR .
169 \fIbuf\fR is a buffer of length
170 \fIlen\fR bytes which is used to store the
171 h_name, h_aliases, and
172 h_addr_list elements of the \fBstruct
173 hostent\fR returned in \fIresbuf\fR.
174 Successful calls to \fBlwres_gethostbyname_r()\fR
176 which is a pointer to the \fBstruct hostent\fR it created.
178 \fBlwres_gethostbyaddr_r()\fR is a thread-safe function
179 that performs a reverse lookup of address \fIaddr\fR
180 which is \fIlen\fR bytes long and is of protocol
181 family \fItype\fR \(em \fBPF_INET\fR or
182 \fBPF_INET6\fR. If an error occurs, the error code is returned
183 in \fI*error\fR. The other function parameters are
184 identical to those in \fBlwres_gethostbyname_r()\fR.
185 \fIresbuf\fR is a pointer to a \fBstruct
186 hostent\fR which is initialised by a successful call to
187 \fBlwres_gethostbyaddr_r()\fR.
188 \fIbuf\fR is a buffer of length
189 \fIlen\fR bytes which is used to store the
190 h_name, h_aliases, and
191 h_addr_list elements of the \fBstruct
192 hostent\fR returned in \fIresbuf\fR. Successful
193 calls to \fBlwres_gethostbyaddr_r()\fR return
194 \fIresbuf\fR, which is a pointer to the
195 \fBstruct hostent()\fR it created.
199 \fBlwres_gethostbyname()\fR,
200 \fBlwres_gethostbyname2()\fR,
201 \fBlwres_gethostbyaddr()\fR,
203 \fBlwres_gethostent()\fR
204 return NULL to indicate an error. In this case the global variable
206 will contain one of the following error codes defined in
207 \fI<lwres/netdb.h>\fR:
210 The host or address was not found.
213 A recoverable error occurred, e.g., a timeout.
214 Retrying the lookup may succeed.
217 A non-recoverable error occurred.
220 The name exists, but has no address information
221 associated with it (or vice versa in the case
222 of a reverse lookup). The code NO_ADDRESS
223 is accepted as a synonym for NO_DATA for backwards
226 \fBlwres_hstrerror\fR(3)
227 translates these error codes to suitable error messages.
229 \fBlwres_gethostent()\fR
231 \fBlwres_gethostent_r()\fR
235 Successful calls to \fBlwres_gethostbyname_r()\fR and
236 \fBlwres_gethostbyaddr_r()\fR return
237 \fIresbuf\fR, a pointer to the \fBstruct
238 hostent\fR that was initialised by these functions. They return
239 \fBNULL\fR if the lookups fail or if \fIbuf\fR
240 was too small to hold the list of addresses and names referenced by
241 the h_name, h_aliases, and
242 h_addr_list elements of the \fBstruct
243 hostent\fR. If \fIbuf\fR was too small, both
244 \fBlwres_gethostbyname_r()\fR and
245 \fBlwres_gethostbyaddr_r()\fR set the global variable
246 \fBerrno\fR to ERANGE.
250 \fBlwres_getipnode\fR(3),
251 \fBlwres_hstrerror\fR(3)
254 \fBlwres_gethostbyname()\fR,
255 \fBlwres_gethostbyname2()\fR,
256 \fBlwres_gethostbyaddr()\fR
258 \fBlwres_endhostent()\fR
259 are not thread safe; they return pointers to static data and
260 provide error codes through a global variable.
261 Thread-safe versions for name and address lookup are provided by
262 \fBlwres_gethostbyname_r()\fR,
264 \fBlwres_gethostbyaddr_r()\fR
267 The resolver daemon does not currently support any non-DNS
268 name services such as
272 consequently the above functions don't, either.