'\"macro stdmacro
.if n .pH g3n.resolver @(#)resolver	40.4 of 10/10/89
.\" Copyright 1989 AT&T
.\" Copyright (c) 1985 Regents of the University of California.
.\" All rights reserved.  The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\"	@(#)resolver.3 1.12 88/10/18 SMI; from UCB 1.5 3/21/86
'\" macro stdmacro
.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
.\"
.\"
.nr X
.if \nX=0 .ds x} resolver 3N "TCP/IP" "\&"
.if \nX=1 .ds x} resolver 3N "TCP/IP"
.if \nX=2 .ds x} resolver 3N "" "\&"
.if \nX=3 .ds x} resolver "" "" "\&"
.TH \*(x}
.SH NAME
\f4resolver\f1, \f4res_mkquery\f1, \f4res_send\f1, \f4res_init\f1, \f4dn_comp\f1, \f4dn_expand\f1 \- resolver routines
.SH SYNOPSIS
.nf
.ft 4
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
.ft 1
.PP
.ft 4
res_mkquery(op, dname, class, type, data, datalen, newrr, buf, buflen)
int op;
char *dname;
int class, type;
char *data;
int datalen;
struct rrec *newrr;
char *buf;
int buflen;
.ft 1
.PP
.ft 4
res_send(msg, msglen, answer, anslen)
char *msg;
int msglen;
char *answer;
int anslen;
.ft 1
.PP
.ft 4
res_init
.ft 1
.PP
.ft 4
dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
char *exp_dn, *comp_dn;
int length;
char **dnptrs, **lastdnptr;
.ft 1
.PP
.ft 4
dn_expand(msg, msglen, comp_dn, exp_dn, length)
char *msg, *comp_dn, exp_dn;
int  msglen, length;
.fi
.ft 1
.SH DESCRIPTION
.PP
These routines are used for making,
sending and interpreting packets to
Internet domain name servers.
Global information that is used by the
resolver routines is kept in the variable
\f4_res\fP.
Most of the values have reasonable defaults
and can be ignored.
Options are a simple bit mask and are
.SM OR\s0'ed
in to enable.
Options stored in
\f4_res.options\fP
are defined in
\f4/usr/include/resolv.h\f1
and are as follows.
.TP 20
\f4RES_INIT\fP
True if the initial name server address
and default domain name are initialized (that is,
\f4res_init \f1
has been called).
.TP
\f4RES_DEBUG\fP
Print debugging messages.
.TP
\f4RES_AAONLY\fP
Accept authoritative answers only.
\f4res_send\f1
will continue until it finds an authoritative
answer or finds an error.
Currently this is not implemented.
.TP
\f4RES_USEVC\fP
Use
.SM TCP
connections for queries instead of
.SM UDP\s0.
.TP
\f4RES_STAYOPEN\fP
Used with
\f4RES_USEVC\fP
to keep the
.SM TCP
connection open between queries.
This is useful only in programs that
regularly do many queries.
.SM UDP
should be the normal mode used.
.TP
\f4RES_IGNTC\fP
Unused currently (ignore truncation errors,
that is, do not retry with
.SM TCP\s0).
.TP
\f4RES_RECURSE\fP
Set the recursion desired bit in queries.
This is the default.
\f4res_send\f1
does not do iterative queries and expects the name server
to handle recursion.
.TP
\f4RES_DEFNAMES\fP
Append the default domain name to single
label queries.
This is the default.
.PP
\f4res_init\f1
reads the initialization file to get the default
domain name and the Internet address of the initial hosts
running the name server.
If this line does
not exist, the host running the resolver is tried.
\f4res_mkquery\f1
makes a standard query message and places it in
.IR buf .
\f4res_mkquery\f1
will return the size of the query or \-1 if the query is
larger than
.IR buflen .
.I op
is usually
\f4QUERY\fP
but can be any of the query types defined in
\f4/usr/include/arpa/nameser.h\f1.
.I dname
is the domain name.
If
.I dname
consists of a single label and the
\f4RES_DEFNAMES\fP
flag is enabled (the default),
.I dname
will be appended with the current domain name.
The current domain name is defined in a system
file and can be overridden by the environment variable
\f4LOCALDOMAIN\f1.
.I newrr
is currently unused but is intended for making update messages.
.PP
\f4res_send\f1
sends a query to name servers and returns an answer.
It will call
\f4res_init\f1
if
\f4RES_INIT\fP
is not set, send the query to the local
name server, and handle timeouts and retries.
The length of the message is returned or
\-1 if there were errors.
.PP
\f4dn_expand\f1
expands the compressed domain name
.I comp_dn
to a full domain name.
Expanded names are converted to upper case.
.I msg
is a pointer to the beginning of the message,
.I exp_dn
is a pointer to a buffer of size
.I length
for the result.
The size of compressed
name is returned or \-1 if there was an error.
.PP
\f4dn_comp\f1
compresses the domain name
.I exp_dn
and stores it in
.IR comp_dn .
The size of the compressed name is returned or \-1
if there were errors.
.I length
is the size of the array pointed to by
.IR comp_dn .
.I dnptrs
is a list of pointers to previously compressed
names in the current message.
The first pointer
points to to the beginning of the message
and the list ends with
\f4NULL\fP.
.I lastdnptr
is a pointer to the end of the array pointed to
.IR dnptrs .
A side effect is to update the list of pointers for
labels inserted into the message by
\f4dn_comp\f1
as the name is compressed.
If
.I dnptr
is
\f4NULL\fP,
do not try to compress names.
If
.I lastdnptr
is
\f4NULL\fP,
do not update the list.
.SH FILES
.PD 0
.TP 20
\f4/usr/include/arpa/nameserv.h\f1
.TP
\f4/usr/include/netinet/in.h\f1
.TP
\f4/usr/include/resolv.h\f1
.TP
\f4/usr/include/sys/types.h\f1
.TP
\f4/etc/resolv.conf\f1
.TP
\f4/usr/lib/libresolv.a\f1
.PD
.SH "SEE ALSO"
\f4named\fP(1M),
\f4resolv.conf\fP(4).
.SH NOTES
\f4/usr/lib/libresolv.a\f1
is necessary for compiling programs.
.LP
Programs must be loaded with the option
\f4\-lresolv\f1.
