dighost.c revision 41626c0997c89dcdecf67c931f0031aadd507977
b0e8629055a766d4555a005a283c2889a5974945Mark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Permission to use, copy, modify, and distribute this software for any
94bd918b63001277f1b28ae4581645f8a835688fBob Halley * purpose with or without fee is hereby granted, provided that the above
94bd918b63001277f1b28ae4581645f8a835688fBob Halley * copyright notice and this permission notice appear in all copies.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/* $Id: dighost.c,v 1.202 2001/06/11 18:20:43 gson Exp $ */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Notice to programmers: Do not use this code as an example of how to
e21a2904f02a03fa06b6db04d348f65fe9c67b2bMark Andrews * use the ISC library to perform DNS lookups. Dig and Host both operate
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * on the request level, since they allow fine-tuning of output and are
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * intended as debugging tools. As a result, they perform many of the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * functions which could be better handled using the dns_resolver
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * functions in most applications.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#endif /* DNS_OPT_NEWCODES */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinunsigned int timeout = 0;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Exit Codes:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 0 Everything went well, including things like NXDOMAIN
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 1 Usage error
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 7 Got too many RR's or Names
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 8 Couldn't open batch file
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 9 No reply from server
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 10 Internal error
36e0109263bd544578c245fe8db1e2718e8a8551Mark Andrews * Apply and clear locks at the event level in global task.
36e0109263bd544578c245fe8db1e2718e8a8551Mark Andrews * Can I get rid of these using shutdown events? XXX
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein debug("lock_lookup %s:%d", __FILE__, __LINE__);\
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
36e0109263bd544578c245fe8db1e2718e8a8551Mark Andrews debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "isc_mutex_unlock");\
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrewsrecv_done(isc_task_t *task, isc_event_t *event);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinconnect_timeout(isc_task_t *task, isc_event_t *event);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein while (*s != '\0') {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (*s == '.')
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein unsigned int len;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinget_reverse(char *reverse, char *value, isc_boolean_t nibble) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (strspn(value, "0123456789.") == strlen(value)) {
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;
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;
return (ISC_FALSE);
return (ISC_TRUE);
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)