dig.c revision 8f56f93547c0be53351ba2bf096e5c82de4dae25
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/*
ddad35552931651426ad70912d29d9ab7d2a8d80Automatic Updater * Copyright (C) 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
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
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copyright notice and this permission notice appear in all copies.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff */
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
321b1c0501d6d97c852ae02e13bdfef6f0bbe776Automatic Updater/* $Id: dig.c,v 1.64 2000/07/13 21:00:58 mws Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <config.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#include <stdlib.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/app.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/string.h>
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#include <isc/util.h>
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#include <isc/task.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <dns/message.h>
80617c8faa03b2c425e320597eb768073fd0b987Michael Graff#include <dns/name.h>
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#include <dns/rdata.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#include <dns/rdataset.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/rdatatype.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dig/dig.h>
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence
32eddfc189108fa93e31761e13150594c7a79d2bDavid Lawrenceextern ISC_LIST(dig_lookup_t) lookup_list;
a095cd0ef599eb04d74fb9f9bc46ae13081c5bcbMark Andrewsextern ISC_LIST(dig_server_t) server_list;
440be4c866f6935ac069db79a414304507a664c2Michael Graffextern ISC_LIST(dig_searchlist_t) search_list;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington#define ADD_STRING(b, s) { \
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff if (strlen(s) >= isc_buffer_availablelength(b)) \
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff return (ISC_R_NOSPACE); \
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff else \
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_buffer_putstr(b, s); \
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffextern isc_boolean_t have_ipv6, show_details, specified_source,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff usesearch, qr;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern in_port_t port;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern unsigned int timeout;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern isc_mem_t *mctx;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern dns_messageid_t id;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern char *rootspace[BUFSIZE];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern isc_buffer_t rootbuf;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern int sendcount;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern int ndots;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern int tries;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern int lookup_counter;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern char fixeddomain[MXNAME];
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrewsextern int exitcode;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern isc_sockaddr_t bind_address;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern char keynametext[MXNAME];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern char keysecret[MXNAME];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern dns_tsigkey_t *key;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern isc_boolean_t validated;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern isc_taskmgr_t *taskmgr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉extern isc_task_t *global_task;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsextern isc_boolean_t debugging;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffextern isc_boolean_t isc_mem_debugging;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellingtonisc_uint16_t bufsize = 0;
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrewsisc_boolean_t
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews identify = ISC_FALSE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 trace = ISC_FALSE,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff ns_search_only = ISC_FALSE,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff forcecomment = ISC_FALSE,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff stats = ISC_TRUE,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff comments = ISC_TRUE,
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff section_question = ISC_TRUE,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews section_answer = ISC_TRUE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 section_authority = ISC_TRUE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 section_additional = ISC_TRUE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 recurse = ISC_TRUE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 defname = ISC_TRUE,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews tcpmode = ISC_FALSE,
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews adflag = ISC_FALSE,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews cdflag = ISC_FALSE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic const char *opcodetext[] = {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "QUERY",
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff "IQUERY",
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff "STATUS",
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff "RESERVED3",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NOTIFY",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "UPDATE",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED6",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED7",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED8",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED9",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED10",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED11",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED12",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED13",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED14",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "RESERVED15"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉};
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static const char *rcodetext[] = {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "NOERROR",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "FORMERR",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "SERVFAIL",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "NXDOMAIN",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "NOTIMPL",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "REFUSED",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "YXDOMAIN",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "YXRRSET",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "NXRRSET",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "NOTAUTH",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "NOTZONE",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "RESERVED11",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "RESERVED12",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "RESERVED13",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "RESERVED14",
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff "RESERVED15",
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "BADVERS"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉};
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graffextern char *progname;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffstatic void
038a3e6bfe6e15479b0469bd87de3a7139ad1109Brian Wellingtonshow_usage(void) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fputs(
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" {global-d-opt} host [@local-server] {local-d-opt}\n"
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff" [ host [@local-server] {local-d-opt} [...]]\n"
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff"Where: domain are in the Domain Name System\n"
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff" q-class is one of (in,chaos,...) [default: in]\n"
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff" (Use ixfr=version for type ixfr)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" q-opt is one of:\n"
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff" -x dot-notation (shortcut for in-addr lookups)\n"
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff" -f filename (batch mode)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" -p port (specify port number)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" -t type (specify query type)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" -c class (specify query class)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" -y name:key (specify named base64 tsig key)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" d-opt is of the form +keyword[=value], where keyword is:\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]vc (TCP mode)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]tcp (TCP mode, alternate syntax)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +time=### (Set query timeout) [5]\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +tries=### (Set number of UDP attempts) [3]\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +domain=### (Set default domainname)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]search (Set whether to use searchlist)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]defname (Set whether to use default domain)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]recursive (Recursive mode)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]adflag (Set AD flag in query)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]cdflag (Set CD flag in query)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]details (Show details of all requests)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +ndots=### (Set NDOTS value)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]comments (Control display of comment lines)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]question (Control display of question)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]answer (Control display of answer)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]authority (Control display of authority)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]additional (Control display of additional)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]short (Disable everything except short\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" form of answer)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]all (Set or clear all display flags)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +qr (Print question before sending)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]cdflag (Set or clear CD flag in query)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]adflag (Set or clear AD flag in query)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]nssearch (Search all authorative nameservers)\n"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉" +[no]identify (ID responders in short answers)\n"
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff" +[no]trace (Trace delegation down from root)\n"
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff" global d-opts and servers (before host name) affect all queries.\n"
607dc8013a8cb34cd03b59292aa1ac01e008c9c1Michael Graff" local d-opts and servers (after host name) affect only that lookup.\n"
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff, stderr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉dighost_shutdown(void) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 free_lists();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_app_shutdown();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graffvoid
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_uint64_t diff;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_time_t now;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 time_t tnow;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_time_now(&now);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "isc_time_now");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (query->lookup->stats) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein diff = isc_time_microdiff(&now, &query->time_sent);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf(";; Query time: %ld msec\n", (long int)diff/1000);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf(";; SERVER: %.*s\n", frmsize, frm);
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington time(&tnow);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff printf(";; WHEN: %s", ctime(&tnow));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf(";; MSG SIZE rcvd: %d\n", bytes);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (key != NULL) {
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (!validated)
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff puts(";; WARNING -- Some TSIG could not "
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "be validated");
ce5bd92088923d1c76e26d313d1d8c0b8bbe38feMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if ((key == NULL) && (keysecret[0] != 0)) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein puts(";; WARNING -- TSIG key was not used.");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff puts("");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (query->lookup->identify && !short_form) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff diff = isc_time_microdiff(&now, &query->time_sent);
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington printf(";; Received %u bytes from %.*s(%s) in %d ms\n\n",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein bytes, frmsize, frm, query->servname,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff (int)diff/1000);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinvoid
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeintrying(int frmsize, char *frm, dig_lookup_t *lookup) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein UNUSED(frmsize);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews UNUSED(frm);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(lookup);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff}
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsstatic isc_result_t
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewssay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews isc_result_t result;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_uint64_t diff;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_time_t now;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff char store[sizeof("12345678901234567890")];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (query->lookup->trace || query->lookup->ns_search_only) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_rdatatype_totext(rdata->type, buf);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (result != ISC_R_SUCCESS)
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff return (result);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ADD_STRING(buf, " ");
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff }
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff result = dns_rdata_totext(rdata, NULL, buf);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff check_result(result, "dns_rdata_totext");
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (query->lookup->identify) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews result = isc_time_now(&now);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 diff = isc_time_microdiff(&now, &query->time_sent);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ADD_STRING(buf, " from server ");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ADD_STRING(buf, query->servname);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 snprintf(store, 19, " in %d ms.", (int)diff/1000);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ADD_STRING(buf, store);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ADD_STRING(buf, "\n");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graffshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence isc_buffer_t *buf, dig_query_t *query)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_name_t *name;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_rdataset_t *rdataset;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_t target;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_result_t result, loopresult;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington dns_name_t empty_name;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char t[4096];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_rdata_t rdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(flags);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff dns_name_init(&empty_name, NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_NOMORE)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff else if (result != ISC_R_SUCCESS)
8470db5b12c18cfb32a757e265ce4e7789052c92Michael Graff return (result);
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff for (;;) {
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews name = NULL;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff isc_buffer_init(&target, t, sizeof(t));
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (rdataset = ISC_LIST_HEAD(name->list);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rdataset != NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rdataset = ISC_LIST_NEXT(rdataset, link)) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 loopresult = dns_rdataset_first(rdataset);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while (loopresult == ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_rdataset_current(rdataset, &rdata);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = say_message(&rdata, query,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff buf);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff check_result(result, "say_message");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff loopresult = dns_rdataset_next(rdataset);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (result == ISC_R_NOMORE)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff break;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews else if (result != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffisc_result_t
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_boolean_t did_flag = ISC_FALSE;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson isc_result_t result;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson dns_messagetextflag_t flags;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson isc_buffer_t *buf = NULL;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson unsigned int len = OUTPUTBUF;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff UNUSED(query);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff debug("printmessage(%s)", headers ? "headers" : "noheaders");
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington /*
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington * Exitcode 9 means we timed out, but if we're printing a message,
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington * we must have recovered. Go ahead and reset it to code 0, and
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff * call this a success.
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff */
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if (exitcode == 9)
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff exitcode = 0;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff flags = 0;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (!headers) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson }
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if (!query->lookup->comments)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = ISC_R_SUCCESS;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = isc_buffer_allocate(mctx, &buf, len);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff check_result(result, "isc_buffer_allocate");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson if (query->lookup->comments && !short_form) {
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson if (!query->lookup->doing_xfr) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (msg == query->lookup->sendmsg)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf(";; Sending:\n");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff else
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf(";; Got answer:\n");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (headers) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf(";; ->>HEADER<<- opcode: %s, status: %s, "
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff "id: %u\n",
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff opcodetext[msg->opcode], rcodetext[msg->rcode],
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson msg->id);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson printf(";; flags: ");
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson printf("qr");
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson did_flag = ISC_TRUE;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf("%saa", did_flag ? " " : "");
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff did_flag = ISC_TRUE; }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff printf("%stc", did_flag ? " " : "");
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff did_flag = ISC_TRUE;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff }
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington printf("%srd", did_flag ? " " : "");
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington did_flag = ISC_TRUE;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff printf("%sra", did_flag ? " " : "");
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff did_flag = ISC_TRUE;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff }
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf("%sad", did_flag ? " " : "");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff did_flag = ISC_TRUE;
ec46482ef3c0c3e9747f0074cb9263adb8aef961Andreas Gustafsson }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff printf("%scd", did_flag ? " " : "");
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff did_flag = ISC_TRUE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff printf("; QUERY: %u, ANSWER: %u, "
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff "AUTHORITY: %u, ADDITIONAL: %u\n",
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff msg->counts[DNS_SECTION_QUESTION],
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff msg->counts[DNS_SECTION_ANSWER],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 msg->counts[DNS_SECTION_AUTHORITY],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 msg->counts[DNS_SECTION_ADDITIONAL]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_pseudosectiontotext(msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_PSEUDOSECTION_OPT,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "dns_message_pseudosectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (query->lookup->section_question && headers) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!short_form) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 question_again:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_sectiontotext(msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_SECTION_QUESTION,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_NOSPACE) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 len += OUTPUTBUF;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_free(&buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &buf, len);
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (result == ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto question_again;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "dns_message_sectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (query->lookup->section_answer) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!short_form) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 answer_again:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_sectiontotext(msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_SECTION_ANSWER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (result == ISC_R_NOSPACE) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 len += OUTPUTBUF;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_free(&buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &buf, len);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto answer_again;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "dns_message_sectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = short_answer(msg, flags, buf, query);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "short_answer");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (query->lookup->section_authority) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!short_form) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 authority_again:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_sectiontotext(msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_SECTION_AUTHORITY,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_NOSPACE) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 len += OUTPUTBUF;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_free(&buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &buf, len);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto authority_again;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "dns_message_sectiontotext");
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (query->lookup->section_additional) {
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (!short_form) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 additional_again:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_sectiontotext(msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_SECTION_ADDITIONAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_NOSPACE) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 len += OUTPUTBUF;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_free(&buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_buffer_allocate(mctx, &buf, len);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto additional_again;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result, "dns_message_sectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Only print the signature on the first record.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (headers) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_pseudosectiontotext(
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_PSEUDOSECTION_TSIG,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "dns_message_pseudosectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_pseudosectiontotext(
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 DNS_PSEUDOSECTION_SIG0,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 flags, buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 check_result(result,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "dns_message_pseudosectiontotext");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (headers && query->lookup->comments && !short_form)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf("\n");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf("%.*s", (int)isc_buffer_usedlength(buf),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (char *)isc_buffer_base(buf));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_free(&buf);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉printgreeting(int argc, char **argv) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int i = 1;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (printcmd) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 puts("");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf("; <<>> DiG 9.0 <<>>");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while (i < argc) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf(" %s", argv[i++]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 puts("");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printf(";; global options: %s %s\n",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 short_form ? "short_form" : "",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printcmd ? "printcmd" : "");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Reorder an argument list so that server names all come at the end.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * This is a bit of a hack, to allow batch-mode processing to properly
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * handle the server options.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉reorder_args(int argc, char *argv[]) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int i, j;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *ptr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int end;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 debug("reorder_args()");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 end = argc - 1;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while (argv[end][0] == '@') {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 end--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (end == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff debug("arg[end]=%s", argv[end]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (i = 1; i < end - 1; i++) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (argv[i][0] == '@') {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 debug("arg[%d]=%s", i, argv[i]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ptr = argv[i];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (j = i + 1; j < end; j++) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 debug("Moving %s to %d", argv[j], j - 1);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 argv[j - 1] = argv[j];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 debug("moving %s to end, %d", ptr, end - 1);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 argv[end - 1] = ptr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 end--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (end < 1)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff * We're not using isc_commandline_parse() here since the command line
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * syntax of dig is quite a bit different from that which can be described
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff * that routine. There is a portability issue here.
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff */
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graffstatic void
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graffparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_boolean_t have_host = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dig_server_t *srv = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dig_lookup_t *lookup = NULL;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff static dig_lookup_t *default_lookup = NULL;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff char *batchname = NULL;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff char batchline[MXNAME];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char address[MXNAME];
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews FILE *fp = NULL;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff int bargc;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews char *bargv[16];
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff int i, n;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff int adrs[4];
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff int rc;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff char **rv;
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson char *ptr;
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * The semantics for parsing the args is a bit complex; if
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * we don't have a host yet, make the arg apply globally,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * otherwise make it apply to the latest host. This is
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * a bit different than the previous versions, but should
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * form a consistent user interface.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff *
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * First, create a "default lookup" which won't actually be used
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * anywhere, except for cloning into new lookups
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (!is_batchfile)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff default_lookup = make_empty_lookup();
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup = default_lookup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff rc = argc;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff rv = argv;
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson for (rc--, rv++; rc > 0; rc--, rv++) {
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson debug("main parsing %s", rv[0]);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson if (strncmp(rv[0], "%", 1) == 0)
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson break;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (strncmp(rv[0], "@", 1) == 0) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews srv = isc_mem_allocate(mctx,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff sizeof(struct dig_server));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (srv == NULL)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fatal("Memory allocation failure");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff strncpy(srv->servername, &rv[0][1], MXNAME-1);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (!lookup->use_my_server_list) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_INIT(lookup->
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff my_server_list);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->use_my_server_list =
c17c59662f0969a5e52e8b7529cbde1a7c746095Andreas Gustafsson ISC_TRUE;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews }
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews ISC_LIST_APPEND(lookup->my_server_list,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff srv, link);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff } else if ((strcmp(rv[0], "+vc") == 0)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff && (!is_batchfile)) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->tcp_mode = ISC_TRUE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff } else if ((strcmp(rv[0], "+novc") == 0)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff && (!is_batchfile)) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->tcp_mode = ISC_FALSE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } else if ((strcmp(rv[0], "+tcp") == 0)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff && (!is_batchfile)) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lookup->tcp_mode = ISC_TRUE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if ((strcmp(rv[0], "+notcp") == 0)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff && (!is_batchfile)) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lookup->tcp_mode = ISC_FALSE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+domain=", 8) == 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /* Global option always */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff strncpy(fixeddomain, &rv[0][8], MXNAME);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+sea", 4) == 0) {
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington /* Global option always */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff usesearch = ISC_TRUE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+nosea", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 usesearch = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+defn", 5) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->defname = ISC_TRUE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+nodefn", 7) == 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lookup->defname = ISC_FALSE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+time=", 6) == 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /* Global option always */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff timeout = atoi(&rv[0][6]);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (timeout <= 0)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff timeout = 1;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff debug("timeout set to %d", timeout);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff } else if (strncmp(rv[0], "+timeout=", 9) == 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /* Global option always */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff timeout = atoi(&rv[0][9]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (timeout <= 0)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff timeout = 1;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington debug("timeout set to %d", timeout);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff } else if (strncmp(rv[0], "+tries=", 7) == 0) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->retries = atoi(&rv[0][7]);
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington if (lookup->retries <= 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->retries = 1;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+buf=", 5) == 0) {
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff lookup->udpsize = atoi(&rv[0][5]);
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington if (lookup->udpsize <= 0)
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->udpsize = 0;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington if (lookup->udpsize > COMMSIZE)
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->udpsize = COMMSIZE;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington } else if (strncmp(rv[0], "+bufsize=", 9) == 0) {
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff lookup->udpsize = atoi(&rv[0][9]);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (lookup->udpsize <= 0)
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->udpsize = 0;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (lookup->udpsize > COMMSIZE)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->udpsize = COMMSIZE;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff } else if (strncmp(rv[0], "+ndots=", 7) == 0) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff /* Global option always */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ndots = atoi(&rv[0][7]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (ndots < 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ndots = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+rec", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->recurse = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+norec", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->recurse = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+adf", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->adflag = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noadf", 6) == 0) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->adflag = ISC_FALSE;
04458c8b5da001294e820289b34bf3aee6258f27Michael Graff } else if (strncmp(rv[0], "+cd", 3) == 0) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lookup->cdflag = ISC_TRUE;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington } else if (strncmp(rv[0], "+nocd", 5) == 0) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->cdflag = ISC_FALSE;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington } else if (strncmp(rv[0], "+ns", 3) == 0) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->ns_search_only = ISC_TRUE;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington lookup->trace_root = ISC_TRUE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff lookup->recurse = ISC_FALSE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff lookup->identify = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!forcecomment)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nons", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->ns_search_only = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+tr", 3) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->trace = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->trace_root = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->recurse = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->identify = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!forcecomment) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_details = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+notr", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->trace = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->trace_root = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+det", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_details = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nodet", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_details = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+cmd", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printcmd = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nocmd", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printcmd = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+sho", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 short_form = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 printcmd = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (!forcecomment) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nosho", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 short_form = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+id", 3) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->identify = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noid", 5) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->identify = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+com", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 forcecomment = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nocom", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 forcecomment = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+sta", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+nosta", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->stats = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+qr", 3) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 qr = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noqr", 5) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 qr = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+que", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noque", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+ans", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_answer = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noans", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_answer = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+add", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noadd", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+aut", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noaut", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+all", 4) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_answer = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "+noall", 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_question = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_authority = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_answer = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->section_additional = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->comments = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "-c", 2) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (rv[0][2] != 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(lookup->rctext, &rv[0][2],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 MXRD);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(lookup->rctext, rv[1],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 MXRD);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rv++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rc--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "-t", 2) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (rv[0][2] != 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(lookup->rttext, &rv[0][2],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 MXRD);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(lookup->rttext, rv[1],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 MXRD);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rv++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rc--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "-f", 2) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (rv[0][2] != 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 batchname = &rv[0][2];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 batchname = rv[1];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rv++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rc--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "-y", 2) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (rv[0][2] != 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ptr = &rv[0][2];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ptr = rv[1];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rv++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rc--;
34350037a886e7a16728335821da2bbff95683a9Evan Hunt }
34350037a886e7a16728335821da2bbff95683a9Evan Hunt ptr = strtok(ptr,":");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ptr == NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_usage();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 exit(exitcode);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(keynametext, ptr, MXNAME);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ptr = strtok(NULL, "");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ptr == NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_usage();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 exit(exitcode);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(keysecret, ptr, MXNAME);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strncmp(rv[0], "-p", 2) == 0) {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt if (rv[0][2] != 0) {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt port = atoi(&rv[0][2]);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt } else {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt port = atoi(rv[1]);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt rv++;
34350037a886e7a16728335821da2bbff95683a9Evan Hunt rc--;
34350037a886e7a16728335821da2bbff95683a9Evan Hunt }
34350037a886e7a16728335821da2bbff95683a9Evan Hunt } else if (strncmp(rv[0], "-b", 2) == 0) {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt if (rv[0][2] != 0) {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt strncpy(address, &rv[0][2],
34350037a886e7a16728335821da2bbff95683a9Evan Hunt MXRD);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strncpy(address, rv[1],
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 MXRD);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff rv++;
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson rc--;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 get_address(address, 0, &bind_address);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson specified_source = ISC_TRUE;
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson } else if (strncmp(rv[0], "-h", 2) == 0) {
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff show_usage();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 exit(exitcode);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strcmp(rv[0], "-memdebug") == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_debugging = 1;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } else if (strcmp(rv[0], "-debug") == 0) {
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff debugging = ISC_TRUE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } else if (strncmp(rv[0], "-x", 2) == 0) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews /*
bd7237e653e15bfb7f202a1c0914271912597ef4Michael Graff * XXXMWS Only works for ipv4 now.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Can't use inet_pton here, since we allow
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * partial addresses.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (rc == 1) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 show_usage();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 exit(exitcode);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 n = sscanf(rv[1], "%d.%d.%d.%d", &adrs[0], &adrs[1],
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff &adrs[2], &adrs[3]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (n == 0)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff show_usage();
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff lookup = clone_lookup(default_lookup, ISC_TRUE);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff for (i = n - 1; i >= 0; i--) {
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence snprintf(batchline, MXNAME/8, "%d.",
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff adrs[i]);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews strncat(lookup->textname, batchline, MXNAME);
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff }
ce5bd92088923d1c76e26d313d1d8c0b8bbe38feMichael Graff strncat(lookup->textname, "in-addr.arpa.", MXNAME);
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley debug("looking up %s", lookup->textname);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews lookup->trace_root = ISC_TF(lookup->trace ||
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews lookup->ns_search_only);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff strcpy(lookup->rttext, "ptr");
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff strcpy(lookup->rctext, "in");
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley lookup->new_search = ISC_TRUE;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews ISC_LIST_APPEND(lookup_list, lookup, link);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews have_host = ISC_TRUE;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews rv++;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews rc--;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /*
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * If we decide to allow query type and class
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * to be specified (without -t and -c options)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * before a host is given, all that needs to
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * happen is the have_host test here get removed.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Nothing should break by doing this.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (have_host) {
8470db5b12c18cfb32a757e265ce4e7789052c92Michael Graff if (strncmp(rv[0], "ixfr=", 5) == 0) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff strcpy(lookup->rttext, "ixfr");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->ixfr_serial =
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews atoi(&rv[0][5]);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews continue;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if (istype(rv[0])) {
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews strncpy(lookup->rttext, rv[0], MXRD);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews continue;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff } else if (isclass(rv[0])) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff strncpy(lookup->rctext, rv[0],
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff MXRD);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff continue;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup=clone_lookup(default_lookup, ISC_TRUE);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff strncpy(lookup->textname, rv[0], MXNAME-1);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->trace_root = ISC_TF(lookup->trace ||
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff lookup->ns_search_only);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lookup->new_search = ISC_TRUE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_APPEND(lookup_list, lookup, link);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_INIT(lookup->my_server_list);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff have_host = ISC_TRUE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff debug("looking up %s", lookup->textname);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence if (batchname != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fp = fopen(batchname, "r");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (fp == NULL) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff perror(batchname);
ce10da99834b806d5a92a6e5b4c8ff3990a4ae0fBrian Wellington if (exitcode < 10)
ce10da99834b806d5a92a6e5b4c8ff3990a4ae0fBrian Wellington exitcode = 10;
5e589b5356a4125b5af32605dead82ab8b467c88Mark Andrews fatal("Couldn't open specified batch file");
5e589b5356a4125b5af32605dead82ab8b467c88Mark Andrews }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff while (fgets(batchline, sizeof(batchline), fp) != 0) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff debug("batch line %s", batchline);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff bargc = 1;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff bargv[bargc] = strtok(batchline, " \t\r\n");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while ((bargv[bargc] != NULL) && (bargc < 14 )) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 bargc++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 bargv[bargc] = strtok(NULL, " \t\r\n");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 bargv[0] = argv[0];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 reorder_args(bargc, (char **)bargv);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 parse_args(ISC_TRUE, bargc, (char **)bargv);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (lookup_list.head == NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup=clone_lookup(default_lookup, ISC_TRUE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->trace_root = ISC_TF(lookup->trace ||
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->ns_search_only);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lookup->new_search = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strcpy(lookup->textname, ".");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strcpy(lookup->rttext, "NS");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LIST_APPEND(lookup_list, lookup, link);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (!is_batchfile)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff printgreeting(argc, argv);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffint
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉main(int argc, char **argv) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_result_t result;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_INIT(lookup_list);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_INIT(server_list);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_INIT(search_list);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff debug("main()");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff progname = argv[0];
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff setup_libs();
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 parse_args(ISC_FALSE, argc, argv);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff setup_system();
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff check_result(result, "isc_app_onrun");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_app_run();
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXMWS This code should really NOT be bypassed. However,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * until the proper code can be added to handle SIGTERM/INT
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * correctly, just exit out "hard" and deal as best we can.
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff */
58efc48a9623797187726360efb57cbabd916f0dMichael Graff#if 0
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (taskmgr != NULL) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews debug("Freeing taskmgr");
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington isc_taskmgr_destroy(&taskmgr);
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (isc_mem_debugging)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_stats(mctx, stderr);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (mctx != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_mem_destroy(&mctx);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_app_finish();
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff#endif
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews return (exitcode);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff}
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
8ed2c82a73a6c0a9c04ad26a4ef39b5a738099f6Andreas Gustafsson