mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-28 13:08: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.
|
* 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 <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -30,6 +30,7 @@
|
|||||||
#include <dns/rdata.h>
|
#include <dns/rdata.h>
|
||||||
#include <dns/rdataset.h>
|
#include <dns/rdataset.h>
|
||||||
#include <dns/rdatatype.h>
|
#include <dns/rdatatype.h>
|
||||||
|
#include <dns/rdataclass.h>
|
||||||
|
|
||||||
#include <dig/dig.h>
|
#include <dig/dig.h>
|
||||||
|
|
||||||
@ -67,9 +68,13 @@ extern isc_boolean_t validated;
|
|||||||
extern isc_taskmgr_t *taskmgr;
|
extern isc_taskmgr_t *taskmgr;
|
||||||
extern isc_task_t *global_task;
|
extern isc_task_t *global_task;
|
||||||
extern isc_boolean_t free_now;
|
extern isc_boolean_t free_now;
|
||||||
|
dig_lookup_t *default_lookup = NULL;
|
||||||
|
|
||||||
extern isc_boolean_t debugging;
|
extern isc_boolean_t debugging;
|
||||||
extern isc_boolean_t isc_mem_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;
|
isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE;
|
||||||
|
|
||||||
@ -168,12 +173,6 @@ show_usage(void) {
|
|||||||
, stderr);
|
, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
dighost_shutdown(void) {
|
|
||||||
free_lists();
|
|
||||||
isc_app_shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||||
isc_uint64_t diff;
|
isc_uint64_t diff;
|
||||||
@ -540,13 +539,14 @@ reorder_args(int argc, char *argv[]) {
|
|||||||
static void
|
static void
|
||||||
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||||
isc_boolean_t have_host = ISC_FALSE;
|
isc_boolean_t have_host = ISC_FALSE;
|
||||||
|
isc_result_t result;
|
||||||
|
isc_textregion_t tr;
|
||||||
dig_server_t *srv = NULL, *s, *s2;
|
dig_server_t *srv = NULL, *s, *s2;
|
||||||
dig_lookup_t *lookup = NULL;
|
dig_lookup_t *lookup = NULL;
|
||||||
static dig_lookup_t *default_lookup = NULL;
|
dns_rdatatype_t rdtype;
|
||||||
char *batchname = NULL;
|
dns_rdataclass_t rdclass;
|
||||||
char batchline[MXNAME];
|
char batchline[MXNAME];
|
||||||
char address[MXNAME];
|
char address[MXNAME];
|
||||||
FILE *fp = NULL;
|
|
||||||
int bargc;
|
int bargc;
|
||||||
char *bargv[16];
|
char *bargv[16];
|
||||||
int i, n;
|
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_additional = ISC_FALSE;
|
||||||
lookup->section_authority = ISC_FALSE;
|
lookup->section_authority = ISC_FALSE;
|
||||||
lookup->section_question = ISC_FALSE;
|
lookup->section_question = ISC_FALSE;
|
||||||
strcpy(lookup->rttext, "soa");
|
lookup->rdtype = dns_rdatatype_soa;
|
||||||
short_form = ISC_TRUE;
|
short_form = ISC_TRUE;
|
||||||
} else if (strncmp(rv[0], "+nons", 6) == 0) {
|
} else if (strncmp(rv[0], "+nons", 6) == 0) {
|
||||||
lookup->ns_search_only = ISC_FALSE;
|
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;
|
lookup->comments = ISC_FALSE;
|
||||||
} else if (strncmp(rv[0], "-c", 2) == 0) {
|
} else if (strncmp(rv[0], "-c", 2) == 0) {
|
||||||
if (rv[0][2] != 0) {
|
if (rv[0][2] != 0) {
|
||||||
strncpy(lookup->rctext, &rv[0][2],
|
ptr = &rv[0][2];
|
||||||
MXRD);
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(lookup->rctext, rv[1],
|
ptr = rv[1];
|
||||||
MXRD);
|
|
||||||
rv++;
|
rv++;
|
||||||
rc--;
|
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) {
|
} else if (strncmp(rv[0], "-t", 2) == 0) {
|
||||||
if (rv[0][2] != 0) {
|
if (rv[0][2] != 0) {
|
||||||
strncpy(lookup->rttext, &rv[0][2],
|
ptr = &rv[0][2];
|
||||||
MXRD);
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(lookup->rttext, rv[1],
|
ptr = rv[1];
|
||||||
MXRD);
|
|
||||||
rv++;
|
rv++;
|
||||||
rc--;
|
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) {
|
} else if (strncmp(rv[0], "-f", 2) == 0) {
|
||||||
if (rv[0][2] != 0) {
|
if (rv[0][2] != 0) {
|
||||||
batchname = &rv[0][2];
|
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);
|
debug("looking up %s", lookup->textname);
|
||||||
lookup->trace_root = ISC_TF(lookup->trace ||
|
lookup->trace_root = ISC_TF(lookup->trace ||
|
||||||
lookup->ns_search_only);
|
lookup->ns_search_only);
|
||||||
strcpy(lookup->rttext, "ptr");
|
lookup->rdtype = dns_rdatatype_ptr;
|
||||||
strcpy(lookup->rctext, "in");
|
lookup->rdclass = dns_rdataclass_in;
|
||||||
lookup->new_search = ISC_TRUE;
|
lookup->new_search = ISC_TRUE;
|
||||||
|
|
||||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||||
@ -862,18 +885,25 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
|||||||
rv++;
|
rv++;
|
||||||
rc--;
|
rc--;
|
||||||
} else {
|
} else {
|
||||||
|
tr.base = rv[0];
|
||||||
|
tr.length = strlen(rv[0]);
|
||||||
if (strncmp(rv[0], "ixfr=", 5) == 0) {
|
if (strncmp(rv[0], "ixfr=", 5) == 0) {
|
||||||
strcpy(lookup->rttext, "ixfr");
|
lookup->rdtype = dns_rdatatype_ixfr;
|
||||||
lookup->ixfr_serial =
|
lookup->ixfr_serial =
|
||||||
atoi(&rv[0][5]);
|
atoi(&rv[0][5]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (istype(rv[0])) {
|
result = dns_rdatatype_fromtext(&rdtype,
|
||||||
strncpy(lookup->rttext, rv[0], MXRD);
|
(isc_textregion_t *)&tr);
|
||||||
|
if ((result == ISC_R_SUCCESS) &&
|
||||||
|
(rdtype != dns_rdatatype_ixfr)) {
|
||||||
|
lookup->rdtype = rdtype;
|
||||||
continue;
|
continue;
|
||||||
} else if (isclass(rv[0])) {
|
}
|
||||||
strncpy(lookup->rctext, rv[0],
|
result = dns_rdataclass_fromtext(&rdclass,
|
||||||
MXRD);
|
(isc_textregion_t *)&tr);
|
||||||
|
if (result == ISC_R_SUCCESS) {
|
||||||
|
lookup->rdclass = rdclass;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lookup=clone_lookup(default_lookup, ISC_TRUE);
|
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);
|
debug("looking up %s", lookup->textname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (batchname != NULL) {
|
/*
|
||||||
fp = fopen(batchname, "r");
|
* If we have a batchfile, seed the lookup list with the
|
||||||
if (fp == NULL) {
|
* 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);
|
perror(batchname);
|
||||||
if (exitcode < 10)
|
if (exitcode < 10)
|
||||||
exitcode = 10;
|
exitcode = 10;
|
||||||
fatal("Couldn't open specified batch file");
|
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);
|
debug("batch line %s", batchline);
|
||||||
bargc = 1;
|
bargc = 1;
|
||||||
bargv[bargc] = strtok(batchline, " \t\r\n");
|
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];
|
bargv[0] = argv[0];
|
||||||
|
argv0 = argv[0];
|
||||||
|
|
||||||
reorder_args(bargc, (char **)bargv);
|
reorder_args(bargc, (char **)bargv);
|
||||||
parse_args(ISC_TRUE, 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->ns_search_only);
|
||||||
lookup->new_search = ISC_TRUE;
|
lookup->new_search = ISC_TRUE;
|
||||||
strcpy(lookup->textname, ".");
|
strcpy(lookup->textname, ".");
|
||||||
strcpy(lookup->rttext, "NS");
|
lookup->rdtype = dns_rdatatype_ns;
|
||||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||||
}
|
}
|
||||||
if (!is_batchfile) {
|
if (!is_batchfile) {
|
||||||
@ -930,7 +966,47 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
|||||||
(dig_server_t *)s2, link);
|
(dig_server_t *)s2, link);
|
||||||
isc_mem_free(mctx, s2);
|
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);
|
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
|
||||||
check_result(result, "isc_app_onrun");
|
check_result(result, "isc_app_onrun");
|
||||||
isc_app_run();
|
isc_app_run();
|
||||||
|
isc_mem_free(mctx, default_lookup);
|
||||||
|
if (batchname != NULL) {
|
||||||
|
fclose(batchfp);
|
||||||
|
batchname = NULL;
|
||||||
|
}
|
||||||
cancel_all();
|
cancel_all();
|
||||||
destroy_libs();
|
destroy_libs();
|
||||||
isc_app_finish();
|
isc_app_finish();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* 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
|
* 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 recvcount = 0;
|
||||||
int sockcount = 0;
|
int sockcount = 0;
|
||||||
int ndots = -1;
|
int ndots = -1;
|
||||||
int tries = 3;
|
int tries = 2;
|
||||||
int lookup_counter = 0;
|
int lookup_counter = 0;
|
||||||
char fixeddomain[MXNAME] = "";
|
char fixeddomain[MXNAME] = "";
|
||||||
int exitcode = 9;
|
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 *
|
dig_server_t *
|
||||||
make_server(const char *servname) {
|
make_server(const char *servname) {
|
||||||
dig_server_t *srv;
|
dig_server_t *srv;
|
||||||
@ -291,8 +246,8 @@ make_empty_lookup(void) {
|
|||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__);
|
||||||
looknew->pending = ISC_TRUE;
|
looknew->pending = ISC_TRUE;
|
||||||
looknew->textname[0]=0;
|
looknew->textname[0]=0;
|
||||||
looknew->rttext[0]=0;
|
looknew->rdtype=dns_rdatatype_a;
|
||||||
looknew->rctext[0]=0;
|
looknew->rdclass=dns_rdataclass_in;
|
||||||
looknew->sendspace = NULL;
|
looknew->sendspace = NULL;
|
||||||
looknew->sendmsg = NULL;
|
looknew->sendmsg = NULL;
|
||||||
looknew->name = NULL;
|
looknew->name = NULL;
|
||||||
@ -343,8 +298,8 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
|
|||||||
looknew = make_empty_lookup();
|
looknew = make_empty_lookup();
|
||||||
INSIST(looknew != NULL);
|
INSIST(looknew != NULL);
|
||||||
strncpy(looknew->textname, lookold-> textname, MXNAME);
|
strncpy(looknew->textname, lookold-> textname, MXNAME);
|
||||||
strncpy(looknew->rttext, lookold-> rttext, 32);
|
looknew->rdtype = lookold->rdtype;
|
||||||
strncpy(looknew->rctext, lookold-> rctext, 32);
|
looknew->rdclass = lookold->rdclass;
|
||||||
looknew->doing_xfr = lookold->doing_xfr;
|
looknew->doing_xfr = lookold->doing_xfr;
|
||||||
looknew->ixfr_serial = lookold->ixfr_serial;
|
looknew->ixfr_serial = lookold->ixfr_serial;
|
||||||
looknew->defname = lookold->defname;
|
looknew->defname = lookold->defname;
|
||||||
@ -1055,12 +1010,9 @@ void
|
|||||||
setup_lookup(dig_lookup_t *lookup) {
|
setup_lookup(dig_lookup_t *lookup) {
|
||||||
isc_result_t result, res2;
|
isc_result_t result, res2;
|
||||||
int len;
|
int len;
|
||||||
dns_rdatatype_t rdtype;
|
|
||||||
dns_rdataclass_t rdclass;
|
|
||||||
dig_server_t *serv;
|
dig_server_t *serv;
|
||||||
dig_query_t *query;
|
dig_query_t *query;
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
isc_constregion_t tr;
|
|
||||||
isc_buffer_t b;
|
isc_buffer_t b;
|
||||||
char store[MXNAME];
|
char store[MXNAME];
|
||||||
|
|
||||||
@ -1167,10 +1119,6 @@ setup_lookup(dig_lookup_t *lookup) {
|
|||||||
isc_buffer_usedregion(&b, &r);
|
isc_buffer_usedregion(&b, &r);
|
||||||
trying((int)r.length, (char *)r.base, lookup);
|
trying((int)r.length, (char *)r.base, lookup);
|
||||||
ENSURE(dns_name_isabsolute(lookup->name));
|
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->id = (unsigned short)(random() & 0xFFFF);
|
||||||
lookup->sendmsg->opcode = dns_opcode_query;
|
lookup->sendmsg->opcode = dns_opcode_query;
|
||||||
@ -1203,36 +1151,21 @@ setup_lookup(dig_lookup_t *lookup) {
|
|||||||
DNS_SECTION_QUESTION);
|
DNS_SECTION_QUESTION);
|
||||||
|
|
||||||
if (lookup->trace_root) {
|
if (lookup->trace_root) {
|
||||||
debug("doing trace_root");
|
lookup->rdtype = dns_rdatatype_soa;
|
||||||
tr.base = "SOA";
|
lookup->rdclass = dns_rdataclass_in;
|
||||||
tr.length = 3;
|
|
||||||
} else {
|
|
||||||
tr.base = lookup->rttext;
|
|
||||||
tr.length = strlen(lookup->rttext);
|
|
||||||
}
|
}
|
||||||
debug("data type is %s", lookup->rttext);
|
if ((lookup->rdtype == dns_rdatatype_axfr) ||
|
||||||
result = dns_rdatatype_fromtext(&rdtype, (isc_textregion_t *)&tr);
|
(lookup->rdtype == dns_rdatatype_ixfr)) {
|
||||||
check_result(result, "dns_rdatatype_fromtext");
|
|
||||||
if ((rdtype == dns_rdatatype_axfr) ||
|
|
||||||
(rdtype == dns_rdatatype_ixfr)) {
|
|
||||||
lookup->doing_xfr = ISC_TRUE;
|
lookup->doing_xfr = ISC_TRUE;
|
||||||
/*
|
/*
|
||||||
* Force TCP mode if we're doing an xfr.
|
* Force TCP mode if we're doing an xfr.
|
||||||
*/
|
*/
|
||||||
lookup->tcp_mode = ISC_TRUE;
|
lookup->tcp_mode = ISC_TRUE;
|
||||||
}
|
}
|
||||||
if (lookup->trace_root) {
|
add_question(lookup->sendmsg, lookup->name, lookup->rdclass,
|
||||||
tr.base = "IN";
|
lookup->rdtype);
|
||||||
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);
|
|
||||||
|
|
||||||
if (rdtype == dns_rdatatype_ixfr)
|
if (lookup->rdtype == dns_rdatatype_ixfr)
|
||||||
insert_soa(lookup);
|
insert_soa(lookup);
|
||||||
|
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
@ -1283,7 +1216,6 @@ setup_lookup(dig_lookup_t *lookup) {
|
|||||||
query->second_rr_rcvd = ISC_FALSE;
|
query->second_rr_rcvd = ISC_FALSE;
|
||||||
query->second_rr_serial = 0;
|
query->second_rr_serial = 0;
|
||||||
query->servname = serv->servername;
|
query->servname = serv->servername;
|
||||||
ISC_LIST_INIT(query->sendlist);
|
|
||||||
ISC_LIST_INIT(query->recvlist);
|
ISC_LIST_INIT(query->recvlist);
|
||||||
ISC_LIST_INIT(query->lengthlist);
|
ISC_LIST_INIT(query->lengthlist);
|
||||||
query->sock = NULL;
|
query->sock = NULL;
|
||||||
@ -1362,46 +1294,65 @@ recv_done(isc_task_t *task, isc_event_t *event);
|
|||||||
static void
|
static void
|
||||||
connect_timeout(isc_task_t *task, isc_event_t *event);
|
connect_timeout(isc_task_t *task, isc_event_t *event);
|
||||||
|
|
||||||
void
|
static void
|
||||||
send_udp(dig_lookup_t *lookup) {
|
send_udp(dig_lookup_t *lookup, isc_boolean_t make_recv) {
|
||||||
dig_query_t *query;
|
dig_query_t *query;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
unsigned int local_timeout;
|
unsigned int local_timeout;
|
||||||
|
|
||||||
debug("send_udp()");
|
debug("send_udp()");
|
||||||
|
|
||||||
if (timeout != INT_MAX) {
|
/*
|
||||||
if (timeout == 0) {
|
* If the timer already exists, that means we're calling this
|
||||||
if (lookup->tcp_mode)
|
* a second time (for a retry). Don't need to recreate it,
|
||||||
local_timeout = TCP_TIMEOUT;
|
* just reset it.
|
||||||
else
|
*/
|
||||||
|
if (lookup->timer == NULL) {
|
||||||
|
if (timeout != INT_MAX) {
|
||||||
|
if (timeout == 0) {
|
||||||
local_timeout = UDP_TIMEOUT;
|
local_timeout = UDP_TIMEOUT;
|
||||||
} else
|
} else
|
||||||
local_timeout = timeout;
|
local_timeout = timeout;
|
||||||
debug("have local timeout of %d", local_timeout);
|
debug("have local timeout of %d", local_timeout);
|
||||||
isc_interval_set(&lookup->interval, local_timeout, 0);
|
isc_interval_set(&lookup->interval, local_timeout, 0);
|
||||||
result = isc_timer_create(timermgr, isc_timertype_once, NULL,
|
result = isc_timer_create(timermgr,
|
||||||
&lookup->interval, global_task,
|
isc_timertype_once, NULL,
|
||||||
connect_timeout, lookup,
|
&lookup->interval,
|
||||||
&lookup->timer);
|
global_task,
|
||||||
check_result(result, "isc_timer_create");
|
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);
|
for (query = ISC_LIST_HEAD(lookup->q);
|
||||||
query != NULL;
|
query != NULL;
|
||||||
query = ISC_LIST_NEXT(query, link)) {
|
query = ISC_LIST_NEXT(query, link)) {
|
||||||
debug("working on lookup %p, query %p",
|
debug("working on lookup %p, query %p",
|
||||||
query->lookup, query);
|
query->lookup, query);
|
||||||
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link);
|
if (make_recv) {
|
||||||
query->working = ISC_TRUE;
|
ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf,
|
||||||
debug("recving with lookup=%p, query=%p, sock=%p",
|
link);
|
||||||
query->lookup, query,
|
query->working = ISC_TRUE;
|
||||||
query->sock);
|
debug("recving with lookup=%p, query=%p, sock=%p",
|
||||||
result = isc_socket_recvv(query->sock, &query->recvlist, 1,
|
query->lookup, query,
|
||||||
global_task, recv_done, query);
|
query->sock);
|
||||||
check_result(result, "isc_socket_recvv");
|
result = isc_socket_recvv(query->sock,
|
||||||
recvcount++;
|
&query->recvlist, 1,
|
||||||
debug("recvcount=%d", recvcount);
|
global_task, recv_done,
|
||||||
ISC_LIST_ENQUEUE(query->sendlist, &lookup->sendbuf, link);
|
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");
|
debug("sending a request");
|
||||||
result = isc_time_now(&query->time_sent);
|
result = isc_time_now(&query->time_sent);
|
||||||
check_result(result, "isc_time_now");
|
check_result(result, "isc_time_now");
|
||||||
@ -1420,11 +1371,8 @@ send_udp(dig_lookup_t *lookup) {
|
|||||||
static void
|
static void
|
||||||
connect_timeout(isc_task_t *task, isc_event_t *event) {
|
connect_timeout(isc_task_t *task, isc_event_t *event) {
|
||||||
dig_lookup_t *lookup=NULL;
|
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);
|
REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
|
||||||
|
|
||||||
debug("connect_timeout()");
|
debug("connect_timeout()");
|
||||||
@ -1433,44 +1381,22 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
|
|||||||
lookup = event->ev_arg;
|
lookup = event->ev_arg;
|
||||||
isc_event_free(&event);
|
isc_event_free(&event);
|
||||||
|
|
||||||
debug("buffer allocate connect_timeout");
|
INSIST(!free_now);
|
||||||
result = isc_buffer_allocate(mctx, &b, 256);
|
if (lookup->retries > 1) {
|
||||||
check_result(result, "isc_buffer_allocate");
|
if (!lookup->tcp_mode) {
|
||||||
for (q = ISC_LIST_HEAD(lookup->q);
|
lookup->retries--;
|
||||||
q != NULL;
|
debug("resending UDP request");
|
||||||
q = ISC_LIST_NEXT(q, link)) {
|
send_udp(lookup, ISC_FALSE);
|
||||||
if (q->working) {
|
} else {
|
||||||
INSIST(!free_now);
|
debug("making new TCP request");
|
||||||
isc_buffer_clear(b);
|
cancel_lookup(lookup);
|
||||||
result = isc_sockaddr_totext(&q->sockaddr, b);
|
lookup->retries--;
|
||||||
check_result(result, "isc_sockaddr_totext");
|
requeue_lookup(lookup, ISC_TRUE);
|
||||||
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(lookup->timer != NULL);
|
else {
|
||||||
isc_timer_detach(&lookup->timer);
|
cancel_lookup(lookup);
|
||||||
isc_buffer_free(&b);
|
}
|
||||||
debug("done with connect_timeout()");
|
|
||||||
UNLOCK_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->slbuf);
|
||||||
isc_buffer_clear(&query->lengthbuf);
|
isc_buffer_clear(&query->lengthbuf);
|
||||||
isc_buffer_putuint16(&query->slbuf, query->lookup->sendbuf.used);
|
isc_buffer_putuint16(&query->slbuf, query->lookup->sendbuf.used);
|
||||||
|
ISC_LIST_INIT(query->sendlist);
|
||||||
ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
|
ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
|
||||||
if (include_question) {
|
if (include_question) {
|
||||||
ISC_LIST_ENQUEUE(query->sendlist, &query->lookup->sendbuf,
|
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);
|
dns_message_destroy(&msg);
|
||||||
clear_query(query);
|
clear_query(query);
|
||||||
cancel_lookup(l);
|
cancel_lookup(l);
|
||||||
|
check_next_lookup(l);
|
||||||
}
|
}
|
||||||
if (msg != NULL)
|
if (msg != NULL)
|
||||||
dns_message_destroy(&msg);
|
dns_message_destroy(&msg);
|
||||||
@ -2163,10 +2091,7 @@ do_lookup_tcp(dig_lookup_t *lookup) {
|
|||||||
lookup->pending = ISC_TRUE;
|
lookup->pending = ISC_TRUE;
|
||||||
if (timeout != INT_MAX) {
|
if (timeout != INT_MAX) {
|
||||||
if (timeout == 0) {
|
if (timeout == 0) {
|
||||||
if (lookup->tcp_mode)
|
|
||||||
local_timeout = TCP_TIMEOUT;
|
local_timeout = TCP_TIMEOUT;
|
||||||
else
|
|
||||||
local_timeout = UDP_TIMEOUT;
|
|
||||||
} else
|
} else
|
||||||
local_timeout = timeout;
|
local_timeout = timeout;
|
||||||
debug("have local timeout of %d", local_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");
|
check_result(result, "isc_socket_bind");
|
||||||
}
|
}
|
||||||
|
|
||||||
send_udp(lookup);
|
send_udp(lookup, ISC_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -2392,10 +2317,3 @@ destroy_libs(void) {
|
|||||||
if (mctx != NULL)
|
if (mctx != NULL)
|
||||||
isc_mem_destroy(&mctx);
|
isc_mem_destroy(&mctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Dummy function, soon to go away
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
free_lists(void) {
|
|
||||||
}
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* 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 <config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -32,7 +32,9 @@ extern int h_errno;
|
|||||||
#include <dns/message.h>
|
#include <dns/message.h>
|
||||||
#include <dns/name.h>
|
#include <dns/name.h>
|
||||||
#include <dns/rdata.h>
|
#include <dns/rdata.h>
|
||||||
|
#include <dns/rdataclass.h>
|
||||||
#include <dns/rdataset.h>
|
#include <dns/rdataset.h>
|
||||||
|
#include <dns/rdatatype.h>
|
||||||
|
|
||||||
#include <dig/dig.h>
|
#include <dig/dig.h>
|
||||||
|
|
||||||
@ -58,10 +60,7 @@ extern char *progname;
|
|||||||
extern isc_task_t *global_task;
|
extern isc_task_t *global_task;
|
||||||
|
|
||||||
isc_boolean_t
|
isc_boolean_t
|
||||||
short_form = ISC_TRUE,
|
short_form = ISC_TRUE;
|
||||||
filter = ISC_FALSE,
|
|
||||||
showallsoa = ISC_FALSE,
|
|
||||||
tcpmode = ISC_FALSE;
|
|
||||||
|
|
||||||
static const char *opcodetext[] = {
|
static const char *opcodetext[] = {
|
||||||
"QUERY",
|
"QUERY",
|
||||||
@ -231,7 +230,6 @@ show_usage(void) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
dighost_shutdown(void) {
|
dighost_shutdown(void) {
|
||||||
free_lists();
|
|
||||||
isc_app_shutdown();
|
isc_app_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,40 +536,60 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||||
isc_boolean_t recursion = ISC_TRUE;
|
|
||||||
char hostname[MXNAME];
|
char hostname[MXNAME];
|
||||||
char querytype[32] = "";
|
|
||||||
char queryclass[32] = "";
|
|
||||||
dig_server_t *srv;
|
dig_server_t *srv;
|
||||||
dig_lookup_t *lookup;
|
dig_lookup_t *lookup;
|
||||||
int i, c, n, adrs[4];
|
int i, c, n, adrs[4];
|
||||||
char store[MXNAME];
|
char store[MXNAME];
|
||||||
|
isc_textregion_t tr;
|
||||||
|
isc_result_t result;
|
||||||
|
dns_rdatatype_t rdtype;
|
||||||
|
dns_rdataclass_t rdclass;
|
||||||
|
|
||||||
UNUSED(is_batchfile);
|
UNUSED(is_batchfile);
|
||||||
|
|
||||||
|
lookup = make_empty_lookup();
|
||||||
|
|
||||||
while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
|
while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
|
||||||
!= EOF) {
|
!= EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'l':
|
case 'l':
|
||||||
tcpmode = ISC_TRUE;
|
lookup->tcp_mode = ISC_TRUE;
|
||||||
filter = ISC_TRUE;
|
lookup->rdtype = dns_rdatatype_axfr;
|
||||||
strcpy(querytype, "axfr");
|
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
case 'd':
|
case 'd':
|
||||||
short_form = ISC_FALSE;
|
short_form = ISC_FALSE;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
recursion = ISC_FALSE;
|
lookup->recurse = ISC_FALSE;
|
||||||
break;
|
break;
|
||||||
case 't':
|
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;
|
break;
|
||||||
case 'c':
|
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;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
strcpy (querytype, "any");
|
lookup->rdtype = dns_rdatatype_any;
|
||||||
short_form = ISC_FALSE;
|
short_form = ISC_FALSE;
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -592,15 +610,14 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
|||||||
tries = 1;
|
tries = 1;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
tcpmode = ISC_TRUE;
|
lookup->tcp_mode = ISC_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
debug("showing all SOAs");
|
debug("showing all SOAs");
|
||||||
if (querytype[0] == 0)
|
lookup->rdtype = dns_rdatatype_soa;
|
||||||
strcpy(querytype, "soa");
|
lookup->rdclass = dns_rdataclass_in;
|
||||||
if (queryclass[0] == 0)
|
lookup->ns_search_only = ISC_TRUE;
|
||||||
strcpy(queryclass, "in");
|
lookup->trace_root = ISC_TRUE;
|
||||||
showallsoa = ISC_TRUE;
|
|
||||||
show_details = ISC_TRUE;
|
show_details = ISC_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
@ -623,7 +640,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
|||||||
ISC_LIST_APPEND(server_list, srv, link);
|
ISC_LIST_APPEND(server_list, srv, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup = make_empty_lookup();
|
|
||||||
lookup->pending = ISC_FALSE;
|
lookup->pending = ISC_FALSE;
|
||||||
/*
|
/*
|
||||||
* XXXMWS Add IPv6 translation here, probably using inet_pton
|
* 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, store, MXNAME);
|
||||||
}
|
}
|
||||||
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
|
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
|
||||||
if (querytype[0] == 0)
|
lookup->rdtype = dns_rdatatype_ptr;
|
||||||
strcpy(querytype, "ptr");
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(lookup->textname, hostname, MXNAME);
|
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;
|
lookup->new_search = ISC_TRUE;
|
||||||
ISC_LIST_APPEND(lookup_list, lookup, link);
|
ISC_LIST_APPEND(lookup_list, lookup, link);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* 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
|
#ifndef DIG_H
|
||||||
#define DIG_H
|
#define DIG_H
|
||||||
@ -43,8 +43,8 @@
|
|||||||
/*
|
/*
|
||||||
* Default timeout values
|
* Default timeout values
|
||||||
*/
|
*/
|
||||||
#define TCP_TIMEOUT 60
|
#define TCP_TIMEOUT 10
|
||||||
#define UDP_TIMEOUT 30
|
#define UDP_TIMEOUT 5
|
||||||
|
|
||||||
#define LOOKUP_LIMIT 64
|
#define LOOKUP_LIMIT 64
|
||||||
/*
|
/*
|
||||||
@ -92,8 +92,8 @@ struct dig_lookup {
|
|||||||
section_additional,
|
section_additional,
|
||||||
new_search;
|
new_search;
|
||||||
char textname[MXNAME]; /* Name we're going to be looking up */
|
char textname[MXNAME]; /* Name we're going to be looking up */
|
||||||
char rttext[MXRD]; /* rdata type text */
|
dns_rdatatype_t rdtype;
|
||||||
char rctext[MXRD]; /* rdata class text */
|
dns_rdataclass_t rdclass;
|
||||||
char namespace[BUFSIZE];
|
char namespace[BUFSIZE];
|
||||||
char onamespace[BUFSIZE];
|
char onamespace[BUFSIZE];
|
||||||
isc_buffer_t namebuf;
|
isc_buffer_t namebuf;
|
||||||
@ -131,7 +131,6 @@ struct dig_query {
|
|||||||
first_repeat_rcvd;
|
first_repeat_rcvd;
|
||||||
isc_uint32_t first_rr_serial;
|
isc_uint32_t first_rr_serial;
|
||||||
isc_uint32_t second_rr_serial;
|
isc_uint32_t second_rr_serial;
|
||||||
int retries;
|
|
||||||
char *servname;
|
char *servname;
|
||||||
isc_bufferlist_t sendlist,
|
isc_bufferlist_t sendlist,
|
||||||
recvlist,
|
recvlist,
|
||||||
@ -173,12 +172,6 @@ debug(const char *format, ...);
|
|||||||
void
|
void
|
||||||
check_result(isc_result_t result, const char *msg);
|
check_result(isc_result_t result, const char *msg);
|
||||||
|
|
||||||
isc_boolean_t
|
|
||||||
isclass(char *text);
|
|
||||||
|
|
||||||
isc_boolean_t
|
|
||||||
istype(char *text);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
setup_lookup(dig_lookup_t *lookup);
|
setup_lookup(dig_lookup_t *lookup);
|
||||||
|
|
||||||
@ -191,9 +184,6 @@ start_lookup(void);
|
|||||||
void
|
void
|
||||||
onrun_callback(isc_task_t *task, isc_event_t *event);
|
onrun_callback(isc_task_t *task, isc_event_t *event);
|
||||||
|
|
||||||
void
|
|
||||||
send_udp(dig_lookup_t *lookup);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
dhmain(int argc, char **argv);
|
dhmain(int argc, char **argv);
|
||||||
|
|
||||||
@ -203,9 +193,6 @@ setup_libs(void);
|
|||||||
void
|
void
|
||||||
setup_system(void);
|
setup_system(void);
|
||||||
|
|
||||||
void
|
|
||||||
free_lists(void);
|
|
||||||
|
|
||||||
dig_lookup_t *
|
dig_lookup_t *
|
||||||
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
|
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* 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>
|
#include <config.h>
|
||||||
|
|
||||||
@ -23,11 +23,6 @@
|
|||||||
|
|
||||||
extern int h_errno;
|
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/app.h>
|
||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
#include <isc/commandline.h>
|
#include <isc/commandline.h>
|
||||||
@ -38,6 +33,13 @@ extern int h_errno;
|
|||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
#include <isc/task.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>
|
#include <dig/dig.h>
|
||||||
|
|
||||||
extern ISC_LIST(dig_lookup_t) lookup_list;
|
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);
|
printsection(query, msg, headers, DNS_SECTION_ANSWER);
|
||||||
|
|
||||||
if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
|
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:");
|
puts ("\nAuthorative answers can be found from:");
|
||||||
printsection(query, msg, headers,
|
printsection(query, msg, headers,
|
||||||
DNS_SECTION_AUTHORITY);
|
DNS_SECTION_AUTHORITY);
|
||||||
@ -570,19 +572,44 @@ show_settings(isc_boolean_t full) {
|
|||||||
printf ("\t %s\t\t\t%s\t\t%s\n",
|
printf ("\t %s\t\t\t%s\t\t%s\n",
|
||||||
tcpmode?"vc":"novc", short_form?"nodebug":"debug",
|
tcpmode?"vc":"novc", short_form?"nodebug":"debug",
|
||||||
debugging?"d2":"nod2");
|
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",
|
defname?"defname":"nodefname",
|
||||||
usesearch?"search":"nosearch",
|
usesearch?"search ":"nosearch",
|
||||||
recurse?"recurse":"norecurse");
|
recurse?"recurse":"norecurse");
|
||||||
printf ("\t timeout = %d\t\tretry = %d\tport = %d\n",
|
printf ("\t timeout = %d\t\tretry = %d\tport = %d\n",
|
||||||
timeout, tries, port);
|
timeout, tries, port);
|
||||||
printf ("\t querytype = %-8s\tclass=%s\n",deftype, defclass);
|
printf ("\t querytype = %-8s\tclass = %s\n",deftype, defclass);
|
||||||
#if 0
|
#if 0
|
||||||
printf ("\t domain = %s\n", fixeddomain);
|
printf ("\t domain = %s\n", fixeddomain);
|
||||||
#endif
|
#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
|
static void
|
||||||
setoption(char *opt) {
|
setoption(char *opt) {
|
||||||
|
|
||||||
@ -593,9 +620,11 @@ setoption(char *opt) {
|
|||||||
} else if (strncasecmp(opt, "cl=", 3) == 0) {
|
} else if (strncasecmp(opt, "cl=", 3) == 0) {
|
||||||
strncpy(defclass, &opt[3], MXRD);
|
strncpy(defclass, &opt[3], MXRD);
|
||||||
} else if (strncasecmp(opt, "type=", 5) == 0) {
|
} 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) {
|
} 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) {
|
} else if (strncasecmp(opt, "querytype=", 10) == 0) {
|
||||||
strncpy(deftype, &opt[10], MXRD);
|
strncpy(deftype, &opt[10], MXRD);
|
||||||
} else if (strncasecmp(opt, "query=", 6) == 0) {
|
} else if (strncasecmp(opt, "query=", 6) == 0) {
|
||||||
@ -641,38 +670,32 @@ setoption(char *opt) {
|
|||||||
static void
|
static void
|
||||||
addlookup(char *opt) {
|
addlookup(char *opt) {
|
||||||
dig_lookup_t *lookup;
|
dig_lookup_t *lookup;
|
||||||
|
isc_result_t result;
|
||||||
|
isc_textregion_t tr;
|
||||||
|
dns_rdatatype_t rdtype;
|
||||||
|
dns_rdataclass_t rdclass;
|
||||||
|
|
||||||
debug ("addlookup()");
|
debug ("addlookup()");
|
||||||
lookup = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
|
tr.base = deftype;
|
||||||
if (lookup == NULL)
|
tr.length = strlen(deftype);
|
||||||
fatal("Memory allocation failure.");
|
result = dns_rdatatype_fromtext(&rdtype, &tr);
|
||||||
lookup->pending = ISC_FALSE;
|
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->textname, opt, MXNAME-1);
|
||||||
strncpy (lookup->rttext, deftype, MXNAME);
|
lookup->rdtype = rdtype;
|
||||||
strncpy (lookup->rctext, defclass, MXNAME);
|
lookup->rdclass = rdclass;
|
||||||
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->trace = ISC_TF(trace || ns_search_only);
|
lookup->trace = ISC_TF(trace || ns_search_only);
|
||||||
lookup->trace_root = trace;
|
lookup->trace_root = trace;
|
||||||
lookup->ns_search_only = ns_search_only;
|
lookup->ns_search_only = ns_search_only;
|
||||||
lookup->identify = identify;
|
lookup->identify = identify;
|
||||||
lookup->recurse = recurse;
|
lookup->recurse = recurse;
|
||||||
lookup->aaonly = aaonly;
|
lookup->aaonly = aaonly;
|
||||||
lookup->adflag = ISC_FALSE;
|
|
||||||
lookup->cdflag = ISC_FALSE;
|
|
||||||
lookup->retries = tries;
|
lookup->retries = tries;
|
||||||
lookup->udpsize = bufsize;
|
lookup->udpsize = bufsize;
|
||||||
lookup->nsfound = 0;
|
|
||||||
lookup->comments = comments;
|
lookup->comments = comments;
|
||||||
lookup->tcp_mode = tcpmode;
|
lookup->tcp_mode = tcpmode;
|
||||||
lookup->stats = stats;
|
lookup->stats = stats;
|
||||||
@ -877,7 +900,7 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
puts ("");
|
puts ("");
|
||||||
debug ("done, and starting to shut down");
|
debug ("done, and starting to shut down");
|
||||||
free_lists();
|
destroy_libs();
|
||||||
isc_mutex_destroy(&lock);
|
isc_mutex_destroy(&lock);
|
||||||
isc_condition_destroy(&cond);
|
isc_condition_destroy(&cond);
|
||||||
if (taskmgr != NULL) {
|
if (taskmgr != NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user