res_send, dn_comp, dn_expand - resolver routines
extern struct state _res;
int res_query(const char *dname, int class, int type,
unsigned char *answer, int anslen);
int res_search(const char *dname, int class, int type,
unsigned char *answer, int anslen);
int res_querydomain(const char *name, const char *domain,
int class, int type, unsigned char *answer,
int res_mkquery(int op, const char *dname, int class,
int type, char *data, int datalen, struct rrec *newrr,
char *buf, int buflen);
int res_send(const char *msg, int msglen, char *answer,
int dn_comp(unsigned char *exp_dn, unsigned char *comp_dn,
int length, unsigned char **dnptrs, unsigned char **lastdnptr);
int dn_expand(unsigned char *msg, unsigned char *eomorig,
unsigned char *comp_dn, char *exp_dn,
Link with -lresolv.
These functions make queries to and interpret the responses from Inter-
net domain name servers.
The res_init() function reads the configuration files (see
resolv.conf(5)) to get the default domain name, search order 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 LOCALDOMAIN.
res_init() is normally executed by the first call to one of the other
The res_query() function queries the name server for the fully quali-
fied domain name name of specified type and class. The reply is left
in the buffer answer of length anslen supplied by the caller.
The res_search() function makes a query and waits for the response like
res_query(), but in addition implements the default and search rules
The res_send() function sends a preformatted query given in msg of
length msglen and returns the answer in answer which is of length
anslen. It will call 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 mes-
sage. 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 global configuration and state information
contained in the structure _res, which is defined in <resolv.h>. The
only field that is normally manipulated by the user is _res.options.
This field can contain the bitwise "OR" of the following options:
True if res_init() has been called.
Print debugging messages. This option is available only if
glibc was built with debugging enabled, which is not the
Accept authoritative answers only. res_send() continues until
it finds an authoritative answer or returns an error. [Not cur-
Use TCP connections for queries rather than UDP datagrams.
Query primary domain name server only.
Ignore truncation errors. Don't retry with TCP. [Not currently
Set the recursion desired bit in queries. Recursion is carried
out by the domain name server, not by res_send(). [Enabled by
If set, res_search() will append the default domain name to sin-
gle component names, i.e., those that do not contain a dot.
The res_init() function returns 0 on success, or -1 if an error occurs.
The res_query(), res_search(), res_querydomain(), res_mkquery() and
res_send() functions return the length of the response, or -1 if an
The dn_comp() and dn_expand() functions return the length of the com-
pressed name, or -1 if an error occurs.
/etc/resolv.conf resolver configuration file
/etc/host.conf resolver configuration file
gethostbyname(3), resolv.conf(5), resolver(5), hostname(7), named(8)
This page is part of release 3.54 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2013-03-05 RESOLVER(3)
Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2018
All Rights Reserved.