Portions Copyright 1989 AT&T Portions Copyright (c) 1985, 1995 Regents of the University of California.
Copyright (C) 2006, Sun Microsystems, Inc. All Rights Reserved
BIND 8.2.2 Interfaces
cc [ flag ... ] file ... -lresolv -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> #include <netdb.h> int res_ninit(res_state statp);
void res_ndestroy(res_state statp);
void fp_resstat(const res_state statp, FILE *fp);
const char *res_hostalias(const res_state statp, const char *name, char * name, char *buf, size_tbuflen);
int res_nquery(res_state statp, const char *dname, int class, int type, u_char *answer, int datalen, int anslen);
int res_nsearch(res_state statp, const char *dname, int class, int type, u_char *answer, int anslen);
int res_nquerydomain(res_state statp, const char *name, const char *domain, int class, int type, u_char *answer, int anslen);
int res_nmkquery(res_state statp, int op, const char *dname, int class, int type, u_char *answer, int datalen, int anslen);
int res_nsend(res_state statp, const u_char *msg, int msglen, u_char *answer, int anslen);
void res_nclose(res_state statp);
int res_snendsigned(res_state statp, const u_char *msg, int msglen, ns_tsig_key *key, u_char *answer, int anslen);
int dn_comp(const char *exp_dn, u_char *comp_dn, int length, u_char **dnptrs, **lastdnptr);
int dn_expand(const u_char *msg, *eomorig, *comp_dn, char *exp_dn, int length);
const char *hstrerror(int err);
void res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt);
int res_getservers(res_state statp, union res_sockaddr_union *set, int cnt);
Deprecated Interfaces
cc [ flag ... ] file ... -lresolv -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> #include <netdb.h> int res_init(void)
int res_query(const char *dname, int class, int type, u_char *answer, int anslen);
int res_search(const char *dname, int class, int type, u_char *answer, int anslen);
int res_mkquery(int op, const char *dname, int class, int type, const char *data,int datalen, struct rrec *newrr, u_char *buf, int buflen);
int res_send(const u_char *msg, int msglen, u_char *answer, int anslen);
void herror(const char *s);
State information is kept in statp and is used to control the behavior of these functions. Set statp to all zeros prior to making the first call to any of these functions.
The res_ndestroy() function should be called to free memory allocated by res_ninit() after the last use of statp.
The functions res_init(), res_query(), res_search(), res_mkquery(), res_send(), and herror() are deprecated. They are supplied for backwards compatibility. They use global configuration and state information that is kept in the structure _res rather than state information referenced through statp.
Most of the values in statp and _res are initialized to reasonable defaults on the first call to res_ninit() or res_init() and can be ignored. Options stored in statp->options or _res.options are defined in <resolv.h>. They are stored as a simple bit mask containing the bitwise OR of the options enabled. RES_INIT
True if the initial name server address and default domain name are initialized, that is, res_init() or res_ninit() has been called.
Print debugging messages.
Accept authoritative answers only. With this option, res_send() will continue until it finds an authoritative answer or finds an error. Currently this option is not implemented.
Use TCP connections for queries instead of UDP datagrams.
Use with RES_USEVC to keep the TCP connection open between queries. This is a useful option for programs that regularly do many queries. The normal mode used should be UDP.
Ignore truncation errors; that is, do not retry with TCP.
Set the recursion-desired bit in queries. This is the default. res_send() and res_nsend() do not do iterative queries and expect the name server to handle recursion.
If set, res_search() and res_nsearch() append the default domain name to single-component names, that is, names that do not contain a dot. This option is enabled by default.
If this option is set, res_search() and res_nsearch() search for host names in the current domain and in parent domains. See hostname(1). This option is used by the standard host lookup routine gethostbyname(3NSL). This option is enabled by default.
This option turns off the user level aliasing feature controlled by the HOSTALIASES environment variable. Network daemons should set this option.
If the RES_BLAST option is defined, resolver() queries will be sent to all servers. If the RES_BLAST option is not defined, but RES_ROTATE is , the list of nameservers are rotated according to a round-robin scheme. RES_BLAST overrides RES_ROTATE.
This option causes res_nsend() and res_send() to rotate the list of nameservers in statp->nsaddr_list or _res.nsaddr_list.
This option causes res_nsendsigned() to leave the message unchanged after TSIG verification. Otherwise the TSIG record would be removed and the header would be updated.
The res_nquery() and res_query() routines return a length that may be bigger than anslen. In that case, retry the query with a larger buf. The answer to the second query may be larger still], so it is recommended that you supply a buf larger than the answer returned by the previous query. answer must be large enough to receive a maximum UDP response from the server or parts of the answer will be silently discarded. The default maximum UDP response size is 512 bytes.
The res_nsearch() and res_search() routines return a length that may be bigger than anslen. In that case, retry the query with a larger buf. The answer to the second query may be larger still], so it is recommended that you supply a buf larger than the answer returned by the previous query. answer must be large enough to receive a maximum UDP response from the server or parts of the answer will be silently discarded. The default maximum UDP response size is 512 bytes.
The res_nsend() and res_send() routines return a length that may be bigger than anslen. In that case, retry the query with a larger buf. The answer to the second query may be larger still], so it is recommended that you supply a buf larger than the answer returned by the previous query. answer must be large enough to receive a maximum UDP response from the server or parts of the answer will be silently discarded. The default maximum UDP response size is 512 bytes.
The dnptrs parameter is a pointer to the head of the list of pointers to previously compressed names in the current message. The first pointer must point to the beginning of the message. The list ends with NULL. The limit to the array is specified by lastdnptr.
A side effect of calling dn_comp() is to update the list of pointers for labels inserted into the message by dn_comp() as the name is compressed. If dnptrs is NULL, names are not compressed. If lastdnptr is NULL, dn_comp() does not update the list of labels.
#define NETDB_INTERNAL -1 /* see errno */ #define NETDB_SUCCESS 0 /* no problem */ #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ #define TRY_AGAIN 2 /* Non-Authoritative not found, or SERVFAIL */ #define NO_RECOVERY 3 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP*/ #define NO_DATA 4 /* Valid name, no data for requested type */
The herror() function writes a message to the diagnostic output consisting of the string parameters, the constant string ":", and a message corresponding to the value of h_errno.
The hstrerror() function returns a string, which is the message text that corresponds to the value of the err parameter.
resolver configuration file
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Committed |
MT-Level |
Unsafe for deprecated interfaces; MT-Safe for all others. |
Lottor, M. RFC 1033, Domain Administrators Operations Guide. Network Working Group. November 1987.
Mockapetris, Paul. RFC 1034, Domain Names - Concepts and Facilities. Network Working Group. November 1987.
Mockapetris, Paul. RFC 1035, Domain Names - Implementation and Specification. Network Working Group. November 1987.
Partridge, Craig. RFC 974, Mail Routing and the Domain System. Network Working Group. January 1986.
Stahl, M. RFC 1032, Domain Administrators Guide. Network Working Group. November 1987.
Vixie, Paul, Dunlap, Kevin J., Karels, Michael J. Name Server Operations Guide for BIND. Internet Software Consortium, 1996.