nslookup.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/commandline.h>
#include <isc/parseint.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/rdatatype.h>
#if defined(HAVE_READLINE)
#include <readline/readline.h>
#endif
static isc_boolean_t interactive;
static char domainopt[DNS_NAME_MAXTEXT];
static const char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"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 flush_lookup_list(void);
static char *
{
static char buf[sizeof("?65535")];
union {
const char *consttext;
char *deconsttext;
} totext;
} else
return totext.deconsttext;
}
void
dighost_shutdown(void) {
debug("dighost_shutdown()");
if (!in_use) {
return;
}
}
static void
char namebuf[DNS_NAME_FORMATSIZE];
}
static void
char text[sizeof("255.255.255.255")];
isc_buffer_t b;
(char *)isc_buffer_base(&b));
}
#ifdef DIG_SIGCHASE
/* Just for compatibility : not use in host program */
{
return(ISC_FALSE);
}
#endif
static void
isc_buffer_t *b = NULL;
unsigned int size = 1024;
else
while (!done) {
if (result != ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
(char *)isc_buffer_base(b));
} else if (result != ISC_R_NOSPACE)
isc_buffer_free(&b);
size *= 2;
}
}
static isc_result_t
char namebuf[DNS_NAME_FORMATSIZE];
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;
sizeof(namebuf));
break;
case dns_rdatatype_soa:
sizeof(namebuf));
break;
default:
sizeof(namebuf));
printrdata(&rdata);
break;
}
}
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
}
static isc_result_t
char namebuf[DNS_NAME_FORMATSIZE];
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);
if (section == DNS_SECTION_QUESTION) {
sizeof(namebuf));
sizeof(namebuf));
sizeof(namebuf));
}
while (loopresult == ISC_R_SUCCESS) {
sizeof(namebuf));
case dns_rdatatype_soa:
break;
default:
printf("\t");
printrdata(&rdata);
}
}
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
}
void
{
}
void
}
char servtext[ISC_SOCKADDR_FORMATSIZE];
/* I've we've gotten this far, we've reached a server. */
query_error = 0;
debug("printmessage()");
puts("");
if (!short_form) {
puts("------------");
/* detailheader(query, msg);*/
puts("------------");
}
char nametext[DNS_NAME_FORMATSIZE];
printf("** server can't find %s: %s\n",
debug("returning with rcode == 0");
/* the lookup failed */
print_error |= 1;
return (ISC_R_SUCCESS);
}
puts("Non-authoritative answer:");
else
printf("*** Can't find %s: No answer\n",
puts("\nAuthoritative answers can be found from:");
}
return (ISC_R_SUCCESS);
}
static void
char sockstr[ISC_SOCKADDR_FORMATSIZE];
printf("Default server: %s\nAddress: %s\n",
if (!full)
return;
}
if (serv_only)
return;
printf("\nSet options:\n");
printf(" %s\t\t\t%s\t\t%s\n",
printf(" %s\t\t%s\n",
printf(" timeout = %d\t\tretry = %d\tport = %d\tndots = %d\n",
printf(" srchlist = ");
printf("/");
}
printf("\n");
}
static isc_boolean_t
if (result == ISC_R_SUCCESS)
return (ISC_TRUE);
else {
return (ISC_FALSE);
}
}
static isc_boolean_t
if (result == ISC_R_SUCCESS)
return (ISC_TRUE);
else {
return (ISC_FALSE);
}
}
static void
isc_uint32_t n;
if (result == ISC_R_SUCCESS)
port = (isc_uint16_t) n;
}
static void
set_timeout(const char *value) {
isc_uint32_t n;
if (result == ISC_R_SUCCESS)
timeout = n;
}
static void
isc_uint32_t n;
if (result == ISC_R_SUCCESS)
tries = n;
}
static void
isc_uint32_t n;
if (result == ISC_R_SUCCESS)
ndots = n;
}
static void
version(void) {
}
static void
/* deprecation_msg = ISC_FALSE; */
} else {
}
}
static void
debug("addlookup()");
if (result != ISC_R_SUCCESS) {
}
if (result != ISC_R_SUCCESS) {
}
lookup = make_empty_lookup();
== ISC_R_SUCCESS) {
} else {
}
if (nofail)
ISC_LIST_INIT(lookup->q);
}
static void
do_next_command(char *input) {
return;
} else
}
static void
get_next_command(void) {
char *buf;
char *ptr;
fatal("memory allocation failure");
if (interactive) {
#ifdef HAVE_READLINE
#else
#endif
} else
} else
#ifdef HAVE_READLINE
if (interactive)
#endif
}
static void
if (argv[0][0] == '-') {
version();
exit(0);
} else if (argv[0][1] != 0) {
} else
} else {
if (!have_lookup) {
} else {
set_nameserver(argv[0]);
}
}
}
}
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);
}
}
static void
if (global_event == NULL)
while (in_use) {
start_lookup();
return;
}
}
}
int
result = isc_app_start();
setup_libs();
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
if (domainopt[0] != '\0')
if (in_use)
NULL);
else
(void)isc_app_run();
puts("");
debug("done, and starting to shut down");
if (global_event != NULL)
cancel_all();
destroy_libs();
return (query_error | print_error);
}