res_init() — Domain name resolver initialization

Standards

Standards / Extensions C or C++ Dependencies

BSD 4.3

both OS/390 V2R8

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>

int res_init(void);
struct __res_state _res;

General description

The res_init() function is the Resolver function that initializes the __res_state structure for use by other Resolver functions. Initialization normally occurs on the first call to any of the IP address resolution routines commonly called the XL C/C++ Runtime Library Resolver.

The res_init() routine does its initialization by passing the __res_state structure to the CS for z/OS® Resolver. The Resolver reads the "TCPIP.DATA" configuration file and updates the __res_state structure. The data in the __res_state structure is filled in based on the contents of the "TCPIP.DATA" configuration file and can then be referenced in the _res variable. Global configuration and state information that is used by the Resolver routines is kept in the structure _res. Most of the values have reasonable defaults and can be left unchanged.
Value
Description
_res.retrans
Retransmission time interval is taken from the ResolverTimeOut statement found in the "TCPIP.DATA" configuration file.
_res.retry
The number of times to retransmit a request. It is taken from the ResolverUDPRetries statement found in the "TCPIP.DATA" configuration file.
_res.options
Options stored in _res.options are defined in <resolv.h> and are listed below. Options are stored as a simple bit mask containing the bitwise OR of the options enabled.
Option
Description
RES_INIT
True after the initial name server address and default domain name are initialized, because res_init() has been called. This option should only be tested but not set, except by the res_init() function.
RES_DEBUG
Print debugging messages.
RES_AAONLY
Accept authoritative answers only. With this option, res_send() should continue until it finds an authoritative answer or finds an error. Currently this is not implemented.
RES_USEVC
Use TCP connections for queries instead of UDP datagrams.
RES_STAYOPEN
Used with RES_USEVC to keep the TCP connection open between queries. This is useful only in programs that regularly do many queries. UDP should be the normal mode used.
RES_IGNTC
Ignore truncation errors, that is, don't retry with TCP. Currently unused.
RES_RECURSE
Set the recursion-desired bit in queries. This is the default. (res_send() does not do iterative queries and expects the name server to handle recursion.)
RES_DEFNAMES
If set, res_search() will append the default domain name to single-component names (those that do not contain a dot). This option is enabled by default.
RES_DNSRCH
If this option is set, res_search() will search for host names in the current domain and in parent domains. This is used by the standard host lookup routine gethostbyname(). This option is enabled by default.
RES_NOALIASES
This option turns off the user level aliasing feature controlled by the "HOSTALIASES" environment variable. Network daemons should set this option.
_res.nscount
The number of name servers specified in the "TCPIP.DATA" configuration file.
_res.*nsaddr_list[0]
The addresses of name servers specified by the NSINTERADDR or NameServer statements found in the "TCPIP.DATA" configuration file.
_res.dnsrch[0]
The beginning of the list of domains to be searched, as specified in the SEARCH statement found in the "TCPIP.DATA" configuration file. The structure will have either a Default DOMAIN or SEARCH.
_res.defdname[0]
The Default Domain name, as specified in the Domain or DomainOrigin statement found in the "TCPIP.DATA" configuration file. The structure will have either a Default DOMAIN or SEARCH.
_res.pfcode
Currently this is not implemented.
_res.ndots
The threshold for the number of dots in the domain name, as specified by the OPTIONS statement value ndots:n found in the "TCPIP.DATA" configuration file. The default is 1.
_res.nsort
The number of elements in sort_list[] as listed in the SORTLIST statement found in the "TCPIP.DATA" configuration file.
_res.sort_list[0]
The network address and subnet mask in the SORTLIST statement found in the "TCPIP.DATA" configuration file.

Returned value

If successful, res_init() returns 0.

If unsuccessful, res_init() returns -1 and sets h_errno to one of the following values:
Error Code
Description
NO_RECOVERY
An error occurred that will continue to fail if tried again. Storage could not be obtained for this thread to contain the _res structure.
TRY_AGAIN
An error occurred while initializing the __res_state structure name selected, which can be retried.

If successful, _res returns the address of __res_state structure.

If unsuccessful, _res returns NULL and sets errno to one of the following values:
Error Code
Description
ENOMEM
The storage needed to define the _res structure could not be obtained.

Related information