nslookup.c revision cc48bb397fa6ba889f25157840492e68114dec8f
/*
* 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.
*/
/* $Id: nslookup.c,v 1.37 2000/09/01 21:54:23 bwelling Exp $ */
#include <config.h>
#include <stdlib.h>
extern int h_errno;
#include <isc/commandline.h>
#include <isc/condition.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
extern unsigned int timeout;
extern dns_messageid_t id;
extern isc_buffer_t rootbuf;
extern int sendcount;
extern int ndots;
extern int tries;
extern int lookup_counter;
extern char fixeddomain[MXNAME];
extern int exitcode;
extern isc_taskmgr_t *taskmgr;
extern char *progname;
isc_uint16_t bufsize = 0;
static const char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMPL",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
static const char *rtypetext[] = {
"rtype_0 = ", /* 0 */
"internet address = ", /* 1 */
"nameserver = ", /* 2 */
"md = ", /* 3 */
"mf = ", /* 4 */
"canonical name = ", /* 5 */
"soa = ", /* 6 */
"mb = ", /* 7 */
"mg = ", /* 8 */
"mr = ", /* 9 */
"rtype_10 = ", /* 10 */
"protocol = ", /* 11 */
"name = ", /* 12 */
"hinfo = ", /* 13 */
"minfo = ", /* 14 */
"mail exchanger = ", /* 15 */
"text = ", /* 16 */
"rp = ", /* 17 */
"afsdb = ", /* 18 */
"x25 address = ", /* 19 */
"isdn address = ", /* 20 */
"rt = ", /* 21 */
"nsap = ", /* 22 */
"nsap_ptr = ", /* 23 */
"signature = ", /* 24 */
"key = ", /* 25 */
"px = ", /* 26 */
"gpos = ", /* 27 */
"has AAAA address", /* 28 */
"loc = ", /* 29 */
"next = ", /* 30 */
"rtype_31 = ", /* 31 */
"rtype_32 = ", /* 32 */
"service = ", /* 33 */
"rtype_34 = ", /* 34 */
"naptr = ", /* 35 */
"kx = ", /* 36 */
"cert = ", /* 37 */
"v6 address = ", /* 38 */
"dname = ", /* 39 */
"rtype_40 = ", /* 40 */
"optional = "}; /* 41 */
static void
show_usage(void) {
}
void
dighost_shutdown(void) {
debug("dighost_shutdown()");
debug("signalling out");
}
void
}
void
}
static isc_result_t
isc_buffer_t *b = NULL;
char *ptr;
debug("printsection()");
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
&name);
while (loopresult == ISC_R_SUCCESS) {
case dns_rdatatype_a:
if (section != DNS_SECTION_ANSWER)
goto def_short_section;
isc_buffer_clear(b);
b);
"dns_name_totext");
printf("Name:\t%.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
isc_buffer_clear(b);
NULL,
b);
"dns_rdata_totext");
printf("Address: %.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
break;
case dns_rdatatype_soa:
isc_buffer_clear(b);
b);
"dns_name_totext");
printf("%.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
isc_buffer_clear(b);
NULL,
b);
"dns_rdata_totext");
((char *)isc_buffer_used(b))[0]=0;
" \t\r\n");
break;
printf("\torigin = %s\n",
ptr);
break;
printf("\tmail addr = %s\n",
ptr);
break;
break;
printf("\tserial = %s\n",
ptr);
break;
printf("\trefresh = %s\n",
ptr);
break;
printf("\tretry = %s\n",
ptr);
break;
printf("\texpire = %s\n",
ptr);
break;
printf("\tminimum = %s\n",
ptr);
break;
default:
isc_buffer_clear(b);
b);
"dns_name_totext");
printf("%.*s\t%s",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b),
else
printf("%.*s\trdata_%d = ",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b),
isc_buffer_clear(b);
NULL, b);
"dns_rdata_totext");
printf("%.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
}
}
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS) {
isc_buffer_free (&b);
return (result);
}
}
isc_buffer_free(&b);
return (ISC_R_SUCCESS);
}
static isc_result_t
isc_buffer_t *b = NULL;
char *ptr;
debug("detailsection()");
if (headers) {
switch (section) {
case DNS_SECTION_QUESTION:
puts(" QUESTIONS:");
break;
case DNS_SECTION_ANSWER:
puts(" ANSWERS:");
break;
case DNS_SECTION_AUTHORITY:
puts(" AUTHORITY RECORDS:");
break;
case DNS_SECTION_ADDITIONAL:
puts(" ADDITIONAL RECORDS:");
break;
}
}
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
&name);
while (loopresult == ISC_R_SUCCESS) {
isc_buffer_clear(b);
b);
"dns_name_totext");
printf(" -> %.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
case dns_rdatatype_soa:
isc_buffer_clear(b);
NULL,
b);
"dns_rdata_totext");
((char *)isc_buffer_used(b))[0]=0;
" \t\r\n");
break;
printf("\torigin = %s\n",
ptr);
break;
printf("\tmail addr = %s\n",
ptr);
break;
break;
printf("\tserial = %s\n",
ptr);
break;
printf("\trefresh = %s\n",
ptr);
break;
printf("\tretry = %s\n",
ptr);
break;
printf("\texpire = %s\n",
ptr);
break;
printf("\tminimum = %s\n",
ptr);
break;
default:
isc_buffer_clear(b);
printf("\t%s",
else
printf("\trdata_%d = ",
isc_buffer_clear(b);
NULL, b);
"dns_rdata_totext");
printf("%.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
}
}
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS) {
isc_buffer_free (&b);
return (result);
}
}
isc_buffer_free(&b);
return (ISC_R_SUCCESS);
}
isc_buffer_t *b = NULL;
isc_region_t r;
debug("printmessage()");
b);
isc_buffer_usedregion(b, &r);
printf("** server can't find %.*s: %s\n",
isc_buffer_free(&b);
debug("returning with rcode == 0");
return (ISC_R_SUCCESS);
}
debug("continuing on with rcode != 0");
(char*)isc_buffer_base(b));
isc_buffer_free(&b);
puts("");
if (!short_form){
puts("------------");
/* detailheader(query, msg);*/
puts("------------");
}
puts("Non-authorative answer:");
puts("\nAuthorative answers can be found from:");
}
return (ISC_R_SUCCESS);
}
static void
isc_buffer_t *b = NULL;
printf("Default server: %s\nAddress: %.*s\n",
(char*)isc_buffer_base(b));
isc_buffer_free(&b);
if (!full)
return;
}
printf("\n\tSet options:\n");
printf("\t %s\t\t\t%s\t\t%s\n",
printf("\t %s\t\t%s\t%s\n",
printf("\t timeout = %d\t\tretry = %d\tport = %d\n",
#if 0
#endif
}
static isc_boolean_t
}
static isc_boolean_t
}
static void
#if 0
/* XXXMWS domain= doesn't work now. */
#endif
} else {
}
}
static dig_lookup_t*
debug("addlookup()");
lookup = make_empty_lookup();
ISC_LIST_INIT(lookup->q);
return (lookup);
}
static void
flush_server_list(void) {
dig_server_t *s, *ps;
debug("flush_lookup_list()");
s = ISC_LIST_HEAD(server_list);
while (s != NULL) {
ps = s;
s = ISC_LIST_NEXT(s, link);
}
}
/*
* This works on the global server list, instead of on a per-lookup
* server list, since the change is persistent.
*/
static void
fatal("Memory allocation failure.");
}
static void
get_next_command(void) {
return;
}
return;
}
} else
}
static void
if (argv[0][0] == '-') {
(argv[0][2] == 0)) {
show_usage();
exit (1);
}
if (argv[0][1] != 0)
else
} else {
if (!have_lookup) {
}
else
}
}
}
static void
flush_lookup_list(void) {
dig_lookup_t *l, *lp;
dig_query_t *q, *qp;
dig_server_t *s, *sp;
lookup_counter = 0;
l = ISC_LIST_HEAD(lookup_list);
while (l != NULL) {
q = ISC_LIST_HEAD(l->q);
while (q != NULL) {
isc_socket_detach(&q->sock);
}
link);
link);
isc_buffer_invalidate(&q->recvbuf);
qp = q;
q = ISC_LIST_NEXT(q, link);
}
s = ISC_LIST_HEAD(l->my_server_list);
while (s != NULL) {
sp = s;
s = ISC_LIST_NEXT(s, link);
}
dns_message_destroy(&l->sendmsg);
isc_timer_detach(&l->timer);
lp = l;
l = ISC_LIST_NEXT(l, link);
}
}
int
setup_libs();
if (deprecation_msg) {
"Note: nslookup is deprecated and may be removed from future releases.\n"
"Consider using the `dig' or `host' programs instead. Run nslookup with\n"
"the `-sil[ent]' option to prevent this message from appearing.\n", stderr);
}
setup_system();
if (in_use) {
start_lookup();
while (busy) {
}
} else {
}
while (in_use) {
start_lookup();
while (busy) {
}
debug("out of the condition wait");
}
}
puts("");
debug("done, and starting to shut down");
destroy_libs();
DESTROYLOCK(&lock);
debug("freeing taskmgr");
}
if (isc_mem_debugging != 0)
return (0);
}