resolver(3)
๐ธ NAME ๐ธ
okay bestie, this is the resolver(3) manual page โ Library Functions Manual energy โ and it's literally the whole resolver routine friend group:
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
โจ LIBRARY โจ
Resolver library (libresolv, -lresolv)
๐ SYNOPSIS ๐
here's the exact code vibe, no cap โ includes first, then the typedefs and every single function declaration:
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
struct __res_state;
typedef struct __res_state *res_state;
int res_ninit(res_state statep);
void res_nclose(res_state statep);
int res_nquery(int anslen;
res_state statep,
const char *dname,
int class, int type,
unsigned char answer[anslen], int anslen);
int res_nsearch(int anslen;
res_state statep,
const char *dname,
int class, int type,
unsigned char answer[anslen], int anslen);
int res_nquerydomain(int anslen;
res_state statep,
const char *name, const char *domain,
int class, int type,
unsigned char answer[anslen], int anslen);
int res_nmkquery(int datalen, int buflen;
res_state statep, int op,
const char *dname,
int class, int type,
const unsigned char data[datalen], int datalen,
const unsigned char *newrr,
unsigned char buf[buflen], int buflen);
int res_nsend(int msglen, int anslen;
res_state statep,
const unsigned char msg[msglen], int msglen,
unsigned char answer[anslen], int anslen);
int dn_comp(int length;
const char *exp_dn,
unsigned char comp_dn[length], int length,
unsigned char **dnptrs,
unsigned char **lastdnptr);
int dn_expand(int length;
const unsigned char *msg,
const unsigned char *eomorig,
const unsigned char *comp_dn,
char exp_dn[length], int length);
[[deprecated]] extern struct __res_state _res;
[[deprecated]] int res_init(void);
[[deprecated]]
int res_query(int anslen;
const char *dname,
int class, int type,
unsigned char answer[anslen], int anslen);
[[deprecated]]
int res_search(int anslen;
const char *dname,
int class, int type,
unsigned char answer[anslen], int anslen);
[[deprecated]]
int res_querydomain(int anslen;
const char *name, const char *domain,
int class, int type,
unsigned char answer[anslen], int anslen);
[[deprecated]]
int res_mkquery(int datalen, int buflen;
int op,
const char *dname,
int class, int type,
const unsigned char data[datalen], int datalen,
const unsigned char *newrr,
unsigned char buf[buflen], int buflen);
[[deprecated]]
int res_send(int msglen, int anslen;
const unsigned char msg[msglen], int msglen,
unsigned char answer[anslen], int anslen);
๐ DESCRIPTION ๐
Heads up bestie: this page is incomplete (like, a bunch of resolver functions that glibc gives you just... aren't described here, rude) and it's likely out of date. Fr fr.
So, the functions described below make queries to Internet domain name servers and interpret the responses that come back.
The API is basically two eras of the same vibe. There's a set of more modern, reentrant functions, and then an older set of nonreentrant functions that have been superseded. The traditional resolver interfaces like res_init() and res_query() use some static (global) state stored in the _res structure, which makes them not thread-safe โ that's the whole problem, bestie. Then BIND 8.2 showed up and introduced a new set of interfaces โ res_ninit(), res_nquery(), and so on โ which take a res_state as their first argument, so you can have a per-thread resolver state. Slay. ๐
The res_ninit() and res_init() functions read the configuration files (peep resolv.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, the one associated with the local host is used. You can override it with the environment variable LOCALDOMAIN. res_ninit() or res_init() is normally executed by the first call to one of the other functions. โญ
๐ซถ Important, bestie: every call tores_ninit()requires a corresponding call tores_nclose()to free the memory allocated byres_ninit()and subsequent calls tores_nquery(). Don't leak, that's not the vibe.
The res_nquery() and res_query() functions query the name server for the fully qualified domain name name of the specified type and class. The reply is left in the buffer answer of length anslen supplied by the caller.
The res_nsearch() and res_search() functions make a query and wait for the response just like res_nquery() and res_query() โ but in addition, they implement the default and search rules controlled by RES_DEFNAMES and RES_DNSRCH (the _res options below explain that whole thing).
The res_nquerydomain() and res_querydomain() functions make a query using res_nquery()/res_query() on the concatenation of name and domain. Iconic combo move. โจ
The following functions are the lower-level routines used by res_nquery()/res_query().
The res_nmkquery() and res_mkquery() functions construct a query message in buf of length buflen for the domain name dname. The query type op is one of the following (typically QUERY):
QUERYโ Standard query. Ngl, the usual one.IQUERYโ Inverse 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. It's just... there. ๐
The res_nsend() and res_send() function send a preformatted query given in msg of length msglen and returns the answer in answer, which is of length anslen. They will call res_ninit()/res_init() if it has not already been called.
The dn_comp() function compresses the domain name exp_dn and stores it in the buffer comp_dn of length length. The compression uses an array of pointers dnptrs 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 lastdnptr. If dnptr is NULL, domain names are not compressed. If lastdnptr is NULL, the list of labels is not updated.
The dn_expand() function expands the compressed domain name comp_dn to a full domain name, which is placed in the buffer exp_dn of size length. The compressed name is contained in a query or reply message, and msg points to the beginning of the message.
The resolver routines use configuration and state information contained in a __res_state structure (either passed as the statep 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 the options 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 use theRES_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 use theRES_DEBUGoption (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 inRFC 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.arpazone 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 inRFC 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.
๐ RETURN VALUE ๐
- The
res_ninit()andres_init()functions return0on success, or-1if an error occurs. - The
res_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-1if an error occurs. - The
dn_comp()anddn_expand()functions return the length of the compressed name, or-1if an error occurs.
In the case of an error return from res_nquery(), res_query(), res_nsearch(), res_search(), res_nquerydomain(), or res_querydomain(), the global variable h_errno (peep gethostbyname(3)) can be consulted to determine the error. ๐
๐ FILES ๐
/etc/resolv.confโ resolver configuration file/etc/host.confโ resolver configuration file
โจ ATTRIBUTES โจ
Ok bestie, this is the part where we talk about who can run this at the same time as who ๐
and literally all the deets on the terminology live in attributes(7), so go peek there if you want the full lore ๐ซถ
So here's the tea, group-chat style, one bullet per interface:
res_ninit(),res_nclose(),res_nquery(),res_nsearch(),res_nquerydomain(),res_nsend()โ Thread safety: MT-Safe locale ๐ธres_nmkquery(),dn_comp(),dn_expand()โ Thread safety: MT-Safe โจ
Translation for the besties: those first six are safe to call from multiple threads but only if you're chill about the locale not changing underneath you (that's the locale part, iykyk ๐). The last three? Fully MT-Safe, no strings attached, no notes. ๐
๐ STANDARDS ๐
None.
Not "none that apply", not "see elsewhere" โ literally none. It's giving โจ unstandardised โจ, it's giving "we made this up and it worked", and honestly? Respect. ๐
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
Drop the date bestie, we're going back: this whole thing shows up in 4.3BSD ๐ฆ
That's it. That's the origin story. Ancient. Iconic. Older than your fave. 4.3BSD walked so your DNS lookups could run, fr fr. ๐
๐ SEE ALSO ๐
Go read these next, they're all part of the same little friend group ๐:
And one more, straight from the source โ the GNU C library source file resolv/README ๐ (yes, actually read it, it's lowkey good).
Okay that's the whole page, you made it to the end, I'm so proud of you ๐ฅน๐ซถ
Shoutout to Linux man-pages 6.20, dated 2026-02-08, and this page is resolver(3) ๐ธ slay, go touch grass, and remember: MT-Safe locale is not the same as MT-Safe. Periodt. ๐
โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- Copyright 2015, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms