dighost.c revision 15a44745412679c30a6d022733925af70a38b715
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User * purpose with or without fee is hereby granted, provided that the above
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User * copyright notice and this permission notice appear in all copies.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
cd32f419a8a5432fbb139f56ee73cbf68b9350ccTinderbox User * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* $Id: dighost.c,v 1.100 2000/07/27 09:36:28 tale Exp $ */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Notice to programmers: Do not use this code as an example of how to
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * use the ISC library to perform DNS lookups. Dig and Host both operate
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * on the request level, since they allow fine-tuning of output and are
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * intended as debugging tools. As a result, they perform many of the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * functions which could be better handled using the dns_resolver
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * functions in most applications.
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsunsigned int timeout = 0;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Apply and clear locks at the event level in global task.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews check_result(isc_mutex_unlock((&lookup_lock)),\
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews "isc_mutex_unlock");\
b2f07642fd712c8fda81a116bcdde229ab291f33Tinderbox Userrecv_done(isc_task_t *task, isc_event_t *event);
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userconnect_timeout(isc_task_t *task, isc_event_t *event);
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User while (*s != '\0') {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User if (*s == '.')
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User unsigned int len;
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User printf("Printing a buffer with length %d\n", r.length);
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntcheck_result(isc_result_t result, const char *msg) {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User fatal("%s: %s", msg, isc_result_totext(result));
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * Create a server structure, which is part of the lookup structure.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * This is little more than a linked list of servers to query in hopes
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * of finding the answer the user is looking for
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User * Produce a cloned server list. The dest list must have already had
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User * ISC_LIST_INIT applied.
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User * Create an empty lookup structure, which holds all the information needed
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User * to get an answer to a user's question. This structure contains two
7e71f05d8643aca84914437c900cb716444507e4Tinderbox User * linked lists: the server list (servers to query) and the query list
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User * (outstanding queries which have been made to the listed servers).
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
return (looknew);
if (servers)
return (looknew);
return (looknew);
setup_text_key(void) {
int secretsize;
unsigned char *secretstore;
&secretbuf);
goto SYSSETUP_FAIL;
namebuf);
goto SYSSETUP_FAIL;
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;
if (fixeddomain[0] != 0) {
if (get_servers &&
ndots);
!= NULL) {
ptr);
mctx, sizeof(struct
dig_server));
__LINE__);
ptr,
link);
(fixeddomain[0] == 0 )){
!= NULL) {
mctx, sizeof(struct
dig_server));
__LINE__);
ptr,
link);
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
setup_libs(void) {
* part of dig.c, host.c, or nslookup.c) to either shutdown the system as
check_if_done(void) {
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)
if (still_working)
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
if (!usesearch)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
MXNAME);
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);
isc_buffer_usedregion(&b, &r);
DNS_SECTION_QUESTION, 0);
ISC_TRUE);
sendcount--;
unsigned int local_timeout;
if (timeout == 0) {
ISC_TRUE);
if (make_recv) {
link);
query);
recvcount++;
link);
sendcount++;
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;
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 xfr_done;
goto next_rdata;
goto next_rdata;
isc_buffer_usedregion(&b, &r);
if (atlimit) {
return (ISC_TRUE);
goto next_rdata;
goto xfr_done;
if (atlimit)
goto xfr_done;
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++;
hex_dump(b);
if (!l->tcp_mode) {
cancel_lookup(l);
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)) {
if (show_details ||
== ISC_R_SUCCESS)) &&
!l->trace_root)) {
ISC_TRUE);
l->trace_root)
ISC_TRUE);
if (show_details) {
l->doing_xfr)
== 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);
int result;
if (result != 0) {
port);
unsigned int local_timeout;
if (timeout == 0) {
sockcount++;
if (specified_source)
sockcount++;
if (specified_source)
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
dig_query_t *q;
if (free_now) {
while (q != NULL) {
q, current_lookup);
while (l != NULL) {
try_clear_lookup(l);
destroy_libs(void) {
void *ptr;
dig_server_t *s;
dig_searchlist_t *o;
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
if (is_dst_up) {
if (isc_mem_debugging)