man-pages/man3/resolver.3.html
2021-03-31 01:06:50 +01:00

709 lines
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of RESOLVER</TITLE>
</HEAD><BODY>
<H1>RESOLVER</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
res_ninit, res_nclose, res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend,
res_init, res_query, res_search, res_querydomain, res_mkquery, res_send,
dn_comp, dn_expand - resolver routines
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/netinet/in.h">netinet/in.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/arpa/nameser.h">arpa/nameser.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/resolv.h">resolv.h</A>&gt;</B>
<B>struct __res_state;</B>
<B>typedef struct __res_state *res_state;</B>
<B>int res_ninit(res_state </B><I>statep</I><B>);</B>
<B>void res_nclose(res_state </B><I>statep</I><B>);</B>
<B>int res_nquery(res_state </B><I>statep</I><B>,</B>
<B> const char *</B><I>dname</I><B>, int </B><I>class</I><B>, int </B><I>type</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
<B>int res_nsearch(res_state </B><I>statep</I><B>,</B>
<B> const char *</B><I>dname</I><B>, int </B><I>class</I><B>, int </B><I>type</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
<B>int res_nquerydomain(res_state </B><I>statep</I><B>,</B>
<B> const char *</B><I>name</I><B>, const char *</B><I>domain</I><B>,</B>
<B> int </B><I>class</I><B>, int </B><I>type</I><B>, unsigned char *</B><I>answer</I><B>,</B>
<B> int </B><I>anslen</I><B>);</B>
<B>int res_nmkquery(res_state </B><I>statep</I><B>,</B>
<B> int </B><I>op</I><B>, const char *</B><I>dname</I><B>, int </B><I>class</I><B>,</B>
<B> int </B><I>type</I><B>, const unsigned char *</B><I>data</I><B>, int </B><I>datalen</I><B>,</B>
<B> const unsigned char *</B><I>newrr</I><B>,</B>
<B> unsigned char *</B><I>buf</I><B>, int </B><I>buflen</I><B>);</B>
<B>int res_nsend(res_state </B><I>statep</I><B>,</B>
<B> const unsigned char *</B><I>msg</I><B>, int </B><I>msglen</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
<B>int dn_comp(const char *</B><I>exp_dn</I><B>, unsigned char *</B><I>comp_dn</I><B>,</B>
<B> int </B><I>length</I><B>, unsigned char **</B><I>dnptrs</I><B>,</B>
<B> unsigned char **</B><I>lastdnptr</I><B>);</B>
<B>int dn_expand(const unsigned char *</B><I>msg</I><B>,</B>
<B> const unsigned char *</B><I>eomorig</I><B>,</B>
<B> const unsigned char *</B><I>comp_dn</I><B>, char *</B><I>exp_dn</I><B>,</B>
<B> int </B><I>length</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H3>Deprecated</H3>
<PRE>
<B>extern struct __res_state _res;</B>
<B>int res_init(void);</B>
<B>int res_query(const char *</B><I>dname</I><B>, int </B><I>class</I><B>, int </B><I>type</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
<B>int res_search(const char *</B><I>dname</I><B>, int </B><I>class</I><B>, int </B><I>type</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
<B>int res_querydomain(const char *</B><I>name</I><B>, const char *</B><I>domain</I><B>,</B>
<B> int </B><I>class</I><B>, int </B><I>type</I><B>, unsigned char *</B><I>answer</I><B>,</B>
<B> int </B><I>anslen</I><B>);</B>
<B>int res_mkquery(int </B><I>op</I><B>, const char *</B><I>dname</I><B>, int </B><I>class</I><B>,</B>
<B> int </B><I>type</I><B>, const unsigned char *</B><I>data</I><B>, int </B><I>datalen</I><B>,</B>
<B> const unsigned char *</B><I>newrr</I><B>,</B>
<B> unsigned char *</B><I>buf</I><B>, int </B><I>buflen</I><B>);</B>
<B>int res_send(const unsigned char *</B><I>msg</I><B>, int </B><I>msglen</I><B>,</B>
<B> unsigned char *</B><I>answer</I><B>, int </B><I>anslen</I><B>);</B>
</PRE>
<P>
Link with <I>-lresolv</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>Note:</B>
This page is incomplete (various resolver functions provided by glibc
are not described) and likely out of date.
<P>
The functions described below make queries to and interpret
the responses from Internet domain name servers.
<P>
The API consists of a set of more modern, reentrant functions
and an older set of nonreentrant functions that have been superseded.
The traditional resolver interfaces such as
<B>res_init</B>()
and
<B>res_query</B>()
use some static (global) state stored in the
<I>_res</I>
structure, rendering these functions non-thread-safe.
BIND 8.2 introduced a set of new interfaces
<B>res_ninit</B>(),
<B>res_nquery</B>(),
and so on, which take a
<I>res_state</I>
as their first argument, so you can use a per-thread resolver state.
<P>
The
<B>res_ninit</B>()
and
<B>res_init</B>()
functions read the configuration files (see
<B><A HREF="/cgi-bin/man/man2html?5+resolv.conf">resolv.conf</A></B>(5))
to get the default domain name and name
server address(es).
If no server is given, the local host is tried.
If no domain is given, that associated with the local host is used.
It can be overridden with the environment variable
<B>LOCALDOMAIN</B>.
<B>res_ninit</B>()
or
<B>res_init</B>()
is normally executed by the first call to one of the
other functions.
Every call to
<B>res_ninit</B>()
requires a corresponding call to
<B>res_nclose</B>()
to free memory allocated by
<B>res_ninit</B>()
and subsequent calls to
<B>res_nquery</B>().
<P>
The
<B>res_nquery</B>()
and
<B>res_query</B>()
functions query the name server for the
fully qualified domain name <I>name</I> of specified <I>type</I> and
<I>class</I>.
The reply is left in the buffer <I>answer</I> of length
<I>anslen</I> supplied by the caller.
<P>
The
<B>res_nsearch</B>()
and
<B>res_search</B>()
functions make a query and waits for the response like
<B>res_nquery</B>()
and
<B>res_query</B>(),
but in addition they implement the default and search
rules controlled by
<B>RES_DEFNAMES</B>
and
<B>RES_DNSRCH</B>
(see description of
<I>_res</I> options below).
<P>
The
<B>res_nquerydomain</B>()
and
<B>res_querydomain</B>()
functions make a query using
<B>res_nquery</B>()/<B>res_query</B>()
on the concatenation of <I>name</I> and <I>domain</I>.
<P>
The following functions are lower-level routines used by
<B>res_query</B>()/<B>res_query</B>().
<P>
The
<B>res_nmkquery</B>()
and
<B>res_mkquery</B>()
functions construct a query message in <I>buf</I>
of length <I>buflen</I> for the domain name <I>dname</I>.
The query type
<I>op</I> is one of the following (typically
<B>QUERY</B>):
<DL COMPACT>
<DT id="1"><B>QUERY</B>
<DD>
Standard query.
<DT id="2"><B>IQUERY</B>
<DD>
Inverse query.
This option was removed in glibc 2.26,
since it has not been supported by DNS servers for a very long time.
<DT id="3"><B>NS_NOTIFY_OP</B>
<DD>
Notify secondary of SOA (Start of Authority) change.
</DL>
<P>
<I>newrr</I> is currently unused.
<P>
The
<B>res_nsend</B>()
and
<B>res_send</B>()
function send a preformatted query given in
<I>msg</I> of length <I>msglen</I> and returns the answer in <I>answer</I>
which is of length <I>anslen</I>.
They will call
<B>res_ninit</B>()/<B>res_init</B>()
if it has not already been called.
<P>
The
<B>dn_comp</B>()
function compresses the domain name <I>exp_dn</I>
and stores it in the buffer <I>comp_dn</I> of length <I>length</I>.
The compression uses an array of pointers <I>dnptrs</I> to previously
compressed names in the current message.
The first pointer points
to the beginning of the message and the list ends with NULL.
The limit of the array is specified by <I>lastdnptr</I>.
If <I>dnptr</I> is NULL, domain names are not compressed.
If <I>lastdnptr</I> is NULL, the list
of labels is not updated.
<P>
The
<B>dn_expand</B>()
function expands the compressed domain name
<I>comp_dn</I> to a full domain name, which is placed in the buffer
<I>exp_dn</I> of size <I>length</I>.
The compressed name is contained
in a query or reply message, and <I>msg</I> points to the beginning of
the message.
<P>
The resolver routines use configuration and state information
contained in a
<I>__res_state</I>
structure (either passed as the
<I>statep</I>
argument, or in the global variable
<I>_res</I>,
in the case of the older nonreentrant functions).
The only field of this structure that is normally manipulated by the
user is the
<I>options</I>
field.
This field can contain the bitwise &quot;OR&quot;
of the following options:
<DL COMPACT>
<DT id="4"><B>RES_INIT</B>
<DD>
True if
<B>res_ninit</B>()
or
<B>res_init</B>()
has been called.
<DT id="5"><B>RES_DEBUG</B>
<DD>
Print debugging messages.
This option is available only if glibc was built with debugging enabled,
which is not the default.
<DT id="6"><B>RES_AAONLY</B> (unimplemented; deprecated in glibc 2.25)
<DD>
Accept authoritative answers only.
<B>res_send</B>()
continues until
it finds an authoritative answer or returns an error.
This option was present but unimplemented in glibc until version 2.24;
since glibc 2.25, it is deprecated, and its usage produces a warning.
<DT id="7"><B>RES_USEVC</B>
<DD>
Use TCP connections for queries rather than UDP datagrams.
<DT id="8"><B>RES_PRIMARY</B> (unimplemented; deprecated in glibc 2.25)
<DD>
Query primary domain name server only.
This option was present but unimplemented in glibc until version 2.24;
since glibc 2.25, it is deprecated, and its usage produces a warning.
<DT id="9"><B>RES_IGNTC</B>
<DD>
Ignore truncation errors.
Don't retry with TCP.
<DT id="10"><B>RES_RECURSE</B>
<DD>
Set the recursion desired bit in queries.
Recursion is carried out
by the domain name server, not by
<B>res_send</B>().
[Enabled by default].
<DT id="11"><B>RES_DEFNAMES</B>
<DD>
If set,
<B>res_search</B>()
will append the default domain name to
single component names---that is, those that do not contain a dot.
[Enabled by default].
<DT id="12"><B>RES_STAYOPEN</B>
<DD>
Used with
<B>RES_USEVC</B>
to keep the TCP connection open between queries.
<DT id="13"><B>RES_DNSRCH</B>
<DD>
If set,
<B>res_search</B>()
will search for hostnames in the current
domain and in parent domains.
This option is used by
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3).
[Enabled by default].
<DT id="14"><B>RES_INSECURE1</B>
<DD>
Accept a response from a wrong server.
This can be used to detect potential security hazards,
but you need to compile glibc with debugging enabled and use
<B>RES_DEBUG</B>
option (for debug purpose only).
<DT id="15"><B>RES_INSECURE2</B>
<DD>
Accept a response which contains a wrong query.
This can be used to detect potential security hazards,
but you need to compile glibc with debugging enabled and use
<B>RES_DEBUG</B>
option (for debug purpose only).
<DT id="16"><B>RES_NOALIASES</B>
<DD>
Disable usage of
<B>HOSTALIASES</B>
environment variable.
<DT id="17"><B>RES_USE_INET6</B>
<DD>
Try an AAAA query before an A query inside the
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3)
function, and map IPv4 responses in IPv6 &quot;tunneled form&quot; if no AAAA records
are found but an A record set exists.
Since glibc 2.25, this option is deprecated,
and its usage produces a warning;
applications should use
<B><A HREF="/cgi-bin/man/man2html?3+getaddrinfo">getaddrinfo</A></B>(3),
rather than
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3).
<DT id="18"><B>RES_ROTATE</B>
<DD>
Causes round-robin selection of name servers from among those listed.
This has the effect of spreading the query load among all listed servers,
rather than having all clients try the first listed server first every
time.
<DT id="19"><B>RES_NOCHECKNAME</B> (unimplemented; deprecated in glibc 2.25)
<DD>
Disable the modern BIND checking of incoming hostnames and mail names
for invalid characters such as underscore (_), non-ASCII,
or control characters.
This option was present in glibc until version 2.24;
since glibc 2.25, it is deprecated, and its usage produces a warning.
<DT id="20"><B>RES_KEEPTSIG</B> (unimplemented; deprecated in glibc 2.25)
<DD>
Do not strip TSIG records.
This option was present but unimplemented in glibc until version 2.24;
since glibc 2.25, it is deprecated, and its usage produces a warning.
<DT id="21"><B>RES_BLAST (unimplemented; deprecated in glibc 2.25)</B>
<DD>
Send each query simultaneously and recursively to all servers.
This option was present but unimplemented in glibc until version 2.24;
since glibc 2.25, it is deprecated, and its usage produces a warning.
<DT id="22"><B>RES_USEBSTRING</B> (glibc 2.3.4 to 2.24)
<DD>
Make reverse IPv6 lookups using the bit-label format described in RFC 2673;
if this option is not set (which is the default), then nibble format is used.
This option was removed in glibc 2.25,
since it relied on a backward-incompatible
DNS extension that was never deployed on the Internet.
<DT id="23"><B>RES_NOIP6DOTINT</B> (glibc 2.24 and earlier)
<DD>
Use
<I>ip6.arpa</I>
zone in IPv6 reverse lookup instead of
<I>ip6.int</I>,
which is deprecated since glibc 2.3.4.
This option is present in glibc up to and including version 2.24,
where it is enabled by default.
In glibc 2.25, this option was removed.
<DT id="24"><B>RES_USE_EDNS0</B> (since glibc 2.6)
<DD>
Enables support for the DNS extensions (EDNS0) described in RFC 2671.
<DT id="25"><B>RES_SNGLKUP</B> (since glibc 2.10)
<DD>
By default, glibc performs IPv4 and IPv6 lookups in parallel since
version 2.9.
Some appliance DNS servers cannot handle these queries properly
and make the requests time out.
This option disables the behavior and makes glibc
perform the IPv6 and IPv4 requests sequentially
(at the cost of some slowdown of the resolving process).
<DT id="26"><B>RES_SNGLKUPREOP</B>
<DD>
When
<B>RES_SNGLKUP</B>
option is enabled, opens a new socket for the each request.
<DT id="27"><B>RES_USE_DNSSEC</B>
<DD>
Use DNSSEC with OK bit in OPT record.
This option implies
<B>RES_USE_EDNS0</B>.
<DT id="28"><B>RES_NOTLDQUERY</B>
<DD>
Do not look up unqualified name as a top-level domain (TLD).
<DT id="29"><B>RES_DEFAULT</B>
<DD>
Default option which implies:
<B>RES_RECURSE</B>,
<B>RES_DEFNAMES</B>,
<B>RES_DNSRCH</B>
and
<B>RES_NOIP6DOTINT</B>.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>res_ninit</B>()
and
<B>res_init</B>()
functions return 0 on success, or -1 if an error
occurs.
<P>
The
<B>res_nquery</B>(),
<B>res_query</B>(),
<B>res_nsearch</B>(),
<B>res_search</B>(),
<B>res_nquerydomain</B>(),
<B>res_querydomain</B>(),
<B>res_nmkquery</B>(),
<B>res_mkquery</B>(),
<B>res_nsend</B>(),
and
<B>res_send</B>()
functions return the length
of the response, or -1 if an error occurs.
<P>
The
<B>dn_comp</B>()
and
<B>dn_expand</B>()
functions return the length
of the compressed name, or -1 if an error occurs.
<P>
In the case of an error return from
<B>res_nquery</B>(),
<B>res_query</B>(),
<B>res_nsearch</B>(),
<B>res_search</B>(),
<B>res_nquerydomain</B>(),
or
<B>res_querydomain</B>(),
the global variable
<I>h_errno</I>
(see
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3))
can be consulted to determine the cause of the error.
<A NAME="lbAG">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="30"><I>/etc/resolv.conf</I>
<DD>
resolver configuration file
<DT id="31"><I>/etc/host.conf</I>
<DD>
resolver configuration file
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>res_ninit</B>(),
<B>res_nclose</B>(),
<B>res_nquery</B>(),
<BR>
<B>res_nsearch</B>(),
<B>res_nquerydomain</B>(),
<B>res_nsend</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>res_nmkquery</B>(),
<B>dn_comp</B>(),
<BR>
<B>dn_expand</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
4.3BSD.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+resolv.conf">resolv.conf</A></B>(5),
<B><A HREF="/cgi-bin/man/man2html?5+resolver">resolver</A></B>(5),
<B><A HREF="/cgi-bin/man/man2html?7+hostname">hostname</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?8+named">named</A></B>(8)
<P>
The GNU C library source file
<I>resolv/README</I>.
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="32"><A HREF="#lbAB">NAME</A><DD>
<DT id="33"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DL>
<DT id="34"><A HREF="#lbAD">Deprecated</A><DD>
</DL>
<DT id="35"><A HREF="#lbAE">DESCRIPTION</A><DD>
<DT id="36"><A HREF="#lbAF">RETURN VALUE</A><DD>
<DT id="37"><A HREF="#lbAG">FILES</A><DD>
<DT id="38"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="39"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="40"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="41"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:54 GMT, March 31, 2021
</BODY>
</HTML>