Commit cefd6800 authored by Michael Sawyer's avatar Michael Sawyer
Browse files

Host was broken in last commit; fixed here.

Add nslookup.c; non-functional and not compiled by make all.
parent e893dce9
......@@ -55,6 +55,9 @@ dig: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
host: host.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ host.@O@ dighost.@O@ ${UOBJS} ${LIBS}
nslookup: nslookup.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ nslookup.@O@ dighost.@O@ ${UOBJS} ${LIBS}
clean distclean::
rm -f ${TARGETS}
......
......@@ -34,6 +34,7 @@ extern int h_errno;
extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t tcp_mode, have_ipv6, show_details,
usesearch, trace, qr;
......@@ -979,3 +980,43 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
}
printgreeting (argc, argv);
}
int
main(int argc, char **argv) {
dig_lookup_t *lookup = NULL;
#ifdef TWIDDLE
FILE *fp;
int i, p;
#endif
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug ("dhmain()");
#ifdef TWIDDLE
fp = fopen("/dev/urandom", "r");
if (fp!=NULL) {
fread (&i, sizeof(int), 1, fp);
srandom(i);
}
else {
srandom ((int)&main);
}
p = getpid()%16+8;
for (i=0 ; i<p; i++);
#endif
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
lookup = ISC_LIST_HEAD(lookup_list);
setup_lookup(lookup);
if (tcp_mode)
do_lookup_tcp(lookup);
else
do_lookup_udp(lookup);
isc_app_run();
free_lists(0);
return (0);
}
......@@ -74,9 +74,6 @@ int lookup_counter = 0;
char fixeddomain[MXNAME]="";
int exitcode = 9;
static void
free_lists(void);
static int
count_dots(char *string) {
char *s;
......@@ -117,9 +114,11 @@ fatal(char *format, ...) {
vfprintf(stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
if (exitcode == 0)
exitcode = 8;
#ifdef NEVER
isc_app_shutdown();
free_lists();
free_lists(exitcode);
if (mctx != NULL) {
#ifdef MEMDEBUG
isc_mem_stats(mctx, stderr);
......@@ -227,7 +226,7 @@ twiddlebuf(isc_buffer_t buf) {
}
#endif
static void
void
setup_system(void) {
char rcinput[MXNAME];
FILE *fp;
......@@ -254,6 +253,8 @@ setup_system(void) {
* does NOT insure that id's cann't be guessed.
*/
srandom (getpid() + (int)&setup_system);
free_now = ISC_FALSE;
get_servers = (server_list.head == NULL);
fp = fopen (RESOLVCONF, "r");
if (fp != NULL) {
......@@ -364,7 +365,7 @@ setup_system(void) {
}
}
static void
void
setup_libs(void) {
isc_result_t result;
isc_buffer_t b;
......@@ -1495,8 +1496,8 @@ do_lookup_udp(dig_lookup_t *lookup) {
send_udp(lookup);
}
static void
free_lists(void) {
void
free_lists(int exitcode) {
void *ptr;
dig_lookup_t *l;
dig_query_t *q;
......@@ -1576,47 +1577,6 @@ free_lists(void) {
if (mctx != NULL)
isc_mem_destroy(&mctx);
exit(exitcode);
}
int
main(int argc, char **argv) {
dig_lookup_t *lookup = NULL;
#ifdef TWIDDLE
FILE *fp;
int i, p;
#endif
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
#ifdef TWIDDLE
fp = fopen("/dev/urandom", "r");
if (fp!=NULL) {
fread (&i, sizeof(int), 1, fp);
srandom(i);
}
else {
srandom ((int)&main);
}
p = getpid()%16+8;
for (i=0 ; i<p; i++);
#endif
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
lookup = ISC_LIST_HEAD(lookup_list);
setup_lookup(lookup);
if (tcp_mode)
do_lookup_tcp(lookup);
else
do_lookup_udp(lookup);
isc_app_run();
free_lists();
/*
* Should never get here.
*/
return (2);
if (exitcode != 0)
exit(exitcode);
}
......@@ -610,7 +610,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
* XXXMWS Add IPv6 translation here, probably using inet_pton
* to extract the formatted text.
*/
if (strcspn(hostname, "0123456789.") != strlen(hostname)) {
if (strspn(hostname, "0123456789.") == strlen(hostname)) {
lookup->textname[0]=0;
n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
......@@ -649,6 +649,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->ns_search_only = showallsoa;
lookup->use_my_server_list = ISC_FALSE;
lookup->retries = tries;
lookup->udpsize = 0;
lookup->nsfound = 0;
lookup->trace = showallsoa;
lookup->trace_root = ISC_FALSE;
......@@ -659,3 +660,42 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
have_host = ISC_TRUE;
}
int
main(int argc, char **argv) {
dig_lookup_t *lookup = NULL;
#ifdef TWIDDLE
FILE *fp;
int i, p;
#endif
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug ("dhmain()");
#ifdef TWIDDLE
fp = fopen("/dev/urandom", "r");
if (fp!=NULL) {
fread (&i, sizeof(int), 1, fp);
srandom(i);
}
else {
srandom ((int)&main);
}
p = getpid()%16+8;
for (i=0 ; i<p; i++);
#endif
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
lookup = ISC_LIST_HEAD(lookup_list);
setup_lookup(lookup);
if (tcp_mode)
do_lookup_tcp(lookup);
else
do_lookup_udp(lookup);
isc_app_run();
free_lists(0);
return (0);
}
......@@ -148,6 +148,15 @@ void
do_lookup_tcp (dig_lookup_t *lookup);
void
send_udp(dig_lookup_t *lookup);
int
dhmain(int argc, char **argv);
void
setup_libs(void);
void
setup_system(void);
void
free_lists(int exitcode);
/* Routines needed in dig.c and host.c */
void
......
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <stdlib.h>
extern int h_errno;
#include <isc/app.h>
#include <isc/string.h>
#include <isc/util.h>
#include <isc/mutex.h>
#include <isc/condition.h>
#include <isc/commandline.h>
#include <dns/message.h>
#include <dns/rdata.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#include <dig/dig.h>
extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t tcp_mode, have_ipv6, show_details,
usesearch, trace, qr;
extern in_port_t port;
extern unsigned int timeout;
extern isc_mem_t *mctx;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *task;
extern isc_timermgr_t *timermgr;
extern isc_socketmgr_t *socketmgr;
extern dns_messageid_t id;
extern char *rootspace[BUFSIZE];
extern isc_buffer_t rootbuf;
extern int sendcount;
extern int ndots;
extern int tries;
extern int lookup_counter;
extern char fixeddomain[MXNAME];
#ifdef TWIDDLE
extern isc_boolean_t twiddle;
#endif
extern int exitcode;
isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
filter = ISC_FALSE, showallsoa = ISC_FALSE;
isc_uint16_t bufsize = 0;
isc_boolean_t identify = ISC_FALSE,
trace = ISC_FALSE, ns_search_only = ISC_FALSE,
forcecomment = ISC_FALSE, stats = ISC_TRUE,
comments = ISC_TRUE, section_question = ISC_TRUE,
section_answer = ISC_TRUE, section_authority = ISC_TRUE,
section_additional = ISC_TRUE, recurse = ISC_TRUE,
defname = ISC_TRUE, aaonly = ISC_FALSE;
isc_mutex_t lock;
isc_condition_t cond;
isc_boolean_t busy = ISC_FALSE, arg_lookup = ISC_FALSE;
static char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
static char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMPL",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
static void
show_usage() {
fputs (
"Usage:\n"
, stderr);
}
void
check_next_lookup(dig_lookup_t *lookup) {
dig_lookup_t *next;
dig_query_t *query;
isc_boolean_t still_working=ISC_FALSE;
debug("In check_next_lookup", stderr);
for (query = ISC_LIST_HEAD(lookup->q);
query != NULL;
query = ISC_LIST_NEXT(query, link)) {
if (query->working) {
debug("Still have a worker.", stderr);
still_working=ISC_TRUE;
}
}
if (still_working)
return;
next = ISC_LIST_NEXT(lookup, link);
debug ("Have %d retries left for %s\n",
lookup->retries, lookup->textname);
if ((next == NULL)&&((lookup->retries <= 1)
||tcp_mode || !lookup->pending)) {
debug("Shutting Down.", stderr);
isc_mutex_lock(&lock);
busy = ISC_FALSE;
isc_condition_signal(&cond);
isc_mutex_unlock(&lock);
return;
}
if (tcp_mode) {
setup_lookup(next);
do_lookup_tcp(next);
} else {
if ((lookup->retries > 1) && (lookup->pending)) {
lookup->retries --;
send_udp(lookup);
} else {
ENSURE (next != NULL);
setup_lookup(next);
do_lookup_udp(next);
}
}
}
void
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
isc_uint64_t diff;
isc_time_t now;
isc_result_t result;
time_t tnow;
result = isc_time_now(&now);
check_result (result, "isc_time_now");
if (query->lookup->stats) {
diff = isc_time_microdiff(&now, &query->time_sent);
printf(";; Query time: %ld msec\n", (long int)diff/1000);
printf(";; SERVER: %.*s\n", frmsize, frm);
time (&tnow);
printf(";; WHEN: %s", ctime(&tnow));
printf (";; MSG SIZE rcvd: %d\n\n", bytes);
} else if (query->lookup->identify && !short_form) {
diff = isc_time_microdiff(&now, &query->time_sent);
printf(";; Received %u bytes from %.*s in %d ms\n",
bytes, frmsize, frm, (int)diff/1000);
}
}
void
trying(int frmsize, char *frm, dig_lookup_t *lookup) {
UNUSED (frmsize);
UNUSED (frm);
UNUSED (lookup);
}
static void
say_message(dns_rdata_t *rdata, dig_query_t *query) {
isc_buffer_t *b=NULL, *b2=NULL;
isc_region_t r, r2;
isc_result_t result;
isc_uint64_t diff;
isc_time_t now;
result = isc_buffer_allocate(mctx, &b, BUFSIZE);
check_result (result, "isc_buffer_allocate");
result = dns_rdata_totext(rdata, NULL, b);
check_result(result, "dns_rdata_totext");
isc_buffer_usedregion(b, &r);
if (!query->lookup->trace && !query->lookup->ns_search_only)
printf ( "%.*s", (int)r.length, (char *)r.base);
else {
result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
check_result (result, "isc_buffer_allocate");
result = dns_rdatatype_totext(rdata->type, b2);
check_result(result, "dns_rdatatype_totext");
isc_buffer_usedregion(b2, &r2);
printf ( "%.*s %.*s",(int)r2.length, (char *)r2.base,
(int)r.length, (char *)r.base);
isc_buffer_free (&b2);
}
if (query->lookup->identify) {
result = isc_time_now(&now);
check_result (result, "isc_time_now");
diff = isc_time_microdiff(&now, &query->time_sent);
printf (" from server %s in %d ms", query->servname,
(int)diff/1000);
}
printf ("\n");
isc_buffer_free(&b);
}
static isc_result_t
printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
isc_boolean_t headers, dig_query_t *query)
{
dns_name_t *name, *print_name;
dns_rdataset_t *rdataset;
isc_buffer_t target;
isc_result_t result, loopresult;
isc_region_t r;
dns_name_t empty_name;
char t[4096];
isc_boolean_t first;
isc_boolean_t no_rdata;
dns_rdata_t rdata;
if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE;
else
no_rdata = ISC_FALSE;
if (headers && query->lookup->comments && !short_form)
printf(";; %s SECTION:\n", section_name);
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, sectionid);
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
name = NULL;
dns_message_currentname(msg, sectionid, &name);
isc_buffer_init(&target, t, sizeof(t));
first = ISC_TRUE;
print_name = name;
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) {
if (!short_form) {
result = dns_rdataset_totext(rdataset,
print_name,
ISC_FALSE,
no_rdata,
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
first = ISC_FALSE;
}
#endif
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
say_message(&rdata, query);
loopresult = dns_rdataset_next(
rdataset);
}
}
}
isc_buffer_usedregion(&target, &r);
if (no_rdata)
printf(";%.*s", (int)r.length, (char *)r.base);
else
printf("%.*s", (int)r.length, (char *)r.base);
result = dns_message_nextname(msg, sectionid);
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
char *set_name, isc_boolean_t headers)
{
isc_buffer_t target;
isc_result_t result;
isc_region_t r;
char t[4096];
UNUSED(msg);
if (headers)
printf(";; %s SECTION:\n", set_name);
isc_buffer_init(&target, t, sizeof(t));
result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
printf("%.*s", (int)r.length, (char *)r.base);
return (ISC_R_SUCCESS);
}
isc_result_t
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
isc_boolean_t did_flag = ISC_FALSE;
isc_result_t result;
dns_rdataset_t *opt, *tsig = NULL;
dns_name_t *tsigname;
UNUSED (query);
/*
* Exitcode 9 means we timed out, but if we're printing a message,
* we much have recovered. Go ahead and reset it to code 0, and
* call this a success.
*/
if (exitcode == 9)
exitcode = 0;
result = ISC_R_SUCCESS;
if (query->lookup->comments && !short_form) {
if (msg == query->lookup->sendmsg)
printf (";; Sending:\n");
else
printf (";; Got answer:\n");
}
if (headers) {
if (query->lookup->comments && !short_form) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, "
"id: %u\n",
opcodetext[msg->opcode], rcodetext[msg->rcode],
msg->id);
printf(";; flags: ");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {