nslookup.c revision 96eeb9496c09114c116132d5a493ef5eb88e3192
/*
* Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2003 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.119 2008/12/16 23:47:57 tbox Exp $ */
#include <config.h>
#include <stdlib.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>
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);
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];
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");
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\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
}
static isc_result_t
const char *desc) {
isc_uint32_t n;
if (result != ISC_R_SUCCESS) {
return result;
}
*uip = n;
return (ISC_R_SUCCESS);
}
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
/* 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
get_next_command(void) {
char *buf;
char *input;
fatal("memory allocation failure");
goto cleanup;
}
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
} else
}
static void
if (argv[0][0] == '-') {
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();
setup_system();
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 (0);
}