res_ninit,  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


   #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);

   int res_nquery(res_state statep,
              const char *dname, int class, int type,
              unsigned char *answer, int anslen);

   int res_nsearch(res_state statep,
              const char *dname, int class, int type,
              unsigned char *answer, int anslen);

   int res_nquerydomain(res_state statep,
              const char *name, const char *domain,
              int class, int type, unsigned char *answer,
              int anslen);

   int res_nmkquery(res_state statep,
              int op, const char *dname, int class,
              int type, const unsigned char *data, int datalen,
              const unsigned char *newrr,
              unsigned char *buf, int buflen);

   int res_nsend(res_state statep,
              const unsigned char *msg, int msglen,
              unsigned char *answer, int anslen);

   int dn_comp(const char *exp_dn, unsigned char *comp_dn,
              int length, unsigned char **dnptrs,
              unsigned char **lastdnptr);

   int dn_expand(const unsigned char *msg,
              const unsigned char *eomorig,
              const unsigned char *comp_dn, char *exp_dn,
              int length);

   extern struct __res_state _res;

   int res_init(void);

   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 anslen);

   int res_mkquery(int op, const char *dname, int class,
              int type, const unsigned char *data, int datalen,
              const unsigned char *newrr,
              unsigned char *buf, int buflen);

   int res_send(const unsigned char *msg, int msglen,
              unsigned char *answer, int anslen);

   Link with -lresolv.


   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 as res_init() and res_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
   interfaces res_ninit(), res_nquery(), and so on, which take a res_state
   as their first argument, so you can use a per-thread resolver state.

   The  res_ninit()  and res_init() functions read the configuration files
   (see 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, that associated with the local host is used.   It  can
   be  overridden  with the environment variable LOCALDOMAIN.  res_ninit()
   or res_init() is normally executed by the first  call  to  one  of  the
   other functions.

   The  res_nquery()  and  res_query() functions query the name server for
   the fully qualified domain name name of specified type and class.   The
   reply  is  left  in  the buffer answer of length anslen supplied by the

   The res_nsearch() and res_search() functions make a query and waits for
   the  response  like  res_nquery() and res_query(), but in addition they
   implement the default and search rules controlled by  RES_DEFNAMES  and
   RES_DNSRCH (see description of _res options below).

   The  res_nquerydomain()  and  res_querydomain()  functions make a query
   using res_nquery()/res_query() on the concatenation of name and domain.

   The   following   functions   are   lower-level   routines   used    by

   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  usually  QUERY,  but  can  be any of the types defined in
   <arpa/nameser.h>.  newrr is currently unused.

   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:

          True if res_ninit() or 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
          currently implemented].

          Use TCP connections for queries rather than UDP datagrams.

          Query   primary   domain   name  server  only.   [Not  currently

          Ignore truncation errors.  Don't retry with TCP.

          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
          single component names---that is, those that do not contain a dot.
          [Enabled by default].

          Used with RES_USEVC to keep  the  TCP  connection  open  between

          If  set,  res_search()  will search for hostnames in the current
          domain  and  in  parent  domains.   This  option  is   used   by
          gethostbyname(3).  [Enabled by default].

          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  RES_DEBUG  option (for debug
          purpose only).

          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  RES_DEBUG  option
          (for debug purpose only).

          Disable usage of HOSTALIASES environment variable.

          Try  an AAAA query before an A query inside the gethostbyname(3)
          function, and map IPv4 responses in IPv6 "tunneled form"  if  no
          AAAA records are found but an A record set exists.

          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.

          Disable the modern BIND checking of incoming hostnames and  mail
          names  for invalid characters such as underscore (_), non-ASCII,
          or control characters.  [Not currently implemented].

          Do not strip TSIG records.  [Not currently implemented].

          Send each query simultaneously and recursively to  all  servers.
          Note this option overrides RES_ROTATE.

   RES_USEBSTRING (since glibc 2.3.4)
          Make  reverse  IPv6 lookups using the bit-label format described
          in RFC 2673; if this option is not set, then  nibble  format  is

          Use  zone  in  IPv6 reverse lookup instead of,
          which is deprecated since glibc 2.3.4.  [Enabled by default].

   RES_USE_EDNS0 (since glibc 2.6)
          Enables support for the DNS extensions (EDNS0) described in  RFC

   RES_SNGLKUP (since glibc 2.10)
          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).

          When RES_SNGLKUP option is enabled, opens a new socket  for  the
          each request.

          Use  DNSSEC  with  OK  bit  in  OPT record.  This option implies

          Do not look up unqualified name as a top-level domain (TLD).

          Default  option  which   implies:   RES_RECURSE,   RES_DEFNAMES,


   The  res_ninit() and res_init() functions return 0 on success, or -1 if
   an error occurs.

   The    res_nquery(),    res_query(),    res_nsearch(),    res_search(),
   res_nquerydomain(),  res_querydomain(),  res_nmkquery(), res_mkquery(),
   res_nsend(),  and  res_send()  functions  return  the  length  of   the
   response, or -1 if an error occurs.

   The  dn_comp()  and  dn_expand()  functions  return  the  length of the
   compressed name, or -1 if an error occurs.


   /etc/resolv.conf          resolver configuration file
   /etc/host.conf            resolver configuration file


   For  an  explanation  of  the  terms  used   in   this   section,   see

   Interface                           Attribute      Value          
   res_ninit(), res_nquery(),          Thread safety  MT-Safe locale 
   res_nsearch(), res_nquerydomain(),                                
   res_nmkquery(), dn_comp(),          Thread safety  MT-Safe        




   gethostbyname(3), resolv.conf(5), resolver(5), hostname(7), named(8)

   The GNU C library source file resolv/README.


   This page is part of release 4.09 of the Linux  man-pages  project.   A
   description  of  the project, information about reporting bugs, and the
   latest    version    of    this    page,    can     be     found     at


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.