mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
Clean up type and class code. (No more ugly istype() and isclass() functions)
Minor changes to timeout handling code. Don't preload batch file.
This commit is contained in:
parent
9df7d74e42
commit
aa6054ec74
147
bin/dig/dig.c
147
bin/dig/dig.c
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dig.c,v 1.68 2000/07/14 21:33:02 mws Exp $ */
|
||||
/* $Id: dig.c,v 1.69 2000/07/18 01:28:15 mws Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
@ -30,6 +30,7 @@
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatatype.h>
|
||||
#include <dns/rdataclass.h>
|
||||
|
||||
#include <dig/dig.h>
|
||||
|
||||
@ -67,9 +68,13 @@ extern isc_boolean_t validated;
|
||||
extern isc_taskmgr_t *taskmgr;
|
||||
extern isc_task_t *global_task;
|
||||
extern isc_boolean_t free_now;
|
||||
dig_lookup_t *default_lookup = NULL;
|
||||
|
||||
extern isc_boolean_t debugging;
|
||||
extern isc_boolean_t isc_mem_debugging;
|
||||
char *batchname = NULL;
|
||||
FILE *batchfp = NULL;
|
||||
char *argv0;
|
||||
|
||||
isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE;
|
||||
|
||||
@ -168,12 +173,6 @@ show_usage(void) {
|
||||
, stderr);
|
||||
}
|
||||
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
free_lists();
|
||||
isc_app_shutdown();
|
||||
}
|
||||
|
||||
void
|
||||
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
isc_uint64_t diff;
|
||||
@ -540,13 +539,14 @@ reorder_args(int argc, char *argv[]) {
|
||||
static void
|
||||
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
isc_boolean_t have_host = ISC_FALSE;
|
||||
isc_result_t result;
|
||||
isc_textregion_t tr;
|
||||
dig_server_t *srv = NULL, *s, *s2;
|
||||
dig_lookup_t *lookup = NULL;
|
||||
static dig_lookup_t *default_lookup = NULL;
|
||||
char *batchname = NULL;
|
||||
dns_rdatatype_t rdtype;
|
||||
dns_rdataclass_t rdclass;
|
||||
char batchline[MXNAME];
|
||||
char address[MXNAME];
|
||||
FILE *fp = NULL;
|
||||
int bargc;
|
||||
char *bargv[16];
|
||||
int i, n;
|
||||
@ -665,7 +665,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
lookup->section_additional = ISC_FALSE;
|
||||
lookup->section_authority = ISC_FALSE;
|
||||
lookup->section_question = ISC_FALSE;
|
||||
strcpy(lookup->rttext, "soa");
|
||||
lookup->rdtype = dns_rdatatype_soa;
|
||||
short_form = ISC_TRUE;
|
||||
} else if (strncmp(rv[0], "+nons", 6) == 0) {
|
||||
lookup->ns_search_only = ISC_FALSE;
|
||||
@ -754,24 +754,47 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
lookup->comments = ISC_FALSE;
|
||||
} else if (strncmp(rv[0], "-c", 2) == 0) {
|
||||
if (rv[0][2] != 0) {
|
||||
strncpy(lookup->rctext, &rv[0][2],
|
||||
MXRD);
|
||||
ptr = &rv[0][2];
|
||||
} else {
|
||||
strncpy(lookup->rctext, rv[1],
|
||||
MXRD);
|
||||
ptr = rv[1];
|
||||
rv++;
|
||||
rc--;
|
||||
}
|
||||
tr.base = ptr;
|
||||
tr.length = strlen(ptr);
|
||||
result = dns_rdataclass_fromtext(&rdclass,
|
||||
(isc_textregion_t *)&tr);
|
||||
if (result == ISC_R_SUCCESS)
|
||||
lookup->rdclass = rdclass;
|
||||
else
|
||||
fprintf (stderr, ";; Warning, ignoring "
|
||||
"invalid class %s\n",
|
||||
ptr);
|
||||
} else if (strncmp(rv[0], "-t", 2) == 0) {
|
||||
if (rv[0][2] != 0) {
|
||||
strncpy(lookup->rttext, &rv[0][2],
|
||||
MXRD);
|
||||
ptr = &rv[0][2];
|
||||
} else {
|
||||
strncpy(lookup->rttext, rv[1],
|
||||
MXRD);
|
||||
ptr = rv[1];
|
||||
rv++;
|
||||
rc--;
|
||||
}
|
||||
tr.base = ptr;
|
||||
tr.length = strlen(ptr);
|
||||
if (strncmp(rv[0], "ixfr=", 5) == 0) {
|
||||
lookup->rdtype = dns_rdatatype_ixfr;
|
||||
lookup->ixfr_serial =
|
||||
atoi(&rv[0][5]);
|
||||
} else {
|
||||
result = dns_rdatatype_fromtext(&rdtype,
|
||||
(isc_textregion_t *)&tr);
|
||||
if ((result == ISC_R_SUCCESS) &&
|
||||
(rdtype != dns_rdatatype_ixfr))
|
||||
lookup->rdtype = rdtype;
|
||||
else
|
||||
fprintf (stderr, ";; Warning, "
|
||||
"ignoring invalid type %s\n",
|
||||
ptr);
|
||||
}
|
||||
} else if (strncmp(rv[0], "-f", 2) == 0) {
|
||||
if (rv[0][2] != 0) {
|
||||
batchname = &rv[0][2];
|
||||
@ -853,8 +876,8 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
debug("looking up %s", lookup->textname);
|
||||
lookup->trace_root = ISC_TF(lookup->trace ||
|
||||
lookup->ns_search_only);
|
||||
strcpy(lookup->rttext, "ptr");
|
||||
strcpy(lookup->rctext, "in");
|
||||
lookup->rdtype = dns_rdatatype_ptr;
|
||||
lookup->rdclass = dns_rdataclass_in;
|
||||
lookup->new_search = ISC_TRUE;
|
||||
|
||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||
@ -862,18 +885,25 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
rv++;
|
||||
rc--;
|
||||
} else {
|
||||
tr.base = rv[0];
|
||||
tr.length = strlen(rv[0]);
|
||||
if (strncmp(rv[0], "ixfr=", 5) == 0) {
|
||||
strcpy(lookup->rttext, "ixfr");
|
||||
lookup->rdtype = dns_rdatatype_ixfr;
|
||||
lookup->ixfr_serial =
|
||||
atoi(&rv[0][5]);
|
||||
continue;
|
||||
}
|
||||
if (istype(rv[0])) {
|
||||
strncpy(lookup->rttext, rv[0], MXRD);
|
||||
result = dns_rdatatype_fromtext(&rdtype,
|
||||
(isc_textregion_t *)&tr);
|
||||
if ((result == ISC_R_SUCCESS) &&
|
||||
(rdtype != dns_rdatatype_ixfr)) {
|
||||
lookup->rdtype = rdtype;
|
||||
continue;
|
||||
} else if (isclass(rv[0])) {
|
||||
strncpy(lookup->rctext, rv[0],
|
||||
MXRD);
|
||||
}
|
||||
result = dns_rdataclass_fromtext(&rdclass,
|
||||
(isc_textregion_t *)&tr);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
lookup->rdclass = rdclass;
|
||||
continue;
|
||||
}
|
||||
lookup=clone_lookup(default_lookup, ISC_TRUE);
|
||||
@ -886,15 +916,20 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
debug("looking up %s", lookup->textname);
|
||||
}
|
||||
}
|
||||
if (batchname != NULL) {
|
||||
fp = fopen(batchname, "r");
|
||||
if (fp == NULL) {
|
||||
/*
|
||||
* If we have a batchfile, seed the lookup list with the
|
||||
* first entry, then trust the callback in dighost_shutdown
|
||||
* to get the rest
|
||||
*/
|
||||
if ((batchname != NULL) && !(is_batchfile)) {
|
||||
batchfp = fopen(batchname, "r");
|
||||
if (batchfp == NULL) {
|
||||
perror(batchname);
|
||||
if (exitcode < 10)
|
||||
exitcode = 10;
|
||||
fatal("Couldn't open specified batch file");
|
||||
}
|
||||
while (fgets(batchline, sizeof(batchline), fp) != 0) {
|
||||
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
|
||||
debug("batch line %s", batchline);
|
||||
bargc = 1;
|
||||
bargv[bargc] = strtok(batchline, " \t\r\n");
|
||||
@ -904,6 +939,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
}
|
||||
|
||||
bargv[0] = argv[0];
|
||||
argv0 = argv[0];
|
||||
|
||||
reorder_args(bargc, (char **)bargv);
|
||||
parse_args(ISC_TRUE, bargc, (char **)bargv);
|
||||
@ -915,7 +951,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
lookup->ns_search_only);
|
||||
lookup->new_search = ISC_TRUE;
|
||||
strcpy(lookup->textname, ".");
|
||||
strcpy(lookup->rttext, "NS");
|
||||
lookup->rdtype = dns_rdatatype_ns;
|
||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||
}
|
||||
if (!is_batchfile) {
|
||||
@ -930,7 +966,47 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
(dig_server_t *)s2, link);
|
||||
isc_mem_free(mctx, s2);
|
||||
}
|
||||
isc_mem_free(mctx, default_lookup);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
char batchline[MXNAME];
|
||||
int bargc;
|
||||
char *bargv[16];
|
||||
|
||||
|
||||
if (batchname == NULL) {
|
||||
isc_app_shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
if (feof(batchfp)) {
|
||||
batchname = NULL;
|
||||
isc_app_shutdown();
|
||||
fclose(batchfp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
|
||||
debug("batch line %s", batchline);
|
||||
bargc = 1;
|
||||
bargv[bargc] = strtok(batchline, " \t\r\n");
|
||||
while ((bargv[bargc] != NULL) && (bargc < 14 )) {
|
||||
bargc++;
|
||||
bargv[bargc] = strtok(NULL, " \t\r\n");
|
||||
}
|
||||
|
||||
bargv[0] = argv0;
|
||||
|
||||
reorder_args(bargc, (char **)bargv);
|
||||
parse_args(ISC_TRUE, bargc, (char **)bargv);
|
||||
start_lookup();
|
||||
} else {
|
||||
batchname = NULL;
|
||||
fclose(batchfp);
|
||||
isc_app_shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -950,6 +1026,11 @@ main(int argc, char **argv) {
|
||||
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
|
||||
check_result(result, "isc_app_onrun");
|
||||
isc_app_run();
|
||||
isc_mem_free(mctx, default_lookup);
|
||||
if (batchname != NULL) {
|
||||
fclose(batchfp);
|
||||
batchname = NULL;
|
||||
}
|
||||
cancel_all();
|
||||
destroy_libs();
|
||||
isc_app_finish();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dighost.c,v 1.89 2000/07/14 21:33:03 mws Exp $ */
|
||||
/* $Id: dighost.c,v 1.90 2000/07/18 01:28:16 mws Exp $ */
|
||||
|
||||
/*
|
||||
* Notice to programmers: Do not use this code as an example of how to
|
||||
@ -92,7 +92,7 @@ int sendcount = 0;
|
||||
int recvcount = 0;
|
||||
int sockcount = 0;
|
||||
int ndots = -1;
|
||||
int tries = 3;
|
||||
int tries = 2;
|
||||
int lookup_counter = 0;
|
||||
char fixeddomain[MXNAME] = "";
|
||||
int exitcode = 9;
|
||||
@ -202,51 +202,6 @@ check_result(isc_result_t result, const char *msg) {
|
||||
}
|
||||
}
|
||||
|
||||
isc_boolean_t
|
||||
isclass(char *text) {
|
||||
/*
|
||||
* Tests if a field is a class, without needing isc libs
|
||||
* initialized. This list will have to be manually kept in
|
||||
* sync with what the libs support.
|
||||
*/
|
||||
const char *classlist[] = { "in", "hs", "chaos" };
|
||||
const int numclasses = 3;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < numclasses; i++)
|
||||
if (strcasecmp(text, classlist[i]) == 0)
|
||||
return (ISC_TRUE);
|
||||
|
||||
return (ISC_FALSE);
|
||||
}
|
||||
|
||||
isc_boolean_t
|
||||
istype(char *text) {
|
||||
/*
|
||||
* Tests if a field is a type, without needing isc libs
|
||||
* initialized. This list will have to be manually kept in
|
||||
* sync with what the libs support.
|
||||
*/
|
||||
const char *typelist[] = {"a", "ns", "md", "mf", "cname",
|
||||
"soa", "mb", "mg", "mr", "null",
|
||||
"wks", "ptr", "hinfo", "minfo",
|
||||
"mx", "txt", "rp", "afsdb",
|
||||
"x25", "isdn", "rt", "nsap",
|
||||
"nsap_ptr", "sig", "key", "px",
|
||||
"gpos", "aaaa", "loc", "nxt",
|
||||
"srv", "naptr", "kx", "cert",
|
||||
"a6", "dname", "opt", "unspec",
|
||||
"tkey", "tsig", "axfr", "any"};
|
||||
const int numtypes = 42;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < numtypes; i++) {
|
||||
if (strcasecmp(text, typelist[i]) == 0)
|
||||
return (ISC_TRUE);
|
||||
}
|
||||
return (ISC_FALSE);
|
||||
}
|
||||
|
||||
dig_server_t *
|
||||
make_server(const char *servname) {
|
||||
dig_server_t *srv;
|
||||
@ -291,8 +246,8 @@ make_empty_lookup(void) {
|
||||
__FILE__, __LINE__);
|
||||
looknew->pending = ISC_TRUE;
|
||||
looknew->textname[0]=0;
|
||||
looknew->rttext[0]=0;
|
||||
looknew->rctext[0]=0;
|
||||
looknew->rdtype=dns_rdatatype_a;
|
||||
looknew->rdclass=dns_rdataclass_in;
|
||||
looknew->sendspace = NULL;
|
||||
looknew->sendmsg = NULL;
|
||||
looknew->name = NULL;
|
||||
@ -343,8 +298,8 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
|
||||
looknew = make_empty_lookup();
|
||||
INSIST(looknew != NULL);
|
||||
strncpy(looknew->textname, lookold-> textname, MXNAME);
|
||||
strncpy(looknew->rttext, lookold-> rttext, 32);
|
||||
strncpy(looknew->rctext, lookold-> rctext, 32);
|
||||
looknew->rdtype = lookold->rdtype;
|
||||
looknew->rdclass = lookold->rdclass;
|
||||
looknew->doing_xfr = lookold->doing_xfr;
|
||||
looknew->ixfr_serial = lookold->ixfr_serial;
|
||||
looknew->defname = lookold->defname;
|
||||
@ -1055,12 +1010,9 @@ void
|
||||
setup_lookup(dig_lookup_t *lookup) {
|
||||
isc_result_t result, res2;
|
||||
int len;
|
||||
dns_rdatatype_t rdtype;
|
||||
dns_rdataclass_t rdclass;
|
||||
dig_server_t *serv;
|
||||
dig_query_t *query;
|
||||
isc_region_t r;
|
||||
isc_constregion_t tr;
|
||||
isc_buffer_t b;
|
||||
char store[MXNAME];
|
||||
|
||||
@ -1167,10 +1119,6 @@ setup_lookup(dig_lookup_t *lookup) {
|
||||
isc_buffer_usedregion(&b, &r);
|
||||
trying((int)r.length, (char *)r.base, lookup);
|
||||
ENSURE(dns_name_isabsolute(lookup->name));
|
||||
if (lookup->rctext[0] == 0)
|
||||
strcpy(lookup->rctext, "IN");
|
||||
if (lookup->rttext[0] == 0)
|
||||
strcpy(lookup->rttext, "A");
|
||||
|
||||
lookup->sendmsg->id = (unsigned short)(random() & 0xFFFF);
|
||||
lookup->sendmsg->opcode = dns_opcode_query;
|
||||
@ -1203,36 +1151,21 @@ setup_lookup(dig_lookup_t *lookup) {
|
||||
DNS_SECTION_QUESTION);
|
||||
|
||||
if (lookup->trace_root) {
|
||||
debug("doing trace_root");
|
||||
tr.base = "SOA";
|
||||
tr.length = 3;
|
||||
} else {
|
||||
tr.base = lookup->rttext;
|
||||
tr.length = strlen(lookup->rttext);
|
||||
lookup->rdtype = dns_rdatatype_soa;
|
||||
lookup->rdclass = dns_rdataclass_in;
|
||||
}
|
||||
debug("data type is %s", lookup->rttext);
|
||||
result = dns_rdatatype_fromtext(&rdtype, (isc_textregion_t *)&tr);
|
||||
check_result(result, "dns_rdatatype_fromtext");
|
||||
if ((rdtype == dns_rdatatype_axfr) ||
|
||||
(rdtype == dns_rdatatype_ixfr)) {
|
||||
if ((lookup->rdtype == dns_rdatatype_axfr) ||
|
||||
(lookup->rdtype == dns_rdatatype_ixfr)) {
|
||||
lookup->doing_xfr = ISC_TRUE;
|
||||
/*
|
||||
* Force TCP mode if we're doing an xfr.
|
||||
*/
|
||||
lookup->tcp_mode = ISC_TRUE;
|
||||
}
|
||||
if (lookup->trace_root) {
|
||||
tr.base = "IN";
|
||||
tr.length = 2;
|
||||
} else {
|
||||
tr.base = lookup->rctext;
|
||||
tr.length = strlen(lookup->rctext);
|
||||
}
|
||||
result = dns_rdataclass_fromtext(&rdclass, (isc_textregion_t *)&tr);
|
||||
check_result(result, "dns_rdataclass_fromtext");
|
||||
add_question(lookup->sendmsg, lookup->name, rdclass, rdtype);
|
||||
add_question(lookup->sendmsg, lookup->name, lookup->rdclass,
|
||||
lookup->rdtype);
|
||||
|
||||
if (rdtype == dns_rdatatype_ixfr)
|
||||
if (lookup->rdtype == dns_rdatatype_ixfr)
|
||||
insert_soa(lookup);
|
||||
|
||||
if (key != NULL) {
|
||||
@ -1283,7 +1216,6 @@ setup_lookup(dig_lookup_t *lookup) {
|
||||
query->second_rr_rcvd = ISC_FALSE;
|
||||
query->second_rr_serial = 0;
|
||||
query->servname = serv->servername;
|
||||
ISC_LIST_INIT(query->sendlist);
|
||||
ISC_LIST_INIT(query->recvlist);
|
||||
ISC_LIST_INIT(query->lengthlist);
|
||||
query->sock = NULL;
|
||||
@ -1362,46 +1294,65 @@ recv_done(isc_task_t *task, isc_event_t *event);
|
||||
static void
|
||||
connect_timeout(isc_task_t *task, isc_event_t *event);
|
||||
|
||||
void
|
||||
send_udp(dig_lookup_t *lookup) {
|
||||
static void
|
||||
send_udp(dig_lookup_t *lookup, isc_boolean_t make_recv) {
|
||||
dig_query_t *query;
|
||||
isc_result_t result;
|
||||
unsigned int local_timeout;
|
||||
|
||||
debug("send_udp()");
|
||||
|
||||
if (timeout != INT_MAX) {
|
||||
if (timeout == 0) {
|
||||
if (lookup->tcp_mode)
|
||||
local_timeout = TCP_TIMEOUT;
|
||||
else
|
||||
/*
|
||||
* If the timer already exists, that means we're calling this
|
||||
* a second time (for a retry). Don't need to recreate it,
|
||||
* just reset it.
|
||||
*/
|
||||
if (lookup->timer == NULL) {
|
||||
if (timeout != INT_MAX) {
|
||||
if (timeout == 0) {
|
||||
local_timeout = UDP_TIMEOUT;
|
||||
} else
|
||||
local_timeout = timeout;
|
||||
debug("have local timeout of %d", local_timeout);
|
||||
isc_interval_set(&lookup->interval, local_timeout, 0);
|
||||
result = isc_timer_create(timermgr, isc_timertype_once, NULL,
|
||||
&lookup->interval, global_task,
|
||||
connect_timeout, lookup,
|
||||
&lookup->timer);
|
||||
check_result(result, "isc_timer_create");
|
||||
} else
|
||||
local_timeout = timeout;
|
||||
debug("have local timeout of %d", local_timeout);
|
||||
isc_interval_set(&lookup->interval, local_timeout, 0);
|
||||
result = isc_timer_create(timermgr,
|
||||
isc_timertype_once, NULL,
|
||||
&lookup->interval,
|
||||
global_task,
|
||||
connect_timeout, lookup,
|
||||
&lookup->timer);
|
||||
check_result(result, "isc_timer_create");
|
||||
}
|
||||
|
||||
} else {
|
||||
result = isc_timer_reset(lookup->timer, isc_timertype_once,
|
||||
NULL, &lookup->interval,
|
||||
ISC_TRUE);
|
||||
check_result(result, "isc_timer_reset");
|
||||
}
|
||||
for (query = ISC_LIST_HEAD(lookup->q);
|
||||
query != NULL;
|
||||
query = ISC_LIST_NEXT(query, link)) {
|
||||
debug("working on lookup %p, query %p",
|
||||
query->lookup, query);
|
||||
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
|
||||
query->working = ISC_TRUE;
|
||||
debug("recving with lookup=%p, query=%p, sock=%p",
|
||||
query->lookup, query,
|
||||
query->sock);
|
||||
result = isc_socket_recvv(query->sock, &query->recvlist, 1,
|
||||
global_task, recv_done, query);
|
||||
check_result(result, "isc_socket_recvv");
|
||||
recvcount++;
|
||||
debug("recvcount=%d", recvcount);
|
||||
ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf, link);
|
||||
if (make_recv) {
|
||||
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf,
|
||||
link);
|
||||
query->working = ISC_TRUE;
|
||||
debug("recving with lookup=%p, query=%p, sock=%p",
|
||||
query->lookup, query,
|
||||
query->sock);
|
||||
result = isc_socket_recvv(query->sock,
|
||||
&query->recvlist, 1,
|
||||
global_task, recv_done,
|
||||
query);
|
||||
check_result(result, "isc_socket_recvv");
|
||||
recvcount++;
|
||||
debug("recvcount=%d", recvcount);
|
||||
}
|
||||
ISC_LIST_INIT(query->sendlist);
|
||||
ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf,
|
||||
link);
|
||||
debug("sending a request");
|
||||
result = isc_time_now(&query->time_sent);
|
||||
check_result(result, "isc_time_now");
|
||||
@ -1420,11 +1371,8 @@ send_udp(dig_lookup_t *lookup) {
|
||||
static void
|
||||
connect_timeout(isc_task_t *task, isc_event_t *event) {
|
||||
dig_lookup_t *lookup=NULL;
|
||||
dig_query_t *q=NULL;
|
||||
isc_result_t result;
|
||||
isc_buffer_t *b=NULL;
|
||||
isc_region_t r;
|
||||
|
||||
UNUSED(task);
|
||||
REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
|
||||
|
||||
debug("connect_timeout()");
|
||||
@ -1433,44 +1381,22 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
|
||||
lookup = event->ev_arg;
|
||||
isc_event_free(&event);
|
||||
|
||||
debug("buffer allocate connect_timeout");
|
||||
result = isc_buffer_allocate(mctx, &b, 256);
|
||||
check_result(result, "isc_buffer_allocate");
|
||||
for (q = ISC_LIST_HEAD(lookup->q);
|
||||
q != NULL;
|
||||
q = ISC_LIST_NEXT(q, link)) {
|
||||
if (q->working) {
|
||||
INSIST(!free_now);
|
||||
isc_buffer_clear(b);
|
||||
result = isc_sockaddr_totext(&q->sockaddr, b);
|
||||
check_result(result, "isc_sockaddr_totext");
|
||||
isc_buffer_usedregion(b, &r);
|
||||
if ((q->lookup->retries > 1) &&
|
||||
(!q->lookup->tcp_mode))
|
||||
printf(";; Connection to %.*s(%s) "
|
||||
"for %s timed out. "
|
||||
"Retrying %d.\n",
|
||||
(int)r.length, r.base,
|
||||
q->servname,
|
||||
q->lookup->textname,
|
||||
q->lookup->retries-1);
|
||||
else {
|
||||
printf(";; Connection to "
|
||||
"%.*s(%s) "
|
||||
"for %s timed out. "
|
||||
"Giving up.\n",
|
||||
(int)r.length, r.base,
|
||||
q->servname,
|
||||
q->lookup->textname);
|
||||
}
|
||||
isc_socket_cancel(q->sock, task,
|
||||
ISC_SOCKCANCEL_ALL);
|
||||
INSIST(!free_now);
|
||||
if (lookup->retries > 1) {
|
||||
if (!lookup->tcp_mode) {
|
||||
lookup->retries--;
|
||||
debug("resending UDP request");
|
||||
send_udp(lookup, ISC_FALSE);
|
||||
} else {
|
||||
debug("making new TCP request");
|
||||
cancel_lookup(lookup);
|
||||
lookup->retries--;
|
||||
requeue_lookup(lookup, ISC_TRUE);
|
||||
}
|
||||
}
|
||||
INSIST(lookup->timer != NULL);
|
||||
isc_timer_detach(&lookup->timer);
|
||||
isc_buffer_free(&b);
|
||||
debug("done with connect_timeout()");
|
||||
else {
|
||||
cancel_lookup(lookup);
|
||||
}
|
||||
UNLOCK_LOOKUP;
|
||||
}
|
||||
|
||||
@ -1581,6 +1507,7 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
|
||||
isc_buffer_clear(&query->slbuf);
|
||||
isc_buffer_clear(&query->lengthbuf);
|
||||
isc_buffer_putuint16(&query->slbuf, query->lookup->sendbuf.used);
|
||||
ISC_LIST_INIT(query->sendlist);
|
||||
ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
|
||||
if (include_question) {
|
||||
ISC_LIST_ENQUEUE(query->sendlist, &query->lookup->sendbuf,
|
||||
@ -2056,6 +1983,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
dns_message_destroy(&msg);
|
||||
clear_query(query);
|
||||
cancel_lookup(l);
|
||||
check_next_lookup(l);
|
||||
}
|
||||
if (msg != NULL)
|
||||
dns_message_destroy(&msg);
|
||||
@ -2163,10 +2091,7 @@ do_lookup_tcp(dig_lookup_t *lookup) {
|
||||
lookup->pending = ISC_TRUE;
|
||||
if (timeout != INT_MAX) {
|
||||
if (timeout == 0) {
|
||||
if (lookup->tcp_mode)
|
||||
local_timeout = TCP_TIMEOUT;
|
||||
else
|
||||
local_timeout = UDP_TIMEOUT;
|
||||
} else
|
||||
local_timeout = timeout;
|
||||
debug("have local timeout of %d", local_timeout);
|
||||
@ -2242,7 +2167,7 @@ do_lookup_udp(dig_lookup_t *lookup) {
|
||||
check_result(result, "isc_socket_bind");
|
||||
}
|
||||
|
||||
send_udp(lookup);
|
||||
send_udp(lookup, ISC_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2392,10 +2317,3 @@ destroy_libs(void) {
|
||||
if (mctx != NULL)
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dummy function, soon to go away
|
||||
*/
|
||||
void
|
||||
free_lists(void) {
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: host.c,v 1.41 2000/07/14 17:57:26 mws Exp $ */
|
||||
/* $Id: host.c,v 1.42 2000/07/18 01:28:17 mws Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
@ -32,7 +32,9 @@ extern int h_errno;
|
||||
#include <dns/message.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdataclass.h>
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatatype.h>
|
||||
|
||||
#include <dig/dig.h>
|
||||
|
||||
@ -58,10 +60,7 @@ extern char *progname;
|
||||
extern isc_task_t *global_task;
|
||||
|
||||
isc_boolean_t
|
||||
short_form = ISC_TRUE,
|
||||
filter = ISC_FALSE,
|
||||
showallsoa = ISC_FALSE,
|
||||
tcpmode = ISC_FALSE;
|
||||
short_form = ISC_TRUE;
|
||||
|
||||
static const char *opcodetext[] = {
|
||||
"QUERY",
|
||||
@ -231,7 +230,6 @@ show_usage(void) {
|
||||
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
free_lists();
|
||||
isc_app_shutdown();
|
||||
}
|
||||
|
||||
@ -538,40 +536,60 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
|
||||
static void
|
||||
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
isc_boolean_t recursion = ISC_TRUE;
|
||||
char hostname[MXNAME];
|
||||
char querytype[32] = "";
|
||||
char queryclass[32] = "";
|
||||
dig_server_t *srv;
|
||||
dig_lookup_t *lookup;
|
||||
int i, c, n, adrs[4];
|
||||
char store[MXNAME];
|
||||
isc_textregion_t tr;
|
||||
isc_result_t result;
|
||||
dns_rdatatype_t rdtype;
|
||||
dns_rdataclass_t rdclass;
|
||||
|
||||
UNUSED(is_batchfile);
|
||||
|
||||
lookup = make_empty_lookup();
|
||||
|
||||
while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
|
||||
!= EOF) {
|
||||
switch (c) {
|
||||
case 'l':
|
||||
tcpmode = ISC_TRUE;
|
||||
filter = ISC_TRUE;
|
||||
strcpy(querytype, "axfr");
|
||||
lookup->tcp_mode = ISC_TRUE;
|
||||
lookup->rdtype = dns_rdatatype_axfr;
|
||||
break;
|
||||
case 'v':
|
||||
case 'd':
|
||||
short_form = ISC_FALSE;
|
||||
break;
|
||||
case 'r':
|
||||
recursion = ISC_FALSE;
|
||||
lookup->recurse = ISC_FALSE;
|
||||
break;
|
||||
case 't':
|
||||
strncpy (querytype, isc_commandline_argument, 32);
|
||||
tr.base = isc_commandline_argument;
|
||||
tr.length = strlen(isc_commandline_argument);
|
||||
result = dns_rdatatype_fromtext(&rdtype,
|
||||
(isc_textregion_t *)&tr);
|
||||
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fprintf (stderr,"Warning: invalid type: %s\n",
|
||||
isc_commandline_argument);
|
||||
else
|
||||
lookup->rdtype = rdtype;
|
||||
break;
|
||||
case 'c':
|
||||
strncpy (queryclass, isc_commandline_argument, 32);
|
||||
tr.base = isc_commandline_argument;
|
||||
tr.length = strlen(isc_commandline_argument);
|
||||
result = dns_rdataclass_fromtext(&rdclass,
|
||||
(isc_textregion_t *)&tr);
|
||||
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fprintf (stderr,"Warning: invalid class: %s\n",
|
||||
isc_commandline_argument);
|
||||
else
|
||||
lookup->rdclass = rdclass;
|
||||
break;
|
||||
case 'a':
|
||||
strcpy (querytype, "any");
|
||||
lookup->rdtype = dns_rdatatype_any;
|
||||
short_form = ISC_FALSE;
|
||||
break;
|
||||
case 'w':
|
||||
@ -592,15 +610,14 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
tries = 1;
|
||||
break;
|
||||
case 'T':
|
||||
tcpmode = ISC_TRUE;
|
||||
lookup->tcp_mode = ISC_TRUE;
|
||||
break;
|
||||
case 'C':
|
||||
debug("showing all SOAs");
|
||||
if (querytype[0] == 0)
|
||||
strcpy(querytype, "soa");
|
||||
if (queryclass[0] == 0)
|
||||
strcpy(queryclass, "in");
|
||||
showallsoa = ISC_TRUE;
|
||||
lookup->rdtype = dns_rdatatype_soa;
|
||||
lookup->rdclass = dns_rdataclass_in;
|
||||
lookup->ns_search_only = ISC_TRUE;
|
||||
lookup->trace_root = ISC_TRUE;
|
||||
show_details = ISC_TRUE;
|
||||
break;
|
||||
case 'N':
|
||||
@ -623,7 +640,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
ISC_LIST_APPEND(server_list, srv, link);
|
||||
}
|
||||
|
||||
lookup = make_empty_lookup();
|
||||
lookup->pending = ISC_FALSE;
|
||||
/*
|
||||
* XXXMWS Add IPv6 translation here, probably using inet_pton
|
||||
@ -643,20 +659,10 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
strncat(lookup->textname, store, MXNAME);
|
||||
}
|
||||
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
|
||||
if (querytype[0] == 0)
|
||||
strcpy(querytype, "ptr");
|
||||
lookup->rdtype = dns_rdatatype_ptr;
|
||||
} else {
|
||||
strncpy(lookup->textname, hostname, MXNAME);
|
||||
}
|
||||
if (querytype[0] == 0)
|
||||
strcpy(querytype, "a");
|
||||
if (queryclass[0] == 0)
|
||||
strcpy(queryclass, "in");
|
||||
strncpy(lookup->rttext, querytype, 32);
|
||||
strncpy(lookup->rctext, queryclass, 32);
|
||||
lookup->ns_search_only = showallsoa;
|
||||
lookup->trace_root = showallsoa;
|
||||
lookup->tcp_mode = tcpmode;
|
||||
lookup->new_search = ISC_TRUE;
|
||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dig.h,v 1.35 2000/07/14 17:57:27 mws Exp $ */
|
||||
/* $Id: dig.h,v 1.36 2000/07/18 01:28:20 mws Exp $ */
|
||||
|
||||
#ifndef DIG_H
|
||||
#define DIG_H
|
||||
@ -43,8 +43,8 @@
|
||||
/*
|
||||
* Default timeout values
|
||||
*/
|
||||
#define TCP_TIMEOUT 60
|
||||
#define UDP_TIMEOUT 30
|
||||
#define TCP_TIMEOUT 10
|
||||
#define UDP_TIMEOUT 5
|
||||
|
||||
#define LOOKUP_LIMIT 64
|
||||
/*
|
||||
@ -92,8 +92,8 @@ struct dig_lookup {
|
||||
section_additional,
|
||||
new_search;
|
||||
char textname[MXNAME]; /* Name we're going to be looking up */
|
||||
char rttext[MXRD]; /* rdata type text */
|
||||
char rctext[MXRD]; /* rdata class text */
|
||||
dns_rdatatype_t rdtype;
|
||||
dns_rdataclass_t rdclass;
|
||||
char namespace[BUFSIZE];
|
||||
char onamespace[BUFSIZE];
|
||||
isc_buffer_t namebuf;
|
||||
@ -131,7 +131,6 @@ struct dig_query {
|
||||
first_repeat_rcvd;
|
||||
isc_uint32_t first_rr_serial;
|
||||
isc_uint32_t second_rr_serial;
|
||||
int retries;
|
||||
char *servname;
|
||||
isc_bufferlist_t sendlist,
|
||||
recvlist,
|
||||
@ -173,12 +172,6 @@ debug(const char *format, ...);
|
||||
void
|
||||
check_result(isc_result_t result, const char *msg);
|
||||
|
||||
isc_boolean_t
|
||||
isclass(char *text);
|
||||
|
||||
isc_boolean_t
|
||||
istype(char *text);
|
||||
|
||||
void
|
||||
setup_lookup(dig_lookup_t *lookup);
|
||||
|
||||
@ -191,9 +184,6 @@ start_lookup(void);
|
||||
void
|
||||
onrun_callback(isc_task_t *task, isc_event_t *event);
|
||||
|
||||
void
|
||||
send_udp(dig_lookup_t *lookup);
|
||||
|
||||
int
|
||||
dhmain(int argc, char **argv);
|
||||
|
||||
@ -203,9 +193,6 @@ setup_libs(void);
|
||||
void
|
||||
setup_system(void);
|
||||
|
||||
void
|
||||
free_lists(void);
|
||||
|
||||
dig_lookup_t *
|
||||
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: nslookup.c,v 1.25 2000/07/14 16:35:29 mws Exp $ */
|
||||
/* $Id: nslookup.c,v 1.26 2000/07/18 01:28:19 mws Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -23,11 +23,6 @@
|
||||
|
||||
extern int h_errno;
|
||||
|
||||
#include <dns/message.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatatype.h>
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/commandline.h>
|
||||
@ -38,6 +33,13 @@ extern int h_errno;
|
||||
#include <isc/util.h>
|
||||
#include <isc/task.h>
|
||||
|
||||
#include <dns/message.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdataclass.h>
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatatype.h>
|
||||
|
||||
#include <dig/dig.h>
|
||||
|
||||
extern ISC_LIST(dig_lookup_t) lookup_list;
|
||||
@ -533,7 +535,7 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
printsection(query, msg, headers, DNS_SECTION_ANSWER);
|
||||
|
||||
if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
|
||||
(strcasecmp(query->lookup->rttext,"a") != 0)) {
|
||||
(query->lookup->rdtype != dns_rdatatype_a)) {
|
||||
puts ("\nAuthorative answers can be found from:");
|
||||
printsection(query, msg, headers,
|
||||
DNS_SECTION_AUTHORITY);
|
||||
@ -570,19 +572,44 @@ show_settings(isc_boolean_t full) {
|
||||
printf ("\t %s\t\t\t%s\t\t%s\n",
|
||||
tcpmode?"vc":"novc", short_form?"nodebug":"debug",
|
||||
debugging?"d2":"nod2");
|
||||
printf ("\t %s\t\t%s\t\t%s\n",
|
||||
printf ("\t %s\t\t%s\t%s\n",
|
||||
defname?"defname":"nodefname",
|
||||
usesearch?"search":"nosearch",
|
||||
usesearch?"search ":"nosearch",
|
||||
recurse?"recurse":"norecurse");
|
||||
printf ("\t timeout = %d\t\tretry = %d\tport = %d\n",
|
||||
timeout, tries, port);
|
||||
printf ("\t querytype = %-8s\tclass=%s\n",deftype, defclass);
|
||||
printf ("\t querytype = %-8s\tclass = %s\n",deftype, defclass);
|
||||
#if 0
|
||||
printf ("\t domain = %s\n", fixeddomain);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static isc_boolean_t
|
||||
testtype(char *typetext) {
|
||||
isc_result_t result;
|
||||
isc_textregion_t tr;
|
||||
dns_rdatatype_t rdtype;
|
||||
|
||||
tr.base = typetext;
|
||||
tr.length = strlen(typetext);
|
||||
result = dns_rdatatype_fromtext(&rdtype, &tr);
|
||||
return (result == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_boolean_t
|
||||
testclass(char *typetext) {
|
||||
isc_result_t result;
|
||||
isc_textregion_t tr;
|
||||
dns_rdataclass_t rdclass;
|
||||
|
||||
tr.base = typetext;
|
||||
tr.length = strlen(typetext);
|
||||
result = dns_rdataclass_fromtext(&rdclass, &tr);
|
||||
return (result == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
setoption(char *opt) {
|
||||
|
||||
@ -593,9 +620,11 @@ setoption(char *opt) {
|
||||
} else if (strncasecmp(opt, "cl=", 3) == 0) {
|
||||
strncpy(defclass, &opt[3], MXRD);
|
||||
} else if (strncasecmp(opt, "type=", 5) == 0) {
|
||||
strncpy(deftype, &opt[5], MXRD);
|
||||
if (testtype(&opt[5]))
|
||||
strncpy(deftype, &opt[5], MXRD);
|
||||
} else if (strncasecmp(opt, "ty=", 3) == 0) {
|
||||
strncpy(deftype, &opt[3], MXRD);
|
||||
if (testclass(&opt[3]))
|
||||
strncpy(defclass, &opt[3], MXRD);
|
||||
} else if (strncasecmp(opt, "querytype=", 10) == 0) {
|
||||
strncpy(deftype, &opt[10], MXRD);
|
||||
} else if (strncasecmp(opt, "query=", 6) == 0) {
|
||||
@ -641,38 +670,32 @@ setoption(char *opt) {
|
||||
static void
|
||||
addlookup(char *opt) {
|
||||
dig_lookup_t *lookup;
|
||||
isc_result_t result;
|
||||
isc_textregion_t tr;
|
||||
dns_rdatatype_t rdtype;
|
||||
dns_rdataclass_t rdclass;
|
||||
|
||||
debug ("addlookup()");
|
||||
lookup = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
|
||||
if (lookup == NULL)
|
||||
fatal("Memory allocation failure.");
|
||||
lookup->pending = ISC_FALSE;
|
||||
tr.base = deftype;
|
||||
tr.length = strlen(deftype);
|
||||
result = dns_rdatatype_fromtext(&rdtype, &tr);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
tr.base = defclass;
|
||||
tr.length = strlen(defclass);
|
||||
result = dns_rdataclass_fromtext(&rdclass, &tr);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
lookup = make_empty_lookup();
|
||||
strncpy(lookup->textname, opt, MXNAME-1);
|
||||
strncpy (lookup->rttext, deftype, MXNAME);
|
||||
strncpy (lookup->rctext, defclass, MXNAME);
|
||||
lookup->namespace[0]=0;
|
||||
lookup->sendspace = NULL;
|
||||
lookup->sendmsg=NULL;
|
||||
lookup->name=NULL;
|
||||
lookup->oname=NULL;
|
||||
lookup->timer = NULL;
|
||||
lookup->xfr_q = NULL;
|
||||
lookup->origin = NULL;
|
||||
lookup->querysig = NULL;
|
||||
lookup->doing_xfr = ISC_FALSE;
|
||||
lookup->ixfr_serial = 0;
|
||||
lookup->defname = ISC_FALSE;
|
||||
lookup->rdtype = rdtype;
|
||||
lookup->rdclass = rdclass;
|
||||
lookup->trace = ISC_TF(trace || ns_search_only);
|
||||
lookup->trace_root = trace;
|
||||
lookup->ns_search_only = ns_search_only;
|
||||
lookup->identify = identify;
|
||||
lookup->recurse = recurse;
|
||||
lookup->aaonly = aaonly;
|
||||
lookup->adflag = ISC_FALSE;
|
||||
lookup->cdflag = ISC_FALSE;
|
||||
lookup->retries = tries;
|
||||
lookup->udpsize = bufsize;
|
||||
lookup->nsfound = 0;
|
||||
lookup->comments = comments;
|
||||
lookup->tcp_mode = tcpmode;
|
||||
lookup->stats = stats;
|
||||
@ -877,7 +900,7 @@ main(int argc, char **argv) {
|
||||
|
||||
puts ("");
|
||||
debug ("done, and starting to shut down");
|
||||
free_lists();
|
||||
destroy_libs();
|
||||
isc_mutex_destroy(&lock);
|
||||
isc_condition_destroy(&cond);
|
||||
if (taskmgr != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user