nslookup.c revision 688a4c50c2025a683d8d2bf5bb53a591556df4fc
/*
* Copyright (C) 2000, 2001 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.78 2001/01/18 05:12:43 gson Exp $ */
#include <config.h>
#include <stdlib.h>
extern int h_errno;
#include <isc/commandline.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/rdatatype.h>
extern isc_boolean_t have_ipv6,
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 int exitcode;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *global_task;
extern char *progname;
isc_uint16_t bufsize = 0;
char domainopt[DNS_NAME_MAXTEXT];
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 flush_lookup_list(void);
void
dighost_shutdown(void) {
debug("dighost_shutdown()");
if (!in_use) {
return;
}
}
void
}
void
}
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));
}
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);
}
isc_buffer_t *b = NULL;
isc_region_t r;
debug("printmessage()");
debug("continuing on with rcode != 0");
(char*)isc_buffer_base(b));
isc_buffer_free(&b);
puts("");
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);
}
if (!short_form){
puts("------------");
/* detailheader(query, msg);*/
puts("------------");
}
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
isc_buffer_t *b = NULL;
printf("Default server: %s\nAddress: %.*s\n",
(char*)isc_buffer_base(b));
isc_buffer_free(&b);
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 void
} else {
}
}
static void
debug("addlookup()");
if (result != ISC_R_SUCCESS) {
}
if (result != ISC_R_SUCCESS) {
}
lookup = make_empty_lookup();
} else {
}
ISC_LIST_INIT(lookup->q);
}
static void
flush_server_list(void) {
dig_server_t *s, *ps;
debug("flush_server_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
return;
}
fatal("Memory allocation failure.");
}
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
}
}
}
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 (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 (domainopt[0] != '\0')
if (in_use)
NULL);
else
(void)isc_app_run();
puts("");
debug("done, and starting to shut down");
if (global_event != NULL)
destroy_libs();
return (0);
}