📄 lwres_gethostent.3
字号:
.\" Copyright (C) 2004, 2005 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: lwres_gethostent.3,v 1.16.2.1.8.5 2005/10/13 02:33:53 marka Exp $.\".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" "BIND9" "BIND9".\" 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 <lwres/netdb.h>.fi.HP 37\fBstruct\ hostent\ *\ \fBlwres_gethostbyname\fR\fR\fB(\fR\fBconst\ char\ *name\fR\fB);\fR.HP 38\fBstruct\ hostent\ *\ \fBlwres_gethostbyname2\fR\fR\fB(\fR\fBconst\ char\ *name\fR\fB, \fR\fBint\ af\fR\fB);\fR.HP 37\fBstruct\ hostent\ *\ \fBlwres_gethostbyaddr\fR\fR\fB(\fR\fBconst\ char\ *addr\fR\fB, \fR\fBint\ len\fR\fB, \fR\fBint\ type\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\ stayopen\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\ *name\fR\fB, \fR\fBstruct\ hostent\ *resbuf\fR\fB, \fR\fBchar\ *buf\fR\fB, \fR\fBint\ buflen\fR\fB, \fR\fBint\ *error\fR\fB);\fR.HP 39\fBstruct\ hostent\ *\ \fBlwres_gethostbyaddr_r\fR\fR\fB(\fR\fBconst\ char\ *addr\fR\fB, \fR\fBint\ len\fR\fB, \fR\fBint\ type\fR\fB, \fR\fBstruct\ hostent\ *resbuf\fR\fB, \fR\fBchar\ *buf\fR\fB, \fR\fBint\ buflen\fR\fB, \fR\fBint\ *error\fR\fB);\fR.HP 36\fBstruct\ hostent\ *\ \fBlwres_gethostent_r\fR\fR\fB(\fR\fBstruct\ hostent\ *resbuf\fR\fB, \fR\fBchar\ *buf\fR\fB, \fR\fBint\ buflen\fR\fB, \fR\fBint\ *error\fR\fB);\fR.HP 24\fBvoid\ \fBlwres_sethostent_r\fR\fR\fB(\fR\fBint\ stayopen\fR\fB);\fR.HP 24\fBvoid\ \fBlwres_endhostent_r\fR\fR\fB(\fR\fBvoid\fR\fB);\fR.SH "DESCRIPTION".PPThese 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\fRwhich is usually defined in\fI<namedb.h>\fR..sp.nfstruct 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.PPThe members of this structure are:.TP\fBh_name\fRThe official (canonical) name of the host..TP\fBh_aliases\fRA NULL\-terminated array of alternate names (nicknames) for the host..TP\fBh_addrtype\fRThe type of address being returned \(em\fBPF_INET\fRor\fBPF_INET6\fR..TP\fBh_length\fRThe length of the address in bytes..TP\fBh_addr_list\fRA\fBNULL\fRterminated array of network addresses for the host. Host addresses are returned in network byte order..PPFor backward compatibility with very old software,\fBh_addr\fRis 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()\fRand\fBlwres_endhostent_r()\fRprovide iteration over the known host entries on systems that provide such functionality through facilities like\fI/etc/hosts\fRor NIS. The lightweight resolver does not currently implement these functions; it only provides them as stub functions that always return failure..PP\fBlwres_gethostbyname()\fRand\fBlwres_gethostbyname2()\fRlook up the hostname\fIname\fR.\fBlwres_gethostbyname()\fRalways looks for an IPv4 address while\fBlwres_gethostbyname2()\fRlooks for an address of protocol family\fIaf\fR: either\fBPF_INET\fRor\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\fRis returned if the lookups by\fBlwres_gethostbyname()\fRor\fBlwres_gethostbyname2()\fRfail..PPReverse lookups of addresses are performed by\fBlwres_gethostbyaddr()\fR.\fIaddr\fRis an address of length\fIlen\fRbytes and protocol family\fItype\fR\(em\fBPF_INET\fRor\fBPF_INET6\fR.\fBlwres_gethostbyname_r()\fRis a thread\-safe function for forward lookups. If an error occurs, an error code is returned in\fI*error\fR.\fIresbuf\fRis a pointer to a\fBstruct hostent\fRwhich is initialised by a successful call to\fBlwres_gethostbyname_r()\fR.\fIbuf\fRis a buffer of length\fIlen\fRbytes which is used to store the\fBh_name\fR,\fBh_aliases\fR, and\fBh_addr_list\fRelements of the\fBstruct hostent\fRreturned in\fIresbuf\fR. Successful calls to\fBlwres_gethostbyname_r()\fRreturn\fIresbuf\fR, which is a pointer to the\fBstruct hostent\fRit created..PP\fBlwres_gethostbyaddr_r()\fRis a thread\-safe function that performs a reverse lookup of address\fIaddr\fRwhich is\fIlen\fRbytes long and is of protocol family\fItype\fR\(em\fBPF_INET\fRor\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\fRis a pointer to a\fBstruct hostent\fRwhich is initialised by a successful call to\fBlwres_gethostbyaddr_r()\fR.\fIbuf\fRis a buffer of length\fIlen\fRbytes which is used to store the\fBh_name\fR,\fBh_aliases\fR, and\fBh_addr_list\fRelements of the\fBstruct hostent\fRreturned in\fIresbuf\fR. Successful calls to\fBlwres_gethostbyaddr_r()\fRreturn\fIresbuf\fR, which is a pointer to the\fBstruct hostent()\fRit created..SH "RETURN VALUES".PPThe functions\fBlwres_gethostbyname()\fR,\fBlwres_gethostbyname2()\fR,\fBlwres_gethostbyaddr()\fR, and\fBlwres_gethostent()\fRreturn NULL to indicate an error. In this case the global variable\fBlwres_h_errno\fRwill contain one of the following error codes defined in\fI<lwres/netdb.h>\fR:.TP\fBHOST_NOT_FOUND\fRThe host or address was not found..TP\fBTRY_AGAIN\fRA recoverable error occurred, e.g., a timeout. Retrying the lookup may succeed..TP\fBNO_RECOVERY\fRA non\-recoverable error occurred..TP\fBNO_DATA\fRThe 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()\fRand\fBlwres_gethostent_r()\fRalways return\fBNULL\fR..PPSuccessful calls to\fBlwres_gethostbyname_r()\fRand\fBlwres_gethostbyaddr_r()\fRreturn\fIresbuf\fR, a pointer to the\fBstruct hostent\fRthat was initialised by these functions. They return\fBNULL\fRif the lookups fail or if\fIbuf\fRwas too small to hold the list of addresses and names referenced by the\fBh_name\fR,\fBh_aliases\fR, and\fBh_addr_list\fRelements of the\fBstruct hostent\fR. If\fIbuf\fRwas too small, both\fBlwres_gethostbyname_r()\fRand\fBlwres_gethostbyaddr_r()\fRset the global variable\fBerrno\fRto\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()\fRand\fBlwres_endhostent()\fRare 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()\fRrespectively..PPThe resolver daemon does not currently support any non\-DNS name services such as\fI/etc/hosts\fRor\fBNIS\fR, consequently the above functions don't, either.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -