lwres_gethostent.docbook revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
c30ef289fe64ac7fedc44cfcc6b439f0f8458b4cgregames<!ENTITY mdash "—">]>
5541a81e194dc99521c0ecf904a940b0b65a93f2nd - Copyright (C) 2001, 2004, 2005, 2007, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
921777ee81b0509c2aed209e3974e103c395259ajerenkrantz - This Source Code Form is subject to the terms of the Mozilla Public
921777ee81b0509c2aed209e3974e103c395259ajerenkrantz - License, v. 2.0. If a copy of the MPL was not distributed with this
b7cbb2495d82008f9fa72226b9213d639362feabjorton - file, You can obtain one at http://mozilla.org/MPL/2.0/.
07342c358cd73b304b1991e359a3faf720c966ecnd<!-- Converted by db4-upgrade version 1.0 -->
07342c358cd73b304b1991e359a3faf720c966ecnd<refentry xmlns="http://docbook.org/ns/docbook" version="5.0">
9556fb65eecaa55b866b413d5e262cd54be88f21nd <refentryinfo>
7d851311462dce44df8469009f98ba66d7f7f18end <corpauthor>Internet Systems Consortium, Inc.</corpauthor>
7d851311462dce44df8469009f98ba66d7f7f18end </refentryinfo>
987c2c2ff2f19f306357f79d3280b347d96c470fnd </refmeta>
99c475e760470ab8ca3d17da82a2f6158466f918rederpj <copyright>
8eeb24cab1b849bd17726d0a030cd299209f108cnd <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
8eeb24cab1b849bd17726d0a030cd299209f108cnd </copyright>
8eeb24cab1b849bd17726d0a030cd299209f108cnd <copyright>
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpj </copyright>
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpj <refnamediv>
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd <refpurpose>lightweight resolver get network host entry</refpurpose>
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd </refnamediv>
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd <refsynopsisdiv>
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd <funcsynopsis>
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawick<funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawick<funcprototype>
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpjstruct hostent *
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpj <paramdef>const char *<parameter>name</parameter></paramdef>
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpj </funcprototype>
d1c46782edbd6bd5ae4592c0174969950c5ca8aetrawick<funcprototype>
d1c46782edbd6bd5ae4592c0174969950c5ca8aetrawickstruct hostent *
a3954060338ccebc73071e89ac936d4ec15ab352trawick <paramdef>const char *<parameter>name</parameter></paramdef>
a3954060338ccebc73071e89ac936d4ec15ab352trawick </funcprototype>
ab56518227d474ee08f039e4c5540011c1b8a913trawick<funcprototype>
ab56518227d474ee08f039e4c5540011c1b8a913trawickstruct hostent *
4e330708371c3e9b04d1043f0a1ac9368bfbd768coar <paramdef>const char *<parameter>addr</parameter></paramdef>
532a5de31e1a9732da4923f88e4931d0724ebe72nd </funcprototype>
532a5de31e1a9732da4923f88e4931d0724ebe72nd<funcprototype>
a98959721afc481c7f3a941f85c462f0b90defdathommaystruct hostent *
219e31b849ef108cd8f58ba0eedae03414e5edb1thommay </funcprototype>
dbb916b882c33a4e340b0dba7d75506cfdd85640trawick<funcprototype>
dbb916b882c33a4e340b0dba7d75506cfdd85640trawick <paramdef>int <parameter>stayopen</parameter></paramdef>
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick </funcprototype>
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick<funcprototype>
9098f795fab5db41a52b6b82fa475e8f9b3850f0trawick </funcprototype>
9efe68be3c81ee85225972195fb725dbfc2e8b24trawick<funcprototype>
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawickstruct hostent *
fc25339741311efd7d460f18b6287ef38d76bbe6madhum <paramdef>const char *<parameter>name</parameter></paramdef>
fc25339741311efd7d460f18b6287ef38d76bbe6madhum <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
fc25339741311efd7d460f18b6287ef38d76bbe6madhum <paramdef>char *<parameter>buf</parameter></paramdef>
fc25339741311efd7d460f18b6287ef38d76bbe6madhum <paramdef>int <parameter>buflen</parameter></paramdef>
fcdca175a52fe517f2317ba0e2b6e6d14522b869madhum <paramdef>int *<parameter>error</parameter></paramdef>
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz </funcprototype>
92a2439559cf1161742650ed9c50c6483bd029cemadhum<funcprototype>
92a2439559cf1161742650ed9c50c6483bd029cemadhumstruct hostent *
ebecc16986604cce1369d5075eff65032e3dd0deianh <paramdef>const char *<parameter>addr</parameter></paramdef>
764315969cef40e50cdc6a5e9638454e10c1c06end <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
bfb54bd96690887dcdf184fd9083c2e167898ce2nd </funcprototype>
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake<funcprototype>
a2c036f0ca71e35c085b4cd9451a6d3718bc65daakestruct hostent *
b92cba59a0890be43b14aaf1ce30606140be9593nd <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick </funcprototype>
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick<funcprototype>
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantz<function>lwres_sethostent_r</function></funcdef>
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantz <paramdef>int <parameter>stayopen</parameter></paramdef>
a3f2646ef3d8a3a5234a5601de0f95f10308c2a6jerenkrantz </funcprototype>
a3f2646ef3d8a3a5234a5601de0f95f10308c2a6jerenkrantz<funcprototype>
9e398d701dd430f073ff5418fb720642e064046ajerenkrantz<function>lwres_endhostent_r</function></funcdef>
1a5b9e0071f0c662036250b482d566ad87ff0b4bjerenkrantz </funcprototype>
1a5b9e0071f0c662036250b482d566ad87ff0b4bjerenkrantz</funcsynopsis>
1a5b9e0071f0c662036250b482d566ad87ff0b4bjerenkrantz </refsynopsisdiv>
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantz <refsection><info><title>DESCRIPTION</title></info>
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74nd These functions provide hostname-to-address and
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74nd address-to-hostname lookups by means of the lightweight resolver.
db5837bbc9bef214303e755fa52122140366cb6fianh They are similar to the standard
db5837bbc9bef214303e755fa52122140366cb6fianh <citerefentry>
db5837bbc9bef214303e755fa52122140366cb6fianh <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
aac2b82fe4f1ac117e2a0702438d6615542642dand </citerefentry>
aac2b82fe4f1ac117e2a0702438d6615542642dand functions provided by most operating systems.
aac2b82fe4f1ac117e2a0702438d6615542642dand They use a
a793d402c74e50326a2401cfbdc562c5781948fdnd which is usually defined in
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzstruct hostent {
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz char *h_name; /* official name of host */
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz char **h_aliases; /* alias list */
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz int h_addrtype; /* host address type */
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz int h_length; /* length of address */
ab8c0315521735c73ce16c8072f91e17c406ca5bnd char **h_addr_list; /* list of addresses from name server */
ab8c0315521735c73ce16c8072f91e17c406ca5bnd#define h_addr h_addr_list[0] /* address, for backward compatibility */
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd</programlisting>
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd The members of this structure are:
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz <variablelist>
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz <varlistentry>
4567cfc6a65328bd3e8dd2b758ca926b389c7058brianp The official (canonical) name of the host.
4cdc5446050c19b9d519a273a129188586e8d445jerenkrantz </varlistentry>
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard <varlistentry>
d5b7ba26785d7494166d48876362ba30ff30b98awrowe A NULL-terminated array of alternate names (nicknames) for the
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz </varlistentry>
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz <varlistentry>
aec70520ebe1e33e0d5e83c3626649d2a41dbe68wrowe The type of address being returned —
59b910556d04c82e951d6c6f7a413ab8fed21467trawick </listitem>
59b910556d04c82e951d6c6f7a413ab8fed21467trawick </varlistentry>
85bf271a2a8d88736575e93504528639f5971f97nd <varlistentry>
85bf271a2a8d88736575e93504528639f5971f97nd <listitem>
5c457d20a708ef42b0824290d0feda1852a37493rederpj The length of the address in bytes.
13590409a89cdf7e5dc52516919ccee94edad59brederpj </listitem>
5c457d20a708ef42b0824290d0feda1852a37493rederpj </varlistentry>
a22d4a5da8c5167776b9e62737379cc9b857ef4drederpj <varlistentry>
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd terminated array of network addresses for the host.
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd Host addresses are returned in network byte order.
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd </listitem>
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick </varlistentry>
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick </variablelist>
59b910556d04c82e951d6c6f7a413ab8fed21467trawick For backward compatibility with very old software,
59b910556d04c82e951d6c6f7a413ab8fed21467trawick is the first address in
03e310ef946842b4dfa718776c870d012fc9ec67striker provide iteration over the known host entries on systems that
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker provide such functionality through facilities like
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker or NIS. The lightweight resolver does not currently implement
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker these functions; it only provides them as stub functions that always
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker return failure.
f59888906d0566361498848fa95b4c416fad976cstriker and <function>lwres_gethostbyname2()</function> look up the
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker <function>lwres_gethostbyname()</function> always looks for an
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker IPv4 address while <function>lwres_gethostbyname2()</function>
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker looks for an address of protocol family
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker <parameter>af</parameter>: either <type>PF_INET</type> or
26acc990e97a62631a3654405d676b928a78ebbcstriker <type>PF_INET6</type> — IPv4 or IPV6 addresses
26acc990e97a62631a3654405d676b928a78ebbcstriker respectively. Successful calls of the functions return a
29ecc0949b383793b24cdd0741cb86c02138ab36striker <type>struct hostent</type>for the name that was looked up.
c97f8ff3a7479c838545de0c59770938b50ab6d3gstein Reverse lookups of addresses are performed by
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick <parameter>len</parameter> bytes and protocol family
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick <parameter>type</parameter> — <type>PF_INET</type> or
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick thread-safe function
368a950bc36b428b737d079f77e8962c831f88aand for forward lookups. If an error occurs, an error code is returned in
368a950bc36b428b737d079f77e8962c831f88aand <type>struct hostent</type> which is initialised by a successful call to
9768955299008e29705461b314b763a79104e576nd <parameter>len</parameter> bytes which is used to store the
9768955299008e29705461b314b763a79104e576nd <constant>h_name</constant>, <constant>h_aliases</constant>, and
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc Successful calls to <function>lwres_gethostbyname_r()</function>
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc which is a pointer to the <type>struct hostent</type> it created.
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc is a thread-safe function
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc that performs a reverse lookup of address <parameter>addr</parameter>
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc which is <parameter>len</parameter> bytes long and is of
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz family <parameter>type</parameter> — <type>PF_INET</type> or
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz <type>PF_INET6</type>. If an error occurs, the error code is returned
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz in <parameter>*error</parameter>. The other function
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz parameters are
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz identical to those in <function>lwres_gethostbyname_r()</function>.
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz <type>struct hostent</type> which is initialised by a successful call to
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz <parameter>buf</parameter> is a buffer of length
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz <parameter>len</parameter> bytes which is used to store the
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz <constant>h_name</constant>, <constant>h_aliases</constant>, and
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz <constant>h_addr_list</constant> elements of the
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz Successful calls to <function>lwres_gethostbyaddr_r()</function> return
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz <parameter>resbuf</parameter>, which is a pointer to the
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz <function>struct hostent()</function> it created.
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz </refsection>
e874834efe9943668668c7fa498af3b3c7caffbdnd The functions
38873f61704cbe5eadaa3fb9dca84a4bee1ae5d5wrowe return NULL to indicate an error. In this case the global variable
38873f61704cbe5eadaa3fb9dca84a4bee1ae5d5wrowe will contain one of the following error codes defined in
68a80326bd8b6f717ae0c44d4bb7273023aad1edwrowe <variablelist>
68a80326bd8b6f717ae0c44d4bb7273023aad1edwrowe <varlistentry>
68a80326bd8b6f717ae0c44d4bb7273023aad1edwrowe The host or address was not found.
6838d0e05a193cb77265db36e3549201b3df57e6wrowe </listitem>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe </varlistentry>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <varlistentry>
903c124068c87c957f1327de486017a19cccd348stoddard A recoverable error occurred, e.g., a timeout.
732269e2780cb818c1b48aeffa0b432b0ce4ee5eaaron Retrying the lookup may succeed.
20aa030accab9a4df293294283fbe6a4ae961588trawick </listitem>
20aa030accab9a4df293294283fbe6a4ae961588trawick </varlistentry>
20aa030accab9a4df293294283fbe6a4ae961588trawick <varlistentry>
e08b3783b570fdea39520da5e6c174394e956d17nd <listitem>
e08b3783b570fdea39520da5e6c174394e956d17nd A non-recoverable error occurred.
e08b3783b570fdea39520da5e6c174394e956d17nd </listitem>
e08b3783b570fdea39520da5e6c174394e956d17nd </varlistentry>
e08b3783b570fdea39520da5e6c174394e956d17nd <varlistentry>
e08b3783b570fdea39520da5e6c174394e956d17nd <listitem>
16de8ff78c533f06c64d5ab2b685953992ff8659thommay The name exists, but has no address information
16de8ff78c533f06c64d5ab2b685953992ff8659thommay associated with it (or vice versa in the case
16de8ff78c533f06c64d5ab2b685953992ff8659thommay of a reverse lookup). The code NO_ADDRESS
16de8ff78c533f06c64d5ab2b685953992ff8659thommay is accepted as a synonym for NO_DATA for backwards
5aef954598e763eea457d204897a6a12d281755dtrawick compatibility.
5aef954598e763eea457d204897a6a12d281755dtrawick </listitem>
5aef954598e763eea457d204897a6a12d281755dtrawick </varlistentry>
340e970018246649e86dd3ebbd34f4719e3ceaf7trawick </variablelist>
1360e9b0036040edfbcd2273ae18db83a93536detrawick <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
1360e9b0036040edfbcd2273ae18db83a93536detrawick </citerefentry>
1360e9b0036040edfbcd2273ae18db83a93536detrawick translates these error codes to suitable error messages.
c3f32ea297c5350948a0c4472c1ff8433ea4e6bastoddard Successful calls to <function>lwres_gethostbyname_r()</function> and
946f7bd76a0dec6d67af79af56a8cff3cb6ef9c1nd <type>struct hostent</type> that was initialised by these functions. They return
946f7bd76a0dec6d67af79af56a8cff3cb6ef9c1nd <type>NULL</type> if the lookups fail or if <parameter>buf</parameter>
8c038cdb417502a969599568ccc4020576d82a10nd was too small to hold the list of addresses and names referenced by
8c038cdb417502a969599568ccc4020576d82a10nd the <constant>h_name</constant>, <constant>h_aliases</constant>, and
8c038cdb417502a969599568ccc4020576d82a10nd <function>lwres_gethostbyaddr_r()</function> set the global
83938932cb2dbe320eda488799bb7a0c04156bcdake </refsection>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe </citerefentry>,
6fbf645df300ffa9c9693399571f2cd821af06fdtrawick <citerefentry>
6fbf645df300ffa9c9693399571f2cd821af06fdtrawick <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
6fbf645df300ffa9c9693399571f2cd821af06fdtrawick </citerefentry>,
c8ff8621370eb28a3f697a00bf5e6b3bc1a0d9f1minfrin <citerefentry>
c8ff8621370eb28a3f697a00bf5e6b3bc1a0d9f1minfrin <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
c8ff8621370eb28a3f697a00bf5e6b3bc1a0d9f1minfrin </citerefentry>
c8ff8621370eb28a3f697a00bf5e6b3bc1a0d9f1minfrin </refsection>
6aa783d83f4304f664233d8252cb67116769676ewrowe are not thread safe; they return pointers to static data and
6aa783d83f4304f664233d8252cb67116769676ewrowe provide error codes through a global variable.
6aa783d83f4304f664233d8252cb67116769676ewrowe Thread-safe versions for name and address lookup are provided by
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd respectively.
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd The resolver daemon does not currently support any non-DNS
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd name services such as
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd consequently the above functions don't, either.
5d6ffa7b5c77dd4132ed6d7f0dd63548b1c3c1c9nd </refsection>