nslookup.c revision e42c402595802edceafbd3e5338dda011fbbcdb6
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Copyright (C) 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Permission to use, copy, modify, and distribute this software for any
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer/* $Id: nslookup.c,v 1.45 2000/09/14 22:03:52 mws Exp $ */
47058d17266420179fa294de6b82d8fb5b918df4Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <config.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <stdlib.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int h_errno;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/app.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/buffer.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/commandline.h>
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington#include <isc/event.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/string.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/timer.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/util.h>
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer#include <isc/task.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/message.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/name.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdata.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdataclass.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdataset.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdatatype.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dig/dig.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern ISC_LIST(dig_lookup_t) lookup_list;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern ISC_LIST(dig_server_t) server_list;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern ISC_LIST(dig_searchlist_t) search_list;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerextern isc_boolean_t have_ipv6, show_details,
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer usesearch, trace, qr, debugging;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern in_port_t port;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern unsigned int timeout;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern isc_mem_t *mctx;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern dns_messageid_t id;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern char *rootspace[BUFSIZE];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern isc_buffer_t rootbuf;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int sendcount;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int ndots;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int tries;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int lookup_counter;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern char fixeddomain[MXNAME];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern int exitcode;
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyerextern isc_taskmgr_t *taskmgr;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonextern isc_task_t *global_task;
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyerextern char *progname;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerisc_boolean_t short_form = ISC_TRUE, printcmd = ISC_TRUE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer filter = ISC_FALSE, showallsoa = ISC_FALSE,
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer tcpmode = ISC_FALSE, deprecation_msg = ISC_TRUE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_uint16_t bufsize = 0;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_boolean_t identify = ISC_FALSE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer trace = ISC_FALSE, ns_search_only = ISC_FALSE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer forcecomment = ISC_FALSE, stats = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer comments = ISC_TRUE, section_question = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_answer = ISC_TRUE, section_authority = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_additional = ISC_TRUE, recurse = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer defname = ISC_TRUE, aaonly = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerisc_boolean_t busy = ISC_FALSE, in_use = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerchar defclass[MXRD] = "IN";
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerchar deftype[MXRD] = "A";
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonisc_event_t *global_event = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyerstatic const char *rcodetext[] = {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOERROR",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "FORMERR",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "SERVFAIL",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NXDOMAIN",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTIMPL",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "REFUSED",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "YXDOMAIN",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "YXRRSET",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NXRRSET",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTAUTH",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTZONE",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED11",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED12",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED13",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED14",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED15",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "BADVERS"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer};
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyerstatic const char *rtypetext[] = {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_0 = ", /* 0 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "internet address = ", /* 1 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "nameserver = ", /* 2 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "md = ", /* 3 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "mf = ", /* 4 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "canonical name = ", /* 5 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "soa = ", /* 6 */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "mb = ", /* 7 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "mg = ", /* 8 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "mr = ", /* 9 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_10 = ", /* 10 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "protocol = ", /* 11 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "name = ", /* 12 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "hinfo = ", /* 13 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "minfo = ", /* 14 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "mail exchanger = ", /* 15 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "text = ", /* 16 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rp = ", /* 17 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "afsdb = ", /* 18 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "x25 address = ", /* 19 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "isdn address = ", /* 20 */
e32394a2ac3466a2235f79ee32c247a11be42a8dAndreas Gustafsson "rt = ", /* 21 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "nsap = ", /* 22 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "nsap_ptr = ", /* 23 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "signature = ", /* 24 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "key = ", /* 25 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "px = ", /* 26 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "gpos = ", /* 27 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "has AAAA address", /* 28 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "loc = ", /* 29 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "next = ", /* 30 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_31 = ", /* 31 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_32 = ", /* 32 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "service = ", /* 33 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_34 = ", /* 34 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "naptr = ", /* 35 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "kx = ", /* 36 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "cert = ", /* 37 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "v6 address = ", /* 38 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dname = ", /* 39 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "rtype_40 = ", /* 40 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "optional = "}; /* 41 */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void flush_lookup_list(void);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void getinput(isc_task_t *task, isc_event_t *event);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic void
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrenceshow_usage(void) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson fputs("Usage:\n", stderr);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyervoid
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerdighost_shutdown(void) {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_event_t *event = global_event;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington flush_lookup_list();
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington debug("dighost_shutdown()");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (!in_use) {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_app_shutdown();
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington return;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington }
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_task_send(global_task, &event);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyervoid
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(bytes);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(frmsize);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(frm);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(query);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyervoid
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyertrying(int frmsize, char *frm, dig_lookup_t *lookup) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(frmsize);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(frm);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(lookup);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic isc_result_t
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerprintsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_section_t section) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_result_t result, loopresult;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t *b = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_t *name;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_t *rdataset = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdata_t rdata;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char *ptr;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(query);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(headers);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer debug("printsection()");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_firstname(msg, section);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (result == ISC_R_NOMORE)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer else if (result != ISC_R_SUCCESS)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (result);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result, "isc_buffer_allocate");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer for (;;) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer name = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_message_currentname(msg, section,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer &name);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer for (rdataset = ISC_LIST_HEAD(name->list);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer rdataset != NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer rdataset = ISC_LIST_NEXT(rdataset, link)) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer loopresult = dns_rdataset_first(rdataset);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (loopresult == ISC_R_SUCCESS) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson dns_rdataset_current(rdataset, &rdata);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson switch (rdata.type) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case dns_rdatatype_a:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (section != DNS_SECTION_ANSWER)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto def_short_section;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_name_totext(name,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_TRUE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("Name:\t%.*s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_rdata_totext(&rdata,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("Address: %.*s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case dns_rdatatype_soa:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_name_totext(name,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_TRUE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("%.*s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_rdata_totext(&rdata,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer ((char *)isc_buffer_used(b))[0]=0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(isc_buffer_base(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\torigin = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\tmail addr = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\tserial = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\trefresh = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\tretry = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\texpire = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\tminimum = %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer default:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer def_short_section:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_name_totext(name,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_TRUE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (rdata.type <= 41)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("%.*s\t%s",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rtypetext[rdata.type]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("%.*s\trdata_%d = ",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdata.type);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_clear(b);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = dns_rdata_totext(&rdata,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL, b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("%.*s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char*)isc_buffer_base(b));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer loopresult = dns_rdataset_next(rdataset);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_nextname(msg, section);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (result == ISC_R_NOMORE)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else if (result != ISC_R_SUCCESS) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_free (&b);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (result);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_free(&b);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic isc_result_t
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerdetailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_section_t section) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_result_t result, loopresult;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_t *b = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_name_t *name;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdataset_t *rdataset = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdata_t rdata;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer char *ptr;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson UNUSED(query);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer debug("detailsection()");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (headers) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer switch (section) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer case DNS_SECTION_QUESTION:
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts(" QUESTIONS:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer case DNS_SECTION_ANSWER:
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts(" ANSWERS:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer case DNS_SECTION_AUTHORITY:
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts(" AUTHORITY RECORDS:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer case DNS_SECTION_ADDITIONAL:
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts(" ADDITIONAL RECORDS:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_message_firstname(msg, section);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result == ISC_R_NOMORE)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (ISC_R_SUCCESS);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else if (result != ISC_R_SUCCESS)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result, "isc_buffer_allocate");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer for (;;) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer name = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_message_currentname(msg, section,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer &name);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer for (rdataset = ISC_LIST_HEAD(name->list);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset != NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset = ISC_LIST_NEXT(rdataset, link)) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer loopresult = dns_rdataset_first(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer while (loopresult == ISC_R_SUCCESS) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdataset_current(rdataset, &rdata);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_clear(b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_name_totext(name,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ISC_TRUE,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_name_totext");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf(" -> %.*s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer (int)isc_buffer_usedlength(b),
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer (char*)isc_buffer_base(b));
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer switch (rdata.type) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer case dns_rdatatype_soa:
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_clear(b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_rdata_totext(&rdata,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_rdata_totext");
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer ((char *)isc_buffer_used(b))[0]=0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(isc_buffer_base(b),
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\torigin = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\tmail addr = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\tserial = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\trefresh = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\tretry = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\texpire = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr = strtok(NULL, " \t\r\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (ptr == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("\tminimum = %s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ptr);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer default:
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_clear(b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (rdata.type <= 41)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t%s",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rtypetext[rdata.type]);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\trdata_%d = ",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdata.type);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_clear(b);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = dns_rdata_totext(&rdata,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL, b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_rdata_totext");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("%.*s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer (int)isc_buffer_usedlength(b),
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer (char*)isc_buffer_base(b));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer loopresult = dns_rdataset_next(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_message_nextname(msg, section);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result == ISC_R_NOMORE)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer break;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else if (result != ISC_R_SUCCESS) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_free (&b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_free(&b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (ISC_R_SUCCESS);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t *b = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_region_t r;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_result_t result;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("printmessage()");
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer debug("continuing on with rcode != 0");
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer check_result(result, "isc_buffer_allocate");
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer printf("Server:\t\t%s\n", query->servname);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer result = isc_sockaddr_totext(&query->sockaddr, b);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer check_result(result, "isc_sockaddr_totext");
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer printf("Address:\t%.*s\n", (int)isc_buffer_usedlength(b),
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer (char*)isc_buffer_base(b));
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer isc_buffer_free(&b);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer puts("");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (msg->rcode != 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result, "isc_buffer_allocate");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_name_totext(query->lookup->name, ISC_FALSE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer b);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result, "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_usedregion(b, &r);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("** server can't find %.*s: %s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (int)r.length, (char*)r.base,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rcodetext[msg->rcode]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_free(&b);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("returning with rcode == 0");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (!short_form){
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("------------");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /* detailheader(query, msg);*/
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_QUESTION);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_ANSWER);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_AUTHORITY);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("------------");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("Non-authorative answer:");
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printsection(query, msg, headers, DNS_SECTION_ANSWER);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer else
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("*** Can't find %s: No answer\n",
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer query->lookup->textname);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer (query->lookup->rdtype != dns_rdatatype_a)) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("\nAuthorative answers can be found from:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printsection(query, msg, headers,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer DNS_SECTION_AUTHORITY);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printsection(query, msg, headers,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer DNS_SECTION_ADDITIONAL);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic void
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyershow_settings(isc_boolean_t full) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_server_t *srv;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_sockaddr_t sockaddr;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_t *b = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_result_t result;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer srv = ISC_LIST_HEAD(server_list);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (srv != NULL) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result, "isc_buffer_allocate");
97beb7237b6383cf518d79cee08e23c8aa2bae3fMichael Sawyer get_address(srv->servername, 53, &sockaddr, ISC_FALSE);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_sockaddr_totext(&sockaddr, b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result, "isc_sockaddr_totext");
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("Default server: %s\nAddress: %.*s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer srv->servername, (int)isc_buffer_usedlength(b),
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer (char*)isc_buffer_base(b));
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_free(&b);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (!full)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer srv = ISC_LIST_NEXT(srv, link);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\n\tSet options:\n");
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t %s\t\t\t%s\t\t%s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer tcpmode?"vc":"novc", short_form?"nodebug":"debug",
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer debugging?"d2":"nod2");
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t %s\t\t%s\t%s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer defname?"defname":"nodefname",
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer usesearch?"search ":"nosearch",
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer recurse?"recurse":"norecurse");
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t timeout = %d\t\tretry = %d\tport = %d\n",
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer timeout, tries, port);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t querytype = %-8s\tclass = %s\n",deftype, defclass);
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer#if 0
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t domain = %s\n", fixeddomain);
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer#endif
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyerstatic isc_boolean_t
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyertesttype(char *typetext) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_result_t result;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_textregion_t tr;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdatatype_t rdtype;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.base = typetext;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.length = strlen(typetext);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (result == ISC_R_SUCCESS)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer return (ISC_TRUE);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer else {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query type: %s\n", typetext);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer return (ISC_FALSE);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer}
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyerstatic isc_boolean_t
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyertestclass(char *typetext) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_result_t result;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_textregion_t tr;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdataclass_t rdclass;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.base = typetext;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.length = strlen(typetext);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (result == ISC_R_SUCCESS)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer return (ISC_TRUE);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer else {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query class: %s\n", typetext);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer return (ISC_FALSE);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer}
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyersetoption(char *opt) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (strncasecmp(opt,"all",4) == 0) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer show_settings(ISC_TRUE);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "class=", 6) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testclass(&opt[6]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(defclass, &opt[6], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "cl=", 3) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testclass(&opt[3]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(defclass, &opt[3], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "type=", 5) == 0) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (testtype(&opt[5]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(deftype, &opt[3], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ty=", 3) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testtype(&opt[3]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(deftype, &opt[3], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "querytype=", 10) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testtype(&opt[10]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(deftype, &opt[10], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "query=", 6) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testtype(&opt[6]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(deftype, &opt[6], MXRD);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "qu=", 3) == 0) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (testtype(&opt[3]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(deftype, &opt[3], MXRD);
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer#if 0
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer /* XXXMWS domain= doesn't work now. */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "domain=", 7) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncpy(fixeddomain, &opt[7], MXNAME);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "do=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncpy(fixeddomain, &opt[3], MXNAME);
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer#endif
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "port=", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer port = atoi(&opt[5]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "po=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer port = atoi(&opt[3]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "timeout=", 8) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer timeout = atoi(&opt[8]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "t=", 2) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer timeout = atoi(&opt[2]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "retry=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer tries = atoi(&opt[6]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ret=", 4) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer tries = atoi(&opt[4]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "def", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer defname = ISC_TRUE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "nodef", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer defname = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "deb", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer short_form = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "nodeb", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer short_form = ISC_TRUE;
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer } else if (strncasecmp(opt, "d2", 2) == 0) {
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer debugging = ISC_TRUE;
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer } else if (strncasecmp(opt, "nod2", 4) == 0) {
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer debugging = ISC_FALSE;
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer } else if (strncasecmp(opt, "sil",3) == 0) {
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer deprecation_msg = ISC_FALSE;
48674819ebf9176b5d5582ae851e485c324c1159Michael Sawyer } else {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf ("*** Invalid option: %s\n",opt);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
48674819ebf9176b5d5582ae851e485c324c1159Michael Sawyerstatic dig_lookup_t*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyeraddlookup(char *opt) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dig_lookup_t *lookup;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_result_t result;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_textregion_t tr;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdatatype_t rdtype;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdataclass_t rdclass;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("addlookup()");
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.base = deftype;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.length = strlen(deftype);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer if (result != ISC_R_SUCCESS) {
bac3fc1a365bd48b1efe4044c7f3f587ed42b8a6Andreas Gustafsson printf("unknown query type: %s\n",deftype);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer rdclass = dns_rdatatype_a;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.base = defclass;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer tr.length = strlen(defclass);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer if (result != ISC_R_SUCCESS) {
bac3fc1a365bd48b1efe4044c7f3f587ed42b8a6Andreas Gustafsson printf("unknown query class: %s\n",defclass);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer rdclass = dns_rdataclass_in;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer lookup = make_empty_lookup();
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncpy(lookup->textname, opt, MXNAME-1);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer lookup->rdtype = rdtype;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer lookup->rdclass = rdclass;
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence lookup->trace = ISC_TF(trace || ns_search_only);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->trace_root = trace;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->ns_search_only = ns_search_only;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->identify = identify;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->recurse = recurse;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->aaonly = aaonly;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer lookup->retries = tries;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->udpsize = bufsize;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->comments = comments;
9fe3676b8490319aa65182f2072cbf5086097979Michael Sawyer lookup->tcp_mode = tcpmode;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->stats = stats;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_question = section_question;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_answer = section_answer;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_authority = section_authority;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_additional = section_additional;
17747cd5ee98901b435cd2b3019c52937955a981Michael Sawyer lookup->new_search = ISC_TRUE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_INIT(lookup->q);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_APPEND(lookup_list, lookup, link);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer lookup->origin = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_INIT(lookup->my_server_list);
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer debug("looking up %s", lookup->textname);
48674819ebf9176b5d5582ae851e485c324c1159Michael Sawyer return (lookup);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrenceflush_server_list(void) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_server_t *s, *ps;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington debug("flush_server_list()");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer s = ISC_LIST_HEAD(server_list);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (s != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ps = s;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer s = ISC_LIST_NEXT(s, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(server_list, ps, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_mem_free(mctx, ps);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence/*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * This works on the global server list, instead of on a per-lookup
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * server list, since the change is persistent.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyersetsrv(char *opt) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_server_t *srv;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer flush_server_list();
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer srv=isc_mem_allocate(mctx, sizeof(struct dig_server));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (srv == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fatal("Memory allocation failure.");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncpy(srv->servername, opt, MXNAME-1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_APPEND(server_list, srv, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrenceget_next_command(void) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char input[COMMSIZE];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char *ptr, *arg;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fputs("> ", stderr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = fgets(input, COMMSIZE, stdin);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ptr == NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer in_use = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ptr = strtok(input, " \t\r\n");
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington if (ptr == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer arg = strtok(NULL, " \t\r\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if ((strcasecmp(ptr, "set") == 0) &&
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (arg != NULL))
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer setoption(arg);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else if ((strcasecmp(ptr, "server") == 0) ||
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (strcasecmp(ptr, "lserver") == 0)) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence printf("Server:\t%s\n", arg);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer setsrv(arg);
6e3a8e17fdf108f47bbba17474fd3d120d356b2fBrian Wellington } else if (strcasecmp(ptr, "exit") == 0) {
6e3a8e17fdf108f47bbba17474fd3d120d356b2fBrian Wellington in_use = ISC_FALSE;
6e3a8e17fdf108f47bbba17474fd3d120d356b2fBrian Wellington return;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington } else if (strcasecmp(ptr, "help") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington strcasecmp(ptr, "?") == 0)
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington {
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not yet implemented.\n", ptr);
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington return;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington } else if (strcasecmp(ptr, "finger") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington strcasecmp(ptr, "root") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington strcasecmp(ptr, "ls") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington strcasecmp(ptr, "view") == 0)
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington {
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not implemented.\n", ptr);
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington return;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer addlookup(ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerparse_args(int argc, char **argv) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_lookup_t *lookup = NULL;
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer isc_boolean_t have_lookup = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer for (argc--, argv++; argc > 0; argc--, argv++) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("main parsing %s", argv[0]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (argv[0][0] == '-') {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if ((argv[0][1] == 'h') &&
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (argv[0][2] == 0)) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer show_usage();
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer exit (1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (argv[0][1] != 0)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer setoption(&argv[0][1]);
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer else
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer have_lookup = ISC_TRUE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else {
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer if (!have_lookup) {
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer have_lookup = ISC_TRUE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer in_use = ISC_TRUE;
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer lookup = addlookup(argv[0]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer setsrv(argv[0]);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerflush_lookup_list(void) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_lookup_t *l, *lp;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_query_t *q, *qp;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_server_t *s, *sp;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup_counter = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer l = ISC_LIST_HEAD(lookup_list);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (l != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer q = ISC_LIST_HEAD(l->q);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (q != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (q->sock != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_socket_cancel(q->sock, NULL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_SOCKCANCEL_ALL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_socket_detach(&q->sock);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ISC_LINK_LINKED(&q->recvbuf, link))
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(q->recvlist, &q->recvbuf,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (ISC_LINK_LINKED(&q->lengthbuf, link))
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_invalidate(&q->recvbuf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_invalidate(&q->lengthbuf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer qp = q;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer q = ISC_LIST_NEXT(q, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(l->q, qp, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_mem_free(mctx, qp);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
e715e011788a529446b8013239c33599542ece32Michael Sawyer s = ISC_LIST_HEAD(l->my_server_list);
e715e011788a529446b8013239c33599542ece32Michael Sawyer while (s != NULL) {
e715e011788a529446b8013239c33599542ece32Michael Sawyer sp = s;
e715e011788a529446b8013239c33599542ece32Michael Sawyer s = ISC_LIST_NEXT(s, link);
e715e011788a529446b8013239c33599542ece32Michael Sawyer ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
e715e011788a529446b8013239c33599542ece32Michael Sawyer isc_mem_free(mctx, sp);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (l->sendmsg != NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_message_destroy(&l->sendmsg);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (l->timer != NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_timer_detach(&l->timer);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lp = l;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer l = ISC_LIST_NEXT(l, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(lookup_list, lp, link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_mem_free(mctx, lp);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtongetinput(isc_task_t *task, isc_event_t *event) {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington UNUSED(task);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (global_event == NULL)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington global_event = event;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer while (in_use) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_app_block();
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer get_next_command();
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_app_unblock();
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (ISC_LIST_HEAD(lookup_list) != NULL) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer start_lookup();
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer return;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_app_shutdown();
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington}
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerint
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyermain(int argc, char **argv) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_result_t result;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_INIT(lookup_list);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_INIT(server_list);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_LIST_INIT(search_list);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_start();
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington check_result(result, "isc_app_start");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer setup_libs();
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer progname = argv[0];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer parse_args(argc, argv);
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer if (deprecation_msg) {
88301f84d1391e96ec87a9a308aa18f45553a56bAndreas Gustafsson fputs(
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer"Note: nslookup is deprecated and may be removed from future releases.\n"
ad7bb5bff3e796f5648835bf87a203d23d8319e4David Lawrence"Consider using the `dig' or `host' programs instead. Run nslookup with\n"
88301f84d1391e96ec87a9a308aa18f45553a56bAndreas Gustafsson"the `-sil[ent]' option to prevent this message from appearing.\n", stderr);
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer setup_system();
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (in_use)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, onrun_callback,
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington NULL);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington else
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, getinput, NULL);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington check_result(result, "isc_app_onrun");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington in_use = ISC_TF(!in_use);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington (void)isc_app_run();
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("");
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("done, and starting to shut down");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (global_event != NULL)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_event_free(&global_event);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer destroy_libs();
db8b100cae62de849ecf4ba9ad3be811fb375b53Michael Sawyer isc_app_finish();
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (0);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}