NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |FILES |ATTRIBUTES |STANDARDS |HISTORY |SEE ALSO |COLOPHON | |
resolver(3) Library Functions Manualresolver(3)res_ninit, res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend, res_nclose, res_init, res_query, res_search, res_querydomain, res_mkquery, res_send, dn_comp, dn_expand - resolver routines
Resolver library (libresolv,-lresolv)
#include <netinet/in.h>#include <arpa/nameser.h>#include <resolv.h>struct __res_state;typedef struct __res_state *res_state;int res_ninit(res_statestatep);void res_nclose(res_statestatep);int res_nquery(int anslen;res_statestatep,const char *dname, intclass, inttype,unsigned charanswer[anslen], intanslen);int res_nsearch(int anslen;res_statestatep,const char *dname, intclass, inttype,unsigned charanswer[anslen], intanslen);int res_nquerydomain(int anslen;res_statestatep,const char *name, const char *domain,intclass, inttype, unsigned charanswer[anslen],intanslen);int res_nmkquery(int datalen, int buflen;res_statestatep,intop, const char *dname, intclass,inttype, const unsigned chardata[datalen], intdatalen,const unsigned char *newrr,unsigned charbuf[buflen], intbuflen);int res_nsend(int msglen, int anslen;res_statestatep,const unsigned charmsg[msglen], intmsglen,unsigned charanswer[anslen], intanslen);int dn_comp(int length;const char *exp_dn, unsigned charcomp_dn[length],intlength, unsigned char **dnptrs,unsigned char **lastdnptr);int dn_expand(int length;const unsigned char *msg,const unsigned char *eomorig,const unsigned char *comp_dn, charexp_dn[length],intlength);[[deprecated]] extern struct __res_state _res;[[deprecated]] int res_init(void);[[deprecated]]int res_query(int anslen;const char *dname, intclass, inttype,unsigned charanswer[anslen], intanslen);[[deprecated]]int res_search(int anslen;const char *dname, intclass, inttype,unsigned charanswer[anslen], intanslen);[[deprecated]]int res_querydomain(int anslen;const char *name, const char *domain,intclass, inttype, unsigned charanswer[anslen],intanslen);[[deprecated]]int res_mkquery(int datalen, int buflen;intop, const char *dname, intclass,inttype, const unsigned chardata[datalen], intdatalen,const unsigned char *newrr,unsigned charbuf[buflen], intbuflen);[[deprecated]]int res_send(int msglen, int anslen;const unsigned charmsg[msglen], intmsglen,unsigned charanswer[anslen], intanslen);
Note:This page is incomplete (various resolver functions provided by glibc are not described) and likely out of date. The functions described below make queries to and interpret the responses from Internet domain name servers. 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 asres_init() andres_query() use some static (global) state stored in the_res structure, rendering these functions non-thread-safe. BIND 8.2 introduced a set of new interfacesres_ninit(),res_nquery(), and so on, which take ares_state as their first argument, so you can use a per-thread resolver state. Theres_ninit() andres_init() functions read the configuration files (seeresolv.conf(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 variableLOCALDOMAIN.res_ninit() orres_init() is normally executed by the first call to one of the other functions. Every call tores_ninit() requires a corresponding call tores_nclose() to free memory allocated byres_ninit() and subsequent calls tores_nquery(). Theres_nquery() andres_query() functions query the name server for the fully qualified domain namename of specifiedtype andclass. The reply is left in the bufferanswer of lengthanslen supplied by the caller. Theres_nsearch() andres_search() functions make a query and waits for the response likeres_nquery() andres_query(), but in addition they implement the default and search rules controlled byRES_DEFNAMESandRES_DNSRCH(see description of_res options below). Theres_nquerydomain() andres_querydomain() functions make a query usingres_nquery()/res_query() on the concatenation ofname anddomain. The following functions are lower-level routines used byres_nquery()/res_query(). Theres_nmkquery() andres_mkquery() functions construct a query message inbuf of lengthbuflen for the domain namedname. The query typeop is one of the following (typicallyQUERY):QUERYStandard query.IQUERYInverse query. This option was removed in glibc 2.26, since it has not been supported by DNS servers for a very long time.NS_NOTIFY_OP Notify secondary of SOA (Start of Authority) change.newrr is currently unused. Theres_nsend() andres_send() function send a preformatted query given inmsg of lengthmsglen and returns the answer inanswer which is of lengthanslen. They will callres_ninit()/res_init() if it has not already been called. Thedn_comp() function compresses the domain nameexp_dn and stores it in the buffercomp_dn of lengthlength. The compression uses an array of pointersdnptrs 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 bylastdnptr. Ifdnptr is NULL, domain names are not compressed. Iflastdnptr is NULL, the list of labels is not updated. Thedn_expand() function expands the compressed domain namecomp_dn to a full domain name, which is placed in the bufferexp_dn of sizelength. The compressed name is contained in a query or reply message, andmsg points to the beginning of the message. The resolver routines use configuration and state information contained in a__res_state structure (either passed as thestatep argument, or in the global variable_res, in the case of the older nonreentrant functions). The only field of this structure that is normally manipulated by the user is theoptions field. This field can contain the bitwise "OR" of the following options:RES_INIT True ifres_ninit() orres_init() has been called.RES_DEBUG Print debugging messages. This option is available only if glibc was built with debugging enabled, which is not the default.RES_AAONLY(unimplemented; deprecated in glibc 2.25) Accept authoritative answers only.res_send() continues until it finds an authoritative answer or returns an error. This option was present but unimplemented until glibc 2.24; since glibc 2.25, it is deprecated, and its usage produces a warning.RES_USEVC Use TCP connections for queries rather than UDP datagrams.RES_PRIMARY(unimplemented; deprecated in glibc 2.25) Query primary domain name server only. This option was present but unimplemented until glibc 2.24; since glibc 2.25, it is deprecated, and its usage produces a warning.RES_IGNTC Ignore truncation errors. Don't retry with TCP.RES_RECURSE Set the recursion desired bit in queries. Recursion is carried out by the domain name server, not byres_send(). [Enabled by default].RES_DEFNAMES If set,res_search() will append the default domain name to single component names—that is, those that do not contain a dot. [Enabled by default].RES_STAYOPEN Used withRES_USEVCto keep the TCP connection open between queries.RES_DNSRCH If set,res_search() will search for hostnames in the current domain and in parent domains. This option is used bygethostbyname(3). [Enabled by default].RES_INSECURE1 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 useRES_DEBUGoption (for debug purpose only).RES_INSECURE2 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 useRES_DEBUG option (for debug purpose only).RES_NOALIASES Disable usage ofHOSTALIASESenvironment variable.RES_USE_INET6 Try an AAAA query before an A query inside thegethostbyname(3) function, and map IPv4 responses in IPv6 "tunneled form" 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 usegetaddrinfo(3), rather thangethostbyname(3).RES_ROTATE 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.RES_NOCHECKNAME(unimplemented; deprecated in glibc 2.25) 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 until glibc 2.24; since glibc 2.25, it is deprecated, and its usage produces a warning.RES_KEEPTSIG(unimplemented; deprecated in glibc 2.25) Do not strip TSIG records. This option was present but unimplemented until glibc 2.24; since glibc 2.25, it is deprecated, and its usage produces a warning.RES_BLAST(unimplemented; deprecated in glibc 2.25) Send each query simultaneously and recursively to all servers. This option was present but unimplemented until glibc 2.24; since glibc 2.25, it is deprecated, and its usage produces a warning.RES_USEBSTRING(glibc 2.3.4 to glibc 2.24) 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.RES_NOIP6DOTINT(glibc 2.24 and earlier) Useip6.arpa zone in IPv6 reverse lookup instead ofip6.int, which is deprecated since glibc 2.3.4. This option is present up to and including glibc 2.24, where it is enabled by default. In glibc 2.25, this option was removed.RES_USE_EDNS0(since glibc 2.6) Enables support for the DNS extensions (EDNS0) described in RFC 2671.RES_SNGLKUP(since glibc 2.10) By default, glibc performs IPv4 and IPv6 lookups in parallel since glibc 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).RES_SNGLKUPREOP WhenRES_SNGLKUPoption is enabled, opens a new socket for the each request.RES_USE_DNSSEC Use DNSSEC with OK bit in OPT record. This option impliesRES_USE_EDNS0.RES_NOTLDQUERY Do not look up unqualified name as a top-level domain (TLD).RES_DEFAULT Default option which implies:RES_RECURSE,RES_DEFNAMES,RES_DNSRCH, andRES_NOIP6DOTINT.
Theres_ninit() andres_init() functions return 0 on success, or -1 if an error occurs. Theres_nquery(),res_query(),res_nsearch(),res_search(),res_nquerydomain(),res_querydomain(),res_nmkquery(),res_mkquery(),res_nsend(), andres_send() functions return the length of the response, or -1 if an error occurs. Thedn_comp() anddn_expand() functions return the length of the compressed name, or -1 if an error occurs. In the case of an error return fromres_nquery(),res_query(),res_nsearch(),res_search(),res_nquerydomain(), orres_querydomain(), the global variableh_errno (seegethostbyname(3)) can be consulted to determine the error.
/etc/resolv.conf resolver configuration file/etc/host.conf resolver configuration file
For an explanation of the terms used in this section, seeattributes(7). ┌───────────────────────────────┬───────────────┬────────────────┐ │Interface│Attribute│Value│ ├───────────────────────────────┼───────────────┼────────────────┤ │res_ninit(),res_nclose(), │ Thread safety │ MT-Safe locale │ │res_nquery(),res_nsearch(), │ │ │ │res_nquerydomain(), │ │ │ │res_nsend() │ │ │ ├───────────────────────────────┼───────────────┼────────────────┤ │res_nmkquery(),dn_comp(), │ Thread safety │ MT-Safe │ │dn_expand() │ │ │ └───────────────────────────────┴───────────────┴────────────────┘
None.
4.3BSD.
gethostbyname(3),resolv.conf(5),resolver(5),hostname(7),named(8) The GNU C library source fileresolv/README.
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-06-28resolver(3)Pages that refer to this page:hostname(1), pmdanetcheck(1), gethostbyname(3), hosts(5), resolv.conf(5)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |