nslookup.c revision da5d1cf1b1aa29ae53a0427be49291b04bd60549
99e207809793732e3e47da3a1cab6925b6eee8e9William King/*
c1aef54e14bb92518b1c062ba8c0292a7cb949cbAutomatic Updater * Copyright (C) 2000, 2001 Internet Software Consortium.
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
99e207809793732e3e47da3a1cab6925b6eee8e9William King * copyright notice and this permission notice appear in all copies.
99e207809793732e3e47da3a1cab6925b6eee8e9William King *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews/* $Id: nslookup.c,v 1.95 2001/12/19 12:16:42 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <config.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <stdlib.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#include <isc/app.h>
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#include <isc/buffer.h>
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#include <isc/commandline.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/event.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/parseint.h>
b9e8ad0f49b416afda1e752aa5c3910f8aa34fffAndreas Gustafsson#include <isc/string.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/timer.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/util.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/task.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/netaddr.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/message.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King#include <dns/name.h>
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#include <dns/fixedname.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/rdata.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/rdataclass.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/rdataset.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/rdatastruct.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/rdatatype.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#include <dns/byaddr.h>
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews#include <dig/dig.h>
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceextern ISC_LIST(dig_lookup_t) lookup_list;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceextern ISC_LIST(dig_server_t) server_list;
1d8abe0521c8e084dfcdd821173c10e0b416aeb3Mark Andrewsextern ISC_LIST(dig_searchlist_t) search_list;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceextern isc_boolean_t usesearch, debugging;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceextern in_port_t port;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingextern unsigned int timeout;
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrenceextern isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingextern int tries;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingextern int lookup_counter;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingextern isc_task_t *global_task;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrenceextern char *progname;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_boolean_t short_form = ISC_TRUE,
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence tcpmode = ISC_FALSE, deprecation_msg = ISC_TRUE,
99e207809793732e3e47da3a1cab6925b6eee8e9William King identify = ISC_FALSE, stats = ISC_TRUE,
99e207809793732e3e47da3a1cab6925b6eee8e9William King comments = ISC_TRUE, section_question = ISC_TRUE,
99e207809793732e3e47da3a1cab6925b6eee8e9William King section_answer = ISC_TRUE, section_authority = ISC_TRUE,
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson section_additional = ISC_TRUE, recurse = ISC_TRUE,
99e207809793732e3e47da3a1cab6925b6eee8e9William King aaonly = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_boolean_t in_use = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic char defclass[MXRD] = "IN";
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic char deftype[MXRD] = "A";
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_event_t *global_event = NULL;
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic char domainopt[DNS_NAME_MAXTEXT];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonstatic const char *rcodetext[] = {
99e207809793732e3e47da3a1cab6925b6eee8e9William King "NOERROR",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "FORMERR",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "SERVFAIL",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "NXDOMAIN",
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrence "NOTIMP",
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews "REFUSED",
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "YXDOMAIN",
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "YXRRSET",
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson "NXRRSET",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "NOTAUTH",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "NOTZONE",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "RESERVED11",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "RESERVED12",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "RESERVED13",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "RESERVED14",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "RESERVED15",
99e207809793732e3e47da3a1cab6925b6eee8e9William King "BADVERS"
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence};
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *rtypetext[] = {
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_0 = ", /* 0 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "internet address = ", /* 1 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "nameserver = ", /* 2 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "md = ", /* 3 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "mf = ", /* 4 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "canonical name = ", /* 5 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "soa = ", /* 6 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "mb = ", /* 7 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "mg = ", /* 8 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "mr = ", /* 9 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_10 = ", /* 10 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "protocol = ", /* 11 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "name = ", /* 12 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "hinfo = ", /* 13 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "minfo = ", /* 14 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "mail exchanger = ", /* 15 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "text = ", /* 16 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rp = ", /* 17 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "afsdb = ", /* 18 */
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "x25 address = ", /* 19 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "isdn address = ", /* 20 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rt = ", /* 21 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "nsap = ", /* 22 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "nsap_ptr = ", /* 23 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "signature = ", /* 24 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "key = ", /* 25 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "px = ", /* 26 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "gpos = ", /* 27 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "has AAAA address ", /* 28 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "loc = ", /* 29 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "next = ", /* 30 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_31 = ", /* 31 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_32 = ", /* 32 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "service = ", /* 33 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_34 = ", /* 34 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "naptr = ", /* 35 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "kx = ", /* 36 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "cert = ", /* 37 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "v6 address = ", /* 38 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "dname = ", /* 39 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "rtype_40 = ", /* 40 */
99e207809793732e3e47da3a1cab6925b6eee8e9William King "optional = " /* 41 */
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley};
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define N_KNOWN_RRTYPES (sizeof(rtypetext) / sizeof(rtypetext[0]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void flush_lookup_list(void);
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void getinput(isc_task_t *task, isc_event_t *event);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingvoid
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingdighost_shutdown(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event = global_event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King flush_lookup_list();
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley debug("dighost_shutdown()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (!in_use) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_app_shutdown();
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_send(global_task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingprintsoa(dns_rdata_t *rdata) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdata_soa_t soa;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char namebuf[DNS_NAME_FORMATSIZE];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdata_tostruct(rdata, &soa, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King check_result(result, "dns_rdata_tostruct");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(&soa.origin, namebuf, sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\torigin = %s\n", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(&soa.contact, namebuf, sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\tmail addr = %s\n", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\tserial = %u\n", soa.serial);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\trefresh = %u\n", soa.refresh);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\tretry = %u\n", soa.retry);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\texpire = %u\n", soa.expire);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\tminimum = %u\n", soa.minimum);
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdata_freestruct(&soa);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingprinta(dns_rdata_t *rdata) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char text[sizeof("255.255.255.255")];
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_t b;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_init(&b, text, sizeof(text));
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdata_totext(rdata, NULL, &b);
99e207809793732e3e47da3a1cab6925b6eee8e9William King check_result(result, "dns_rdata_totext");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("Address: %.*s\n", (int)isc_buffer_usedlength(&b),
99e207809793732e3e47da3a1cab6925b6eee8e9William King (char *)isc_buffer_base(&b));
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingprintrdata(dns_rdata_t *rdata) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_t *b = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int size = 1024;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_boolean_t done = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (rdata->type < N_KNOWN_RRTYPES)
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("%s", rtypetext[rdata->type]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("rdata_%d = ", rdata->type);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (!done) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = isc_buffer_allocate(mctx, &b, size);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result != ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King check_result(result, "isc_buffer_allocate");
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdata_totext(rdata, NULL, b);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("%.*s\n", (int)isc_buffer_usedlength(b),
99e207809793732e3e47da3a1cab6925b6eee8e9William King (char *)isc_buffer_base(b));
99e207809793732e3e47da3a1cab6925b6eee8e9William King done = ISC_TRUE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else if (result != ISC_R_NOSPACE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King check_result(result, "dns_rdata_totext");
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_free(&b);
99e207809793732e3e47da3a1cab6925b6eee8e9William King size *= 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_result_t
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingprintsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_section_t section) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result, loopresult;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_t *name;
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson dns_rdataset_t *rdataset = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdata_t rdata = DNS_RDATA_INIT;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char namebuf[DNS_NAME_FORMATSIZE];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(query);
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(headers);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William King debug("printsection()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson result = dns_message_firstname(msg, section);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_NOMORE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (result != ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (;;) {
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley name = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_message_currentname(msg, section,
99e207809793732e3e47da3a1cab6925b6eee8e9William King &name);
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King rdataset != NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King rdataset = ISC_LIST_NEXT(rdataset, link)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King loopresult = dns_rdataset_first(rdataset);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (loopresult == ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataset_current(rdataset, &rdata);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley switch (rdata.type) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King case dns_rdatatype_a:
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (section != DNS_SECTION_ANSWER)
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson goto def_short_section;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(name, namebuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("Name:\t%s\n", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printa(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley case dns_rdatatype_soa:
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(name, namebuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King sizeof(namebuf));
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson printf("%s\n", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printsoa(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King default:
99e207809793732e3e47da3a1cab6925b6eee8e9William King def_short_section:
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(name, namebuf,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("%s\t", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printrdata(&rdata);
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdata_reset(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King loopresult = dns_rdataset_next(rdataset);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley result = dns_message_nextname(msg, section);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_NOMORE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson else if (result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_result_t
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingdetailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson dns_section_t section) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result, loopresult;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_t *name;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataset_t *rdataset = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdata_t rdata = DNS_RDATA_INIT;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char namebuf[DNS_NAME_FORMATSIZE];
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(query);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson debug("detailsection()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (headers) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King switch (section) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King case DNS_SECTION_QUESTION:
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts(" QUESTIONS:");
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King case DNS_SECTION_ANSWER:
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts(" ANSWERS:");
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King case DNS_SECTION_AUTHORITY:
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts(" AUTHORITY RECORDS:");
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King case DNS_SECTION_ADDITIONAL:
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts(" ADDITIONAL RECORDS:");
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_message_firstname(msg, section);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_NOMORE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (result != ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (result);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley for (;;) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King name = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_message_currentname(msg, section,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson &name);
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (rdataset = ISC_LIST_HEAD(name->list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King rdataset != NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King rdataset = ISC_LIST_NEXT(rdataset, link)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (section == DNS_SECTION_QUESTION) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(name, namebuf,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\t%s, ", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdatatype_format(rdataset->type,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson namebuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("type = %s, ", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataclass_format(rdataset->rdclass,
99e207809793732e3e47da3a1cab6925b6eee8e9William King namebuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King sizeof(namebuf));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley printf("class = %s\n", namebuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King loopresult = dns_rdataset_first(rdataset);
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson while (loopresult == ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataset_current(rdataset, &rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(name, namebuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King sizeof(namebuf));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf(" -> %s\n", namebuf);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley
99e207809793732e3e47da3a1cab6925b6eee8e9William King switch (rdata.type) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King case dns_rdatatype_soa:
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson printsoa(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King default:
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\t");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printrdata(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley dns_rdata_reset(&rdata);
99e207809793732e3e47da3a1cab6925b6eee8e9William King loopresult = dns_rdataset_next(rdataset);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_message_nextname(msg, section);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_NOMORE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King break;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencevoid
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query)
99e207809793732e3e47da3a1cab6925b6eee8e9William King{
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(bytes);
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(from);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence UNUSED(query);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencevoid
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingtrying(char *frm, dig_lookup_t *lookup) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(frm);
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews UNUSED(lookup);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingisc_result_t
e1bb80ea30482d37abf16cd9621045f873c57e74William Kingprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King char servtext[ISC_SOCKADDR_FORMATSIZE];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King debug("printmessage()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("Server:\t\t%s\n", query->servname);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("Address:\t%s\n", servtext);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts("");
93a16701383bbc91e6915d41d1ed827ce8b92246William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (!short_form) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_boolean_t headers = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts("------------");
99e207809793732e3e47da3a1cab6925b6eee8e9William King /* detailheader(query, msg);*/
99e207809793732e3e47da3a1cab6925b6eee8e9William King detailsection(query, msg, headers, DNS_SECTION_QUESTION);
99e207809793732e3e47da3a1cab6925b6eee8e9William King detailsection(query, msg, headers, DNS_SECTION_ANSWER);
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews detailsection(query, msg, headers, DNS_SECTION_AUTHORITY);
99e207809793732e3e47da3a1cab6925b6eee8e9William King detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff puts("------------");
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (msg->rcode != 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King char nametext[DNS_NAME_FORMATSIZE];
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_name_format(query->lookup->name,
99e207809793732e3e47da3a1cab6925b6eee8e9William King nametext, sizeof(nametext));
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("** server can't find %s: %s\n", nametext,
99e207809793732e3e47da3a1cab6925b6eee8e9William King rcodetext[msg->rcode]);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence debug("returning with rcode == 0");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts("Non-authoritative answer:");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King printsection(query, msg, headers, DNS_SECTION_ANSWER);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence else
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("*** Can't find %s: No answer\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King query->lookup->textname);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
99e207809793732e3e47da3a1cab6925b6eee8e9William King (query->lookup->rdtype != dns_rdatatype_a)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts("\nAuthoritative answers can be found from:");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printsection(query, msg, headers,
99e207809793732e3e47da3a1cab6925b6eee8e9William King DNS_SECTION_AUTHORITY);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printsection(query, msg, headers,
99e207809793732e3e47da3a1cab6925b6eee8e9William King DNS_SECTION_ADDITIONAL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingshow_settings(isc_boolean_t full, isc_boolean_t serv_only) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_server_t *srv;
93a16701383bbc91e6915d41d1ed827ce8b92246William King isc_sockaddr_t sockaddr;
93a16701383bbc91e6915d41d1ed827ce8b92246William King dig_searchlist_t *listent;
93a16701383bbc91e6915d41d1ed827ce8b92246William King
93a16701383bbc91e6915d41d1ed827ce8b92246William King srv = ISC_LIST_HEAD(server_list);
93a16701383bbc91e6915d41d1ed827ce8b92246William King
93a16701383bbc91e6915d41d1ed827ce8b92246William King while (srv != NULL) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff char sockstr[ISC_SOCKADDR_FORMATSIZE];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews get_address(srv->servername, port, &sockaddr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_sockaddr_format(&sockaddr, sockstr, sizeof(sockstr));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence printf("Default server: %s\nAddress: %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence srv->servername, sockstr);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (!full)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley srv = ISC_LIST_NEXT(srv, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (serv_only)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\nSet options:\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf(" %s\t\t\t%s\t\t%s\n",
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence tcpmode ? "vc" : "novc",
99e207809793732e3e47da3a1cab6925b6eee8e9William King short_form ? "nodebug" : "debug",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence debugging ? "d2" : "nod2");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf(" %s\t\t%s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch ? "search" : "nosearch",
99e207809793732e3e47da3a1cab6925b6eee8e9William King recurse ? "recurse" : "norecurse");
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf(" timeout = %d\t\tretry = %d\tport = %d\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King timeout, tries, port);
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf(" querytype = %-8s\tclass = %s\n", deftype, defclass);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence printf(" srchlist = ");
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley for (listent = ISC_LIST_HEAD(search_list);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence listent != NULL;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence listent = ISC_LIST_NEXT(listent, link)) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence printf("%s", listent->origin);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (ISC_LIST_NEXT(listent, link) != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("/");
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_boolean_t
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrewstesttype(char *typetext) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_textregion_t tr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdatatype_t rdtype;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.base = typetext;
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.length = strlen(typetext);
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdatatype_fromtext(&rdtype, &tr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_TRUE);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else {
93a16701383bbc91e6915d41d1ed827ce8b92246William King printf("unknown query type: %s\n", typetext);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_FALSE);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_boolean_t
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingtestclass(char *typetext) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_textregion_t tr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataclass_t rdclass;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.base = typetext;
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.length = strlen(typetext);
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdataclass_fromtext(&rdclass, &tr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_TRUE);
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews else {
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews printf("unknown query class: %s\n", typetext);
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews return (ISC_FALSE);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrewsstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingsafecpy(char *dest, char *src, int size) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King strncpy(dest, src, size);
99e207809793732e3e47da3a1cab6925b6eee8e9William King dest[size-1] = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_result_t
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingparse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max, const char *desc) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_uint32_t n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result = isc_parse_uint32(&n, value, 10);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS && n > max)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = ISC_R_RANGE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("invalid %s '%s': %s\n", desc,
99e207809793732e3e47da3a1cab6925b6eee8e9William King value, isc_result_totext(result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King return result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King *uip = n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return (ISC_R_SUCCESS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingset_port(const char *value) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_uint32_t n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result = parse_uint(&n, value, 65535, "port");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King port = n;
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingset_timeout(const char *value) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_uint32_t n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King timeout = n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingset_tries(const char *value) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_uint32_t n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King tries = n;
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingsetoption(char *opt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (strncasecmp(opt, "all", 4) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King show_settings(ISC_TRUE, ISC_FALSE);
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "class=", 6) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (testclass(&opt[6]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(defclass, &opt[6], sizeof(defclass));
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "cl=", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (testclass(&opt[3]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(defclass, &opt[3], sizeof(defclass));
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "type=", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (testtype(&opt[5]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(deftype, &opt[5], sizeof(deftype));
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "ty=", 3) == 0) {
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence if (testtype(&opt[3]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(deftype, &opt[3], sizeof(deftype));
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence } else if (strncasecmp(opt, "querytype=", 10) == 0) {
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence if (testtype(&opt[10]))
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews safecpy(deftype, &opt[10], sizeof(deftype));
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence } else if (strncasecmp(opt, "query=", 6) == 0) {
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (testtype(&opt[6]))
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence safecpy(deftype, &opt[6], sizeof(deftype));
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence } else if (strncasecmp(opt, "qu=", 3) == 0) {
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (testtype(&opt[3]))
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(deftype, &opt[3], sizeof(deftype));
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "domain=", 7) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(domainopt, &opt[7], sizeof(domainopt));
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_search_domain(domainopt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "do=", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(domainopt, &opt[3], sizeof(domainopt));
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_search_domain(domainopt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "port=", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_port(&opt[5]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "po=", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_port(&opt[3]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "timeout=", 8) == 0) {
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews set_timeout(&opt[8]);
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews } else if (strncasecmp(opt, "t=", 2) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_timeout(&opt[2]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "rec", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King recurse = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "norec", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King recurse = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "retry=", 6) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_tries(&opt[6]);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else if (strncasecmp(opt, "ret=", 4) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King set_tries(&opt[4]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "def", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "nodef", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "vc", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King tcpmode = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "novc", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King tcpmode = ISC_FALSE;
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews } else if (strncasecmp(opt, "deb", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King short_form = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "nodeb", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King short_form = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "d2", 2) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King debugging = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "nod2", 4) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King debugging = ISC_FALSE;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else if (strncasecmp(opt, "search", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "nosearch", 5) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else if (strncasecmp(opt, "sil", 3) == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King deprecation_msg = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("*** Invalid option: %s\n", opt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrewsstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingaddlookup(char *opt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_lookup_t *lookup;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_textregion_t tr;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence dns_rdatatype_t rdtype;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dns_rdataclass_t rdclass;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char store[MXNAME];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King debug("addlookup()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.base = deftype;
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.length = strlen(deftype);
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdatatype_fromtext(&rdtype, &tr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("unknown query type: %s\n", deftype);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence rdclass = dns_rdatatype_a;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.base = defclass;
99e207809793732e3e47da3a1cab6925b6eee8e9William King tr.length = strlen(defclass);
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = dns_rdataclass_fromtext(&rdclass, &tr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King printf("unknown query class: %s\n", defclass);
99e207809793732e3e47da3a1cab6925b6eee8e9William King rdclass = dns_rdataclass_in;
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews }
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup = make_empty_lookup();
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (get_reverse(store, opt, lookup->nibble, ISC_TRUE)
99e207809793732e3e47da3a1cab6925b6eee8e9William King == ISC_R_SUCCESS)
99e207809793732e3e47da3a1cab6925b6eee8e9William King {
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(lookup->textname, store, sizeof(lookup->textname));
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->rdtype = dns_rdatatype_ptr;
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence lookup->rdtypeset = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King safecpy(lookup->textname, opt, sizeof(lookup->textname));
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->rdtype = rdtype;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->rdtypeset = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->rdclass = rdclass;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->rdclassset = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->trace = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->trace_root = lookup->trace;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->ns_search_only = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->identify = identify;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->recurse = recurse;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->aaonly = aaonly;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->retries = tries;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->udpsize = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->comments = comments;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->tcp_mode = tcpmode;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->stats = stats;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->section_question = section_question;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->section_answer = section_answer;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->section_authority = section_authority;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->section_additional = section_additional;
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->new_search = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INIT(lookup->q);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LINK_INIT(lookup, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_APPEND(lookup_list, lookup, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup->origin = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INIT(lookup->my_server_list);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence debug("looking up %s", lookup->textname);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingflush_server_list(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_server_t *s, *ps;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence debug("flush_server_list()");
99e207809793732e3e47da3a1cab6925b6eee8e9William King s = ISC_LIST_HEAD(server_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (s != NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King ps = s;
99e207809793732e3e47da3a1cab6925b6eee8e9William King s = ISC_LIST_NEXT(s, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_DEQUEUE(server_list, ps, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_free(mctx, ps);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King/*
99e207809793732e3e47da3a1cab6925b6eee8e9William King * This works on the global server list, instead of on a per-lookup
99e207809793732e3e47da3a1cab6925b6eee8e9William King * server list, since the change is persistent.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingsetsrv(char *opt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_server_t *srv;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (opt == NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King flush_server_list();
99e207809793732e3e47da3a1cab6925b6eee8e9William King srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (srv == NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King fatal("memory allocation failure");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence safecpy(srv->servername, opt, sizeof(srv->servername));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INITANDAPPEND(server_list, srv, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingget_next_command(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *buf;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley char *ptr, *arg;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *input;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence buf = isc_mem_allocate(mctx, COMMSIZE);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont if (buf == NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King fatal("memory allocation failure");
99e207809793732e3e47da3a1cab6925b6eee8e9William King fputs("> ", stderr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_app_block();
99e207809793732e3e47da3a1cab6925b6eee8e9William King ptr = fgets(buf, COMMSIZE, stdin);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_app_unblock();
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (ptr == NULL) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence in_use = ISC_FALSE;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence goto cleanup;
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews }
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews input = buf;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews ptr = next_token(&input, " \t\r\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (ptr == NULL)
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews goto cleanup;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews arg = next_token(&input, " \t\r\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if ((strcasecmp(ptr, "set") == 0) &&
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (arg != NULL))
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews setoption(arg);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews else if ((strcasecmp(ptr, "server") == 0) ||
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley (strcasecmp(ptr, "lserver") == 0)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King setsrv(arg);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence show_settings(ISC_TRUE, ISC_TRUE);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else if (strcasecmp(ptr, "exit") == 0) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence in_use = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King goto cleanup;
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews } else if (strcasecmp(ptr, "help") == 0 ||
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley strcasecmp(ptr, "?") == 0)
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews printf("The '%s' command is not yet implemented.\n", ptr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews goto cleanup;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews } else if (strcasecmp(ptr, "finger") == 0 ||
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews strcasecmp(ptr, "root") == 0 ||
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews strcasecmp(ptr, "ls") == 0 ||
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews strcasecmp(ptr, "view") == 0)
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews {
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley printf("The '%s' command is not implemented.\n", ptr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King goto cleanup;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence addlookup(ptr);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence cleanup:
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_mem_free(mctx, buf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingparse_args(int argc, char **argv) {
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont isc_boolean_t have_lookup = ISC_FALSE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King usesearch = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (argc--, argv++; argc > 0; argc--, argv++) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King debug("main parsing %s", argv[0]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (argv[0][0] == '-') {
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (argv[0][1] != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King setoption(&argv[0][1]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
99e207809793732e3e47da3a1cab6925b6eee8e9William King have_lookup = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King } else {
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont if (!have_lookup) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King have_lookup = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King in_use = ISC_TRUE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King addlookup(argv[0]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
99e207809793732e3e47da3a1cab6925b6eee8e9William King setsrv(argv[0]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence}
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingflush_lookup_list(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_lookup_t *l, *lp;
99e207809793732e3e47da3a1cab6925b6eee8e9William King dig_query_t *q, *qp;
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews dig_server_t *s, *sp;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King lookup_counter = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King l = ISC_LIST_HEAD(lookup_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (l != NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King q = ISC_LIST_HEAD(l->q);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (q != NULL) {
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews if (q->sock != NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_socket_cancel(q->sock, NULL,
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_SOCKCANCEL_ALL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_socket_detach(&q->sock);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (ISC_LINK_LINKED(&q->recvbuf, link))
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_DEQUEUE(q->recvlist, &q->recvbuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (ISC_LINK_LINKED(&q->lengthbuf, link))
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf,
99e207809793732e3e47da3a1cab6925b6eee8e9William King link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_invalidate(&q->recvbuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_buffer_invalidate(&q->lengthbuf);
99e207809793732e3e47da3a1cab6925b6eee8e9William King qp = q;
99e207809793732e3e47da3a1cab6925b6eee8e9William King q = ISC_LIST_NEXT(q, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_DEQUEUE(l->q, qp, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_free(mctx, qp);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King s = ISC_LIST_HEAD(l->my_server_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (s != NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King sp = s;
99e207809793732e3e47da3a1cab6925b6eee8e9William King s = ISC_LIST_NEXT(s, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_free(mctx, sp);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (l->sendmsg != NULL)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence dns_message_destroy(&l->sendmsg);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (l->timer != NULL)
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence isc_timer_detach(&l->timer);
99e207809793732e3e47da3a1cab6925b6eee8e9William King lp = l;
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews l = ISC_LIST_NEXT(l, link);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence ISC_LIST_DEQUEUE(lookup_list, lp, link);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence isc_mem_free(mctx, lp);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence }
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence}
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kinggetinput(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (global_event == NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King global_event = event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (in_use) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King get_next_command();
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (ISC_LIST_HEAD(lookup_list) != NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King start_lookup();
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_app_shutdown();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingint
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingmain(int argc, char **argv) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_t result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INIT(lookup_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INIT(server_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ISC_LIST_INIT(search_list);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = isc_app_start();
99e207809793732e3e47da3a1cab6925b6eee8e9William King check_result(result, "isc_app_start");
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King setup_libs();
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence progname = argv[0];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King parse_args(argc, argv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (deprecation_msg) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King fputs(
99e207809793732e3e47da3a1cab6925b6eee8e9William King"Note: nslookup is deprecated and may be removed from future releases.\n"
99e207809793732e3e47da3a1cab6925b6eee8e9William King"Consider using the `dig' or `host' programs instead. Run nslookup with\n"
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence"the `-sil[ent]' option to prevent this message from appearing.\n", stderr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence setup_system();
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (domainopt[0] != '\0')
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence set_search_domain(domainopt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (in_use)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = isc_app_onrun(mctx, global_task, onrun_callback,
99e207809793732e3e47da3a1cab6925b6eee8e9William King NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = isc_app_onrun(mctx, global_task, getinput, NULL);
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrence check_result(result, "isc_app_onrun");
99e207809793732e3e47da3a1cab6925b6eee8e9William King in_use = ISC_TF(!in_use);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King (void)isc_app_run();
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King puts("");
99e207809793732e3e47da3a1cab6925b6eee8e9William King debug("done, and starting to shut down");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (global_event != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&global_event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King cancel_all();
99e207809793732e3e47da3a1cab6925b6eee8e9William King destroy_libs();
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_app_finish();
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley return (0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley