.\" Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") .\" Copyright (C) 2001 Internet Software Consortium. .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR .\" PERFORMANCE OF THIS SOFTWARE. .\" .\" $Id$ .\" .hy 0 .ad l .\" ** You probably do not want to edit this file directly ** .\" It was generated using the DocBook XSL Stylesheets (version 1.69.1). .\" Instead of manually editing it, you probably should edit the DocBook XML .\" source for it and then use the DocBook XSL Stylesheets to regenerate it. .TH "LWRES_GETHOSTENT" "3" "Jun 30, 2000" "SunOS 5.10" "Introduction to Library Functions" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .SH "NAME" 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 .SH "SYNOPSIS" .nf #include .fi .HP 37 \fBstruct\ hostent\ *\ \fBlwres_gethostbyname\fR\fR\fB(\fR\fBconst\ char\ *\fR\fB\fIname\fR\fR\fB);\fR .HP 38 \fBstruct\ hostent\ *\ \fBlwres_gethostbyname2\fR\fR\fB(\fR\fBconst\ char\ *\fR\fB\fIname\fR\fR\fB, \fR\fBint\ \fR\fB\fIaf\fR\fR\fB);\fR .HP 37 \fBstruct\ hostent\ *\ \fBlwres_gethostbyaddr\fR\fR\fB(\fR\fBconst\ char\ *\fR\fB\fIaddr\fR\fR\fB, \fR\fBint\ \fR\fB\fIlen\fR\fR\fB, \fR\fBint\ \fR\fB\fItype\fR\fR\fB);\fR .HP 34 \fBstruct\ hostent\ *\ \fBlwres_gethostent\fR\fR\fB(\fR\fBvoid\fR\fB);\fR .HP 22 \fBvoid\ \fBlwres_sethostent\fR\fR\fB(\fR\fBint\ \fR\fB\fIstayopen\fR\fR\fB);\fR .HP 22 \fBvoid\ \fBlwres_endhostent\fR\fR\fB(\fR\fBvoid\fR\fB);\fR .HP 39 \fBstruct\ hostent\ *\ \fBlwres_gethostbyname_r\fR\fR\fB(\fR\fBconst\ char\ *\fR\fB\fIname\fR\fR\fB, \fR\fBstruct\ hostent\ *\fR\fB\fIresbuf\fR\fR\fB, \fR\fBchar\ *\fR\fB\fIbuf\fR\fR\fB, \fR\fBint\ \fR\fB\fIbuflen\fR\fR\fB, \fR\fBint\ *\fR\fB\fIerror\fR\fR\fB);\fR .HP 39 \fBstruct\ hostent\ *\ \fBlwres_gethostbyaddr_r\fR\fR\fB(\fR\fBconst\ char\ *\fR\fB\fIaddr\fR\fR\fB, \fR\fBint\ \fR\fB\fIlen\fR\fR\fB, \fR\fBint\ \fR\fB\fItype\fR\fR\fB, \fR\fBstruct\ hostent\ *\fR\fB\fIresbuf\fR\fR\fB, \fR\fBchar\ *\fR\fB\fIbuf\fR\fR\fB, \fR\fBint\ \fR\fB\fIbuflen\fR\fR\fB, \fR\fBint\ *\fR\fB\fIerror\fR\fR\fB);\fR .HP 36 \fBstruct\ hostent\ *\ \fBlwres_gethostent_r\fR\fR\fB(\fR\fBstruct\ hostent\ *\fR\fB\fIresbuf\fR\fR\fB, \fR\fBchar\ *\fR\fB\fIbuf\fR\fR\fB, \fR\fBint\ \fR\fB\fIbuflen\fR\fR\fB, \fR\fBint\ *\fR\fB\fIerror\fR\fR\fB);\fR .HP 24 \fBvoid\ \fBlwres_sethostent_r\fR\fR\fB(\fR\fBint\ \fR\fB\fIstayopen\fR\fR\fB);\fR .HP 24 \fBvoid\ \fBlwres_endhostent_r\fR\fR\fB(\fR\fBvoid\fR\fB);\fR .SH "DESCRIPTION" .PP These functions provide hostname\-to\-address and address\-to\-hostname lookups by means of the lightweight resolver. They are similar to the standard \fBgethostent\fR(3) functions provided by most operating systems. They use a \fBstruct hostent\fR which is usually defined in \fI\fR. .PP .nf struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses from name server */ }; #define h_addr h_addr_list[0] /* address, for backward compatibility */ .fi .sp .PP The members of this structure are: .TP \fBh_name\fR The official (canonical) name of the host. .TP \fBh_aliases\fR A NULL\-terminated array of alternate names (nicknames) for the host. .TP \fBh_addrtype\fR The type of address being returned \(em \fBPF_INET\fR or \fBPF_INET6\fR. .TP \fBh_length\fR The length of the address in bytes. .TP \fBh_addr_list\fR A \fBNULL\fR terminated array of network addresses for the host. Host addresses are returned in network byte order. .PP For backward compatibility with very old software, \fBh_addr\fR is the first address in \fBh_addr_list.\fR .PP \fBlwres_gethostent()\fR, \fBlwres_sethostent()\fR, \fBlwres_endhostent()\fR, \fBlwres_gethostent_r()\fR, \fBlwres_sethostent_r()\fR and \fBlwres_endhostent_r()\fR provide iteration over the known host entries on systems that provide such functionality through facilities like \fI/etc/hosts\fR or NIS. The lightweight resolver does not currently implement these functions; it only provides them as stub functions that always return failure. .PP \fBlwres_gethostbyname()\fR and \fBlwres_gethostbyname2()\fR look up the hostname \fIname\fR. \fBlwres_gethostbyname()\fR always looks for an IPv4 address while \fBlwres_gethostbyname2()\fR looks for an address of protocol family \fIaf\fR: either \fBPF_INET\fR or \fBPF_INET6\fR \(em IPv4 or IPV6 addresses respectively. Successful calls of the functions return a \fBstruct hostent\fRfor the name that was looked up. \fBNULL\fR is returned if the lookups by \fBlwres_gethostbyname()\fR or \fBlwres_gethostbyname2()\fR fail. .PP Reverse lookups of addresses are performed by \fBlwres_gethostbyaddr()\fR. \fIaddr\fR is an address of length \fIlen\fR bytes and protocol family \fItype\fR \(em \fBPF_INET\fR or \fBPF_INET6\fR. \fBlwres_gethostbyname_r()\fR is a thread\-safe function for forward lookups. If an error occurs, an error code is returned in \fI*error\fR. \fIresbuf\fR is a pointer to a \fBstruct hostent\fR which is initialised by a successful call to \fBlwres_gethostbyname_r()\fR. \fIbuf\fR is a buffer of length \fIlen\fR bytes which is used to store the \fBh_name\fR, \fBh_aliases\fR, and \fBh_addr_list\fR elements of the \fBstruct hostent\fR returned in \fIresbuf\fR. Successful calls to \fBlwres_gethostbyname_r()\fR return \fIresbuf\fR, which is a pointer to the \fBstruct hostent\fR it created. .PP \fBlwres_gethostbyaddr_r()\fR is a thread\-safe function that performs a reverse lookup of address \fIaddr\fR which is \fIlen\fR bytes long and is of protocol family \fItype\fR \(em \fBPF_INET\fR or \fBPF_INET6\fR. If an error occurs, the error code is returned in \fI*error\fR. The other function parameters are identical to those in \fBlwres_gethostbyname_r()\fR. \fIresbuf\fR is a pointer to a \fBstruct hostent\fR which is initialised by a successful call to \fBlwres_gethostbyaddr_r()\fR. \fIbuf\fR is a buffer of length \fIlen\fR bytes which is used to store the \fBh_name\fR, \fBh_aliases\fR, and \fBh_addr_list\fR elements of the \fBstruct hostent\fR returned in \fIresbuf\fR. Successful calls to \fBlwres_gethostbyaddr_r()\fR return \fIresbuf\fR, which is a pointer to the \fBstruct hostent()\fR it created. .SH "RETURN VALUES" .PP The functions \fBlwres_gethostbyname()\fR, \fBlwres_gethostbyname2()\fR, \fBlwres_gethostbyaddr()\fR, and \fBlwres_gethostent()\fR return NULL to indicate an error. In this case the global variable \fBlwres_h_errno\fR will contain one of the following error codes defined in \fI\fR: .TP \fBHOST_NOT_FOUND\fR The host or address was not found. .TP \fBTRY_AGAIN\fR A recoverable error occurred, e.g., a timeout. Retrying the lookup may succeed. .TP \fBNO_RECOVERY\fR A non\-recoverable error occurred. .TP \fBNO_DATA\fR 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. .PP \fBlwres_hstrerror\fR(3) translates these error codes to suitable error messages. .PP \fBlwres_gethostent()\fR and \fBlwres_gethostent_r()\fR always return \fBNULL\fR. .PP Successful calls to \fBlwres_gethostbyname_r()\fR and \fBlwres_gethostbyaddr_r()\fR return \fIresbuf\fR, a pointer to the \fBstruct hostent\fR that was initialised by these functions. They return \fBNULL\fR if the lookups fail or if \fIbuf\fR was too small to hold the list of addresses and names referenced by the \fBh_name\fR, \fBh_aliases\fR, and \fBh_addr_list\fR elements of the \fBstruct hostent\fR. If \fIbuf\fR was too small, both \fBlwres_gethostbyname_r()\fR and \fBlwres_gethostbyaddr_r()\fR set the global variable \fBerrno\fR to \fBERANGE\fR. .SH "SEE ALSO" .PP \fBgethostent\fR(3), \fBlwres_getipnode\fR(3), \fBlwres_hstrerror\fR(3) .SH "BUGS" .PP \fBlwres_gethostbyname()\fR, \fBlwres_gethostbyname2()\fR, \fBlwres_gethostbyaddr()\fR and \fBlwres_endhostent()\fR 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 \fBlwres_gethostbyname_r()\fR, and \fBlwres_gethostbyaddr_r()\fR respectively. .PP The resolver daemon does not currently support any non\-DNS name services such as \fI/etc/hosts\fR or \fBNIS\fR, consequently the above functions don't, either.