res_query Subroutine

Purpose

Provides an interface to the server query mechanism.

Library

Standard C Library (libc.a)

Syntax

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

int res_query (DomName, Class, Type, Answer, AnswerLength)
char * DomName;
int  Class;
int  Type;
u_char * Answer;
int  AnswerLength;

Description

The res_query subroutine provides an interface to the server query mechanism. It constructs a query, sends it to the local server, awaits a response, and makes preliminary checks on the reply. The query requests information of the specified type and class for the fully-qualified domain name specified in the DomName parameter. The reply message is left in the answer buffer whose size is specified by the AnswerLength parameter, which is supplied by the caller.

The res_query subroutine is one of a set of subroutines that form the resolver, a set of functions that resolve domain names. The _res data structure contains global information used by the resolver subroutines. The /usr/include/resolv.h file contains the _res structure definition.

All applications containing the res_query subroutine must be compiled with the _BSD macro set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Parameters

Item Description
DomName Points to the name of the domain. If the DomName parameter points to a single-component name and the RES_DEFNAMES structure is set, as it is by default, the subroutine appends the default domain name to the single-component name. The current domain name is defined by the name server in use or is specified in the /etc/resolv.conf file.
Class Specifies one of the following values:
C_IN
Specifies the ARPA Internet.
C_CHAOS
Specifies the Chaos network at MIT.
Type Requires one of the following values:
T_A
Host address
T_NS
Authoritative server
T_MD
Mail destination
T_MF
Mail forwarder
T_CNAME
Canonical name
T_SOA
Start-of-authority zone
T_MB
Mailbox-domain name
T_MG
Mail-group member
T_MR
Mail-rename name
T_NULL
Null resource record
T_WKS
Well-known service
T_PTR
Domain name pointer
T_HINFO
Host information
T_MINFO
Mailbox information
T_MX
Mail-routing information
T_UINFO
User (finger command) information
T_UID
User ID
T_GID
Group ID
Answer Points to an address where the response is stored.
AnswerLength Specifies the size of the answer buffer.

Return Values

Upon successful completion, the res_query subroutine returns the size of the response. Upon unsuccessful completion, the res_query subroutine returns a value of -1 and sets the h_errno value to the appropriate error.

Files

Item Description
/etc/resolv.conf                          Contains the name server and domain name.