dighost.c revision 21f2b02a04468efad0e55ec1fbc4e95f1e4ff286
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * Copyright (C) 2000, 2001 Internet Software Consortium.
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * Permission to use, copy, modify, and distribute this software for any
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * copyright notice and this permission notice appear in all copies.
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer/* $Id: dighost.c,v 1.196 2001/03/14 23:13:57 gson Exp $ */
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * Notice to programmers: Do not use this code as an example of how to
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * use the ISC library to perform DNS lookups. Dig and Host both operate
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * on the request level, since they allow fine-tuning of output and are
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * intended as debugging tools. As a result, they perform many of the
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * functions which could be better handled using the dns_resolver
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer * functions in most applications.
43383a70d36d2c19da0354e96114817f55cae66aMichael Sawyer#endif /* DNS_OPT_NEWCODES */
#ifdef HAVE_ADDRINFO
#ifdef HAVE_GETADDRINFO
#ifdef HAVE_GAISTRERROR
#define USE_GETADDRINFO
#ifndef USE_GETADDRINFO
extern int h_errno;
unsigned int timeout = 0;
int sendcount = 0;
int recvcount = 0;
int sockcount = 0;
int lookup_counter = 0;
int exitcode = 0;
#define LOCK_LOOKUP {\
#define UNLOCK_LOOKUP {\
char *res;
return (res);
s = string;
unsigned int len;
isc_region_t r;
isc_buffer_usedregion(b, &r);
int remaining;
reverse[0] = 0;
return (DNS_R_BADDOTTEDQUAD);
adrs[i]);
isc_buffer_t b;
return (DNS_R_BADDOTTEDQUAD);
name);
return (result);
isc_buffer_putuint8(&b, 0);
return (result);
if (debugging) {
return (srv);
make_empty_lookup(void) {
#ifdef DNS_OPT_NEWCODES_LIVE
return (looknew);
#ifdef DNS_OPT_NEWCODES_LIVE
if (servers)
return (looknew);
return (looknew);
setup_text_key(void) {
int secretsize;
unsigned char *secretstore;
&secretbuf);
goto failure;
namebuf);
goto failure;
setup_file_key(void) {
int secretlen;
goto failure;
goto failure;
static dig_searchlist_t *
return (search);
* Setup the system as a whole, reading key information and resolv.conf
setup_system(void) {
char *ptr;
char *input;
/* XXX Use lwres resolv.conf reader */
goto no_file;
if (get_servers &&
ndots);
!= NULL) {
!= NULL) {
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
clear_searchlist(void) {
* Override the search list derived from resolv.conf by 'domain'.
setup_libs(void) {
#ifdef DNS_OPT_NEWCODES_LIVE
#ifdef DNS_OPT_NEWCODES_LIVE
unsigned int i, optsize = 0;
if (dnssec)
#ifdef DNS_OPT_NEWCODES_LIVE
* part of dig.c, host.c, or nslookup.c) to either shutdown the system as
check_if_done(void) {
sendcount == 0) {
link);
link);
sockcount--;
static isc_boolean_t
dig_server_t *s;
dig_query_t *q;
void *ptr;
if (debugging) {
while (q != NULL) {
q->servname);
return (ISC_FALSE);
while (s != NULL) {
s, lookup);
ptr = s;
return (ISC_TRUE);
start_lookup(void) {
if (cancel_now)
start_lookup();
isc_region_t r;
int len;
int numLookups = 0;
numLookups +=
return numLookups;
BUFSIZE);
NULL,
isc_buffer_usedregion(b, &r);
(char *)r.base);
numLookups++;
if (!success) {
if (section ==
query->
query->
query->
isc_buffer_free(&b);
numLookups +=
return numLookups;
static isc_boolean_t
if (!usesearch)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
int len;
isc_region_t r;
isc_buffer_t b;
lookup_counter = 0;
* is TRUE or we got a domain line in the resolv.conf file.
isc_buffer_usedregion(&b, &r);
#ifndef DNS_OPT_NEWCODES_LIVE
#ifdef DNS_OPT_NEWCODES_LIVE
NULL);
MXNAME);
wirebuf);
optlist);
DNS_SECTION_QUESTION, 0);
ISC_TRUE);
sendcount--;
dig_lookup_t *l;
unsigned int local_timeout;
if (timeout == 0) {
NULL,
&l->interval,
l, &l->timer);
dig_lookup_t *l;
if (specified_source &&
sockcount++;
if (specified_source)
if (l->ns_search_only_leafnode) {
sockcount++;
if (specified_source) {
link);
query);
recvcount++;
link);
sendcount++;
if (l->ns_search_only_leafnode) {
if (!l->tcp_mode)
if (!l->tcp_mode) {
l->retries--;
l->retries);
cancel_lookup(l);
l->retries--;
cancel_lookup(l);
isc_region_t r;
dig_lookup_t *l;
recvcount--;
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
sockcount--;
length);
recvcount++;
dig_lookup_t *l;
sockcount--;
if (include_question) {
link);
recvcount++;
sendcount++;
dig_lookup_t *l;
isc_region_t r;
sockcount--;
isc_buffer_usedregion(b, &r);
sockcount--;
isc_buffer_free(&b);
static isc_boolean_t
isc_buffer_t b;
return (ISC_TRUE);
&name);
return (ISC_TRUE);
goto next_rdata;
&soa,
mctx);
goto doexit;
goto next_rdata;
goto doexit;
goto doexit;
goto next_rdata;
goto doexit;
goto next_rdata;
goto doexit;
if (atlimit) {
if (atlimit)
return (ISC_TRUE);
return (ISC_FALSE);
dig_lookup_t *n, *l;
unsigned int local_timeout;
recvcount--;
|| cancel_now) {
&msg);
l->sendmsg,
l->querysig);
if (l->msgcounter != 0)
l->msgcounter++;
if (l->besteffort)
hex_dump(b);
cancel_lookup(l);
cancel_lookup(l);
l->servfail_stops) {
if (l->tcp_mode)
l->querysig);
&l->querysig);
l->doing_xfr ) {
if (timeout == 0) {
if (l->tcp_mode)
local_timeout, 0);
NULL,
&l->interval,
if ((l->trace)||
(l->ns_search_only)) {
ISC_TRUE);
query);
if (l->ns_search_only)
DNS_SECTION_ANSWER) == 0)
l->trace_root)
ISC_TRUE);
query);
== ISC_R_SUCCESS) &&
!l->trace_root ) {
if (l->pending)
if (l->doing_xfr) {
if (! docancel)
if (docancel) {
cancel_lookup(l);
query);
cancel_lookup(l);
sockcount--;
#ifdef USE_GETADDRINFO
int result;
#ifdef USE_GETADDRINFO
if (!have_ipv6)
else if (!have_ipv4)
if (result != 0) {
port);
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
if (free_now) {
while (q != NULL) {
q, current_lookup);
clear_query (q);
q = nq;
while (l != NULL) {
try_clear_lookup(l);
destroy_libs(void) {
void *ptr;
dig_server_t *s;
while (s != NULL) {
ptr = s;
if (is_dst_up) {
if (memdebugging != 0)