dighost.c revision d405a8134bdcd6da1392fd499bc45d2f938f8baf
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * Permission to use, copy, modify, and distribute this software for any
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * purpose with or without fee is hereby granted, provided that the above
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44aae046c38e796e581110b7ecdf4478167d684dBob Halley/* $Id: dighost.c,v 1.181 2001/01/08 23:50:34 gson Exp $ */
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * Notice to programmers: Do not use this code as an example of how to
c2bc56dc65b4b103a5600565680eb5f33fa4c90bMark Andrews * use the ISC library to perform DNS lookups. Dig and Host both operate
634c61d2ddf514c3b1f5c8d49c2d2375df20a8b6Andreas Gustafsson * on the request level, since they allow fine-tuning of output and are
634c61d2ddf514c3b1f5c8d49c2d2375df20a8b6Andreas Gustafsson * intended as debugging tools. As a result, they perform many of the
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * functions which could be better handled using the dns_resolver
44aae046c38e796e581110b7ecdf4478167d684dBob Halley * functions in most applications.
44aae046c38e796e581110b7ecdf4478167d684dBob Halley#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
fd35453765c6494d077edca44f4d998af5fd4cfaDavid Lawrence#endif /* DNS_OPT_NEWCODES */
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);
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;
* 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 */
if (get_servers &&
ndots);
!= NULL) {
ptr);
__LINE__);
ptr,
MXNAME);
link);
(fixeddomain[0] == 0 )){
!= NULL) {
__LINE__);
ptr,
link);
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
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;
BUFSIZE);
NULL,
isc_buffer_usedregion(b, &r);
(char *)r.base);
if (!success) {
if (section ==
query->
query->
isc_buffer_free(&b);
static isc_boolean_t
return (ISC_FALSE);
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.
if (fixeddomain[0] != 0) {
sizeof(*fixedsearch));
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) {
sockcount++;
if (specified_source) {
link);
query);
recvcount++;
link);
sendcount++;
if (l->ns_search_only) {
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;
isc_region_t r;
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) {
isc_buffer_usedregion(&b, &r);
if (atlimit)
return (ISC_TRUE);
return (ISC_FALSE);
isc_region_t r;
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);
MXNAME);
&ab);
(char *)r.base,
query);
l->trace_root)
ISC_TRUE);
&ab);
(char *)r.base,
query);
== ISC_R_SUCCESS) &&
l->ns_search_only &&
!l->trace_root ) {
if (l->pending)
if (l->doing_xfr) {
if (docancel) {
cancel_lookup(l);
&ab);
(char *)r.base,
query);
cancel_lookup(l);
sockcount--;
int result;
if (result != 0) {
port);
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
if (is_blocking) {
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;
dig_searchlist_t *o;
if (is_blocking) {
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
if (is_dst_up) {
if (memdebugging != 0)