[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Communications Programming Concepts

Domain Name Resolution

When a process receives a symbolic name and needs to resolve it into an address, it calls a resolver subroutine. The method used by the set of resolver subroutines to resolve names depends on the local host configuration. In addition, the organization of the network determines how a resolver subroutine communicates with remote name server hosts (the hosts that resolve names for other hosts).

A resolver subroutine determines which type of network it is dealing with by determining whether the /etc/resolv.conf file exists. If the file exists, a resolver subroutine assumes that the local network has a name server. Otherwise, it assumes that no name server is present.

To resolve a name with no name server present, a resolver subroutine checks the /etc/hosts file for an entry that maps the name to an address.

To resolve a name in a name server network, a resolver subroutine first queries the domain name server (DNS) database, which may be local host (if the host is a domain name server) or a foreign host. If the subroutine is using a remote name server, the subroutine uses the Domain Name Protocol (DOMAIN) to query for the mapping. If this query is unsuccessful, the subroutine then checks for an entry in the local /etc/hosts file.

The resolver subroutines are used to make, send, and interpret packets for name servers in the Internet domain. Together, the following resolver subroutines form the set of functions that resolve domain names:

Global information used by these resolver subroutines is kept in the _res structure. This structure is defined in the /usr/include/resolv.h file and contains the following members:

Member Contents
int Denotes the retrans field.
int Denotes the retry field.
long Denotes the options field.
int Denotes the nscount field.
struct Denotes the sockaddr_in and nsaddr_list [MAXNS] fields.
ushort Denotes the ID field.
char Denotes the defdname [MAXDNAME] field.
#define Denotes the nsaddr nsaddr_list [0] field.

The options field of the _res structure is constructed by logically ORing the following values:

RES_INIT Indicates whether the initial name server and default domain name have been initialized (that is, whether the res_init subroutine has been called).
RES_DEBUG Prints debugging messages.
RES_USEVC Uses Transmission Control Protocol/Internet Protocol (TCP/IP) connections for queries instead of User Datagram Protocol/Internet Protocol (UDP/IP).
RES_STAYOPEN Used with the RES_USEVC value, keeps the TCP/IP connection open between queries. Although UDP/IP is the mode normally used, TCP/IP mode and this option are useful for programs that regularly perform many queries.
RES_RECURSE Sets the Recursion Desired bit for queries. This is the default.
RES_DEFNAMES Appends the default domain name to single-label queries. This is the default.

Three environment variables affect values related to the _res structure:

LOCALDOMAIN Overrides the default local domain, which is read from the /etc/resolv.conf file and stored in the defdname field of the _res structure.
RES_TIMEOUT Overrides the default value of the retrans field of the _res structure, which is the value of the RES_TIMEOUT constant defined in the /usr/include/resolv.h file. This value is the base time-out period in seconds between queries to the name servers. After each failed attempt, the time-out period is doubled. The time-out period is divided by the number of name servers defined. The minimum time-out period is 1 second.
RES_RETRY Overrides the default value for the retry field of the _res structure, which is 4. This value is the number of times the resolver tries to query the name servers before giving up. Setting RES_RETRY to 0 prevents the resolver from querying the name servers.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]