dig.c revision 960c8888f620585d068e63ac9b9d1c59182bffc2
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15a44745412679c30a6d022733925af70a38b715David Lawrence * SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
471e0563c7965c556c759775882cd3448dae78eaMark Andrews/* $Id: dig.c,v 1.43 2000/06/07 00:13:54 mws Exp $ */
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <config.h>
de153390f5a1f6d4fa86af91d4cae772d9846ca0Mark Andrews
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <stdlib.h>
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellingtonextern int h_errno;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/app.h>
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson#include <isc/string.h>
25a66b4e41e2b0a2af4840749bac80ae78c678bfMark Andrews#include <isc/util.h>
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
21f1794606dce19928cf455029e173321f166380Mark Andrews#include <dns/message.h>
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews#include <dns/name.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <dns/rdata.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/rdataset.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/rdatatype.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/message.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington#include <dig/dig.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsextern ISC_LIST(dig_lookup_t) lookup_list;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrewsextern ISC_LIST(dig_server_t) server_list;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceextern ISC_LIST(dig_searchlist_t) search_list;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define ADD_STRING(b, s) {if (strlen(s) >= \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews isc_buffer_availablelength(b)) \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return(ISC_R_NOSPACE); else \
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putstr(b, s);}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern isc_boolean_t have_ipv6, show_details, specified_source,
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews usesearch, qr;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern in_port_t port;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern unsigned int timeout;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern isc_mem_t *mctx;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern dns_messageid_t id;
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrewsextern char *rootspace[BUFSIZE];
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern isc_buffer_t rootbuf;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern int sendcount;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern int ndots;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern int tries;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern int lookup_counter;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsextern char fixeddomain[MXNAME];
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#ifdef TWIDDLE
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrewsextern isc_boolean_t twiddle;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#endif
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrewsextern int exitcode;
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrewsextern isc_sockaddr_t bind_address;
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrenceextern char keynametext[MXNAME];
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceextern char keysecret[MXNAME];
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsextern dns_tsigkey_t *key;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsextern isc_boolean_t validated;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceextern isc_boolean_t debugging;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceextern isc_boolean_t isc_mem_debugging;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrenceisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_uint16_t bufsize = 0;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_boolean_t identify = ISC_FALSE,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence trace = ISC_FALSE, ns_search_only = ISC_FALSE,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence forcecomment = ISC_FALSE, stats = ISC_TRUE,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence comments = ISC_TRUE, section_question = ISC_TRUE,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence section_answer = ISC_TRUE, section_authority = ISC_TRUE,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence section_additional = ISC_TRUE, recurse = ISC_TRUE,
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence defname = ISC_TRUE, aaonly = ISC_FALSE, tcpmode = ISC_FALSE;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestatic const char *opcodetext[] = {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "QUERY",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "IQUERY",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "STATUS",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "RESERVED3",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "NOTIFY",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "UPDATE",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "RESERVED6",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "RESERVED7",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED8",
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "RESERVED9",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED10",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED11",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED12",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED13",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED14",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "RESERVED15"
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson};
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafssonstatic const char *rcodetext[] = {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson "NOERROR",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "FORMERR",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "SERVFAIL",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "NXDOMAIN",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "NOTIMPL",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "REFUSED",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "YXDOMAIN",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "YXRRSET",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "NXRRSET",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "NOTAUTH",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "NOTZONE",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "RESERVED11",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "RESERVED12",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "RESERVED13",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "RESERVED14",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "RESERVED15",
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "BADVERS"
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence};
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtonstatic void
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtonshow_usage(void) {
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington fputs (
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" {global-d-opt} host [@local-server] {local-d-opt}\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" [ host [@local-server] {local-d-opt} [...]]\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence"Where: domain are in the Domain Name System\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" q-class is one of (in,chaos,...) [default: in]\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" (Use ixfr=version for type ixfr)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" q-opt is one of:\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -x dot-notation (shortcut for in-addr lookups)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -f filename (batch mode)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -p port (specify port number)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -t type (specify query type)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -c class (specify query class)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" -y name:key (specify named base64 tsig key)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" d-opt is of the form +keyword[=value], where keyword is:\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]vc (TCP mode)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]tcp (TCP mode, alternate syntax)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +time=### (Set query timeout) [5]\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +tries=### (Set number of UDP attempts) [3]\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +domain=### (Set default domainname)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]search (Set whether to use searchlist)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]defname (Set whether to use default domaon)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]recursive (Recursive mode)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]aaonly (Set AA flag in query)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]details (Show details of all requests)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#ifdef TWIDDLE
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +twiddle (Intentionally form bad requests)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#endif
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +ndots=### (Set NDOTS value)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]comments (Control display of comment lines)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]question (Control display of question)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]answer (Control display of answer)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]authority (Control display of authority)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]additional (Control display of additional)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]short (Disable everything except short\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" form of answer)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +qr (Print question before sending)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" Additional d-opts subject to removal before release:\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]nssearch (Search all authorative nameservers)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]identify (ID responders in short answers)\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" Available but not yet completed:\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence" +[no]trace (Trace delegation down from root)\n"
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson" global d-opts and servers (before host name) affect all queries.\n"
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson" local d-opts and servers (after host name) affect only that lookup.\n"
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence, stderr);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence}
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencevoid
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedighost_shutdown(void) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_app_shutdown();
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews}
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsvoid
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencereceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_uint64_t diff;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_time_t now;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson isc_result_t result;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews time_t tnow;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews result = isc_time_now(&now);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews check_result (result, "isc_time_now");
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews if (query->lookup->stats) {
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews printf(";; Query time: %ld msec\n", (long int)diff/1000);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews printf(";; SERVER: %.*s\n", frmsize, frm);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews time (&tnow);
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews printf(";; WHEN: %s", ctime(&tnow));
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews printf (";; MSG SIZE rcvd: %d\n", bytes);
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews if (key != NULL) {
aa05bbdef7f7827dde158dcc913f4dade84c8511Brian Wellington if (!validated)
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews puts (";; WARNING -- Some TSIG could not "
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews "be validated");
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews }
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews if ((key == NULL) && (keysecret[0] != 0)) {
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews puts (";; WARNING -- TSIG key was not used.");
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews }
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews puts ("");
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews } else if (query->lookup->identify && !short_form) {
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews printf(";; Received %u bytes from %.*s in %d ms\n",
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington bytes, frmsize, frm, (int)diff/1000);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews }
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsvoid
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewstrying(int frmsize, char *frm, dig_lookup_t *lookup) {
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews UNUSED (frmsize);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews UNUSED (frm);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews UNUSED (lookup);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic isc_result_t
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewssay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff isc_result_t result;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews isc_uint64_t diff;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews isc_time_t now;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews char store[sizeof("12345678901234567890")];
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (query->lookup->trace || query->lookup->ns_search_only) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_rdatatype_totext(rdata->type, buf);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews ADD_STRING(buf, " ");
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews }
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews result = dns_rdata_totext(rdata, NULL, buf);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews check_result(result, "dns_rdata_totext");
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (query->lookup->identify) {
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews result = isc_time_now(&now);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (result != ISC_R_SUCCESS)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews return (result);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews ADD_STRING(buf, " from server ");
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews ADD_STRING(buf, query->servname);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews snprintf (store, 19, " in %d ms.", (int)diff/1000);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews ADD_STRING(buf, store);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews }
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews ADD_STRING(buf,"\n");
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (ISC_R_SUCCESS);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington}
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrewsstatic isc_result_t
613991eef6bb79b9703382aff26cddd0281da915Bob Halleyshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_buffer_t *buf, dig_query_t *query)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews{
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington dns_name_t *name;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington dns_rdataset_t *rdataset;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington isc_buffer_t target;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington isc_result_t result, loopresult;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington dns_name_t empty_name;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington char t[4096];
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington dns_rdata_t rdata;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington UNUSED (flags);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson dns_name_init(&empty_name, NULL);
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews if (result == ISC_R_NOMORE)
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson return (ISC_R_SUCCESS);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews else if (result != ISC_R_SUCCESS)
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews return (result);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews for (;;) {
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews name = NULL;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
36e37042c6c9252cdf6eb99bd71ccb6e6c43ba6dBrian Wellington
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews isc_buffer_init(&target, t, sizeof(t));
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington for (rdataset = ISC_LIST_HEAD(name->list);
d9af67ef70db20f94a954cca237b3fdb30ac2bc7Brian Wellington rdataset != NULL;
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington rdataset = ISC_LIST_NEXT(rdataset, link)) {
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington loopresult = dns_rdataset_first(rdataset);
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington while (loopresult == ISC_R_SUCCESS) {
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington dns_rdataset_current(rdataset, &rdata);
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington result = say_message(&rdata, query,
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington buf);
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington check_result (result, "say_message");
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews loopresult = dns_rdataset_next(
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews rdataset);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (result == ISC_R_NOMORE)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson break;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else if (result != ISC_R_SUCCESS)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (result);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews return (ISC_R_SUCCESS);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff}
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_result_t
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff isc_boolean_t did_flag = ISC_FALSE;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington isc_result_t result;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington dns_messagetextflag_t flags;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff isc_buffer_t *buf = NULL;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff UNUSED (query);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson debug ("printmessage(%s)",headers?"headers":"noheaders");
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Exitcode 9 means we timed out, but if we're printing a message,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * we much have recovered. Go ahead and reset it to code 0, and
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * call this a success.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (exitcode == 9)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson exitcode = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson flags = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (!headers) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (!query->lookup->comments)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ISC_R_SUCCESS;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = isc_buffer_allocate(mctx, &buf, OUTPUTBUF);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson check_result (result, "isc_buffer_allocate");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (query->lookup->comments && !short_form) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (!query->lookup->doing_xfr) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (msg == query->lookup->sendmsg)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson printf (";; Sending:\n");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson printf (";; Got answer:\n");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (headers) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson printf(";; ->>HEADER<<- opcode: %s, status: %s, "
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "id: %u\n",
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson opcodetext[msg->opcode], rcodetext[msg->rcode],
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson msg->id);
b0c15bd9792112fb47f6d956e580e4369e92f4e7Mark Andrews printf(";; flags: ");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson printf("qr");
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews did_flag = ISC_TRUE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("%saa", did_flag ? " " : "");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews did_flag = ISC_TRUE; }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("%stc", did_flag ? " " : "");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews did_flag = ISC_TRUE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("%srd", did_flag ? " " : "");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews did_flag = ISC_TRUE;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
e6bd97dded968f82e26b270842b789bff7bca422Mark Andrews printf("%sra", did_flag ? " " : "");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews did_flag = ISC_TRUE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("%sad", did_flag ? " " : "");
5d2026ea7b5ae43bbd69d98b747f75ba3290bef1Mark Andrews did_flag = ISC_TRUE;
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington }
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews printf("%scd", did_flag ? " " : "");
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews did_flag = ISC_TRUE;
5d2026ea7b5ae43bbd69d98b747f75ba3290bef1Mark Andrews }
6c29053a20f7614167bafa4388c666644a095349Andreas Gustafsson
5d2026ea7b5ae43bbd69d98b747f75ba3290bef1Mark Andrews printf("; QUERY: %u, ANSWER: %u, "
5d2026ea7b5ae43bbd69d98b747f75ba3290bef1Mark Andrews "AUTHORITY: %u, ADDITIONAL: %u\n",
6c29053a20f7614167bafa4388c666644a095349Andreas Gustafsson msg->counts[DNS_SECTION_QUESTION],
6c29053a20f7614167bafa4388c666644a095349Andreas Gustafsson msg->counts[DNS_SECTION_ANSWER],
5d2026ea7b5ae43bbd69d98b747f75ba3290bef1Mark Andrews msg->counts[DNS_SECTION_AUTHORITY],
5f7a9845e900bc491db9feab137895721073631fMark Andrews msg->counts[DNS_SECTION_ADDITIONAL]);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_message_pseudosectiontotext(msg,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews DNS_PSEUDOSECTION_OPT,
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews flags, buf);
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews check_result(result,
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews "dns_message_pseudosectiontotext");
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington }
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington }
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (query->lookup->section_question && headers) {
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews if (!short_form) {
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews result = dns_message_sectiontotext(msg,
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews DNS_SECTION_QUESTION,
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews flags, buf);
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews check_result(result, "dns_message_sectiontotext");
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews }
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews }
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews if (query->lookup->section_answer) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (!short_form) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_message_sectiontotext(msg,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews DNS_SECTION_ANSWER,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews flags, buf);
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews check_result(result, "dns_message_sectiontotext");
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews else {
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington result = short_answer(msg, flags, buf, query);
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington check_result (result, "short_answer");
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington }
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington }
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (query->lookup->section_authority) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (!short_form) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_message_sectiontotext(msg,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews DNS_SECTION_AUTHORITY,
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews flags, buf);
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews check_result(result, "dns_message_sectiontotext");
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews }
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews }
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews if (query->lookup->section_additional) {
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews if (!short_form) {
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews result = dns_message_sectiontotext(msg,
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews DNS_SECTION_ADDITIONAL,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews flags, buf);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews check_result(result, "dns_message_sectiontotext");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* Only print the signature on the first record */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (headers) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_message_pseudosectiontotext(
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence msg,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews DNS_PSEUDOSECTION_TSIG,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews flags, buf);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews check_result(result,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "dns_message_pseudosectiontotext");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_message_pseudosectiontotext(
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews msg,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews DNS_PSEUDOSECTION_SIG0,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews flags, buf);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews check_result(result,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "dns_message_pseudosectiontotext");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (headers && query->lookup->comments && !short_form)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("\n");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf ("%.*s",(int)isc_buffer_usedlength(buf),
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (char *)isc_buffer_base(buf));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_free(&buf);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (result);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic void
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundssonprintgreeting(int argc, char **argv) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int i = 1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (printcmd) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews puts ("");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf ("; <<>> DiG 9.0 <<>>");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews while (i < argc) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf (" %s", argv[i++]);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews puts ("");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley printf (";; global options: %s %s\n",
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews short_form?"short_form":"",
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews printcmd?"printcmd":"");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
19d365e4448f1782611280b020987988b7ac3210Mark Andrews}
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington
19d365e4448f1782611280b020987988b7ac3210Mark Andrews/*
19d365e4448f1782611280b020987988b7ac3210Mark Andrews * Reorder an argument list so that server names all come at the end.
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * This is a bit of a hack, to allow batch-mode processing to properly
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * handle the server options.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyreorder_args(int argc, char *argv[]) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int i, j;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews char *ptr;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int end;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews debug ("reorder_args()");
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence end = argc-1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews while (argv[end][0] == '@') {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews end--;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews if (end == 0)
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews return;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews debug ("arg[end]=%s",argv[end]);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (i = 1; i<end-1; i++) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (argv[i][0] == '@') {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews debug ("Arg[%d]=%s", i, argv[i]);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff ptr = argv[i];
d981ca645597116d227a48bf37cc5edc061c854dBob Halley for (j = i+1; j<end; j++) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews debug ("Moving %s to %d", argv[j], j-1);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews argv[j-1] = argv[j];
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews }
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews debug ("Moving %s to end, %d", ptr, end-1);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff argv[end-1] = ptr;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews end--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (end < 1)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews }
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews/*
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington * We're not using isc_commandline_parse() here since the command line
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * syntax of dig is quite a bit different from that which can be described
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * that routine. There is a portability issue here.
19d365e4448f1782611280b020987988b7ac3210Mark Andrews */
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafssonstatic void
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafssonparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafsson isc_boolean_t have_host = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dig_server_t *srv = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dig_lookup_t *lookup = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews char *batchname = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char batchline[MXNAME];
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char address[MXNAME];
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews FILE *fp = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int bargc;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews char *bargv[16];
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char bargv0[sizeof("dig")];
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews int i, n;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews int adrs[4];
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews int rc;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char **rv;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char *ptr;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews /*
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews * The semantics for parsing the args is a bit complex; if
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews * we don't have a host yet, make the arg apply globally,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * otherwise make it apply to the latest host. This is
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * a bit different than the previous versions, but should
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * form a consistent user interface.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews rc = argc;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rv = argv;
ad7209ea70d346527ffdcda335153831341d9dcfAndreas Gustafsson for (rc--, rv++; rc > 0; rc--, rv++) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews debug ("Main parsing %s", rv[0]);
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews if (strncmp(rv[0], "@", 1) == 0) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews srv = isc_mem_allocate(mctx,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley sizeof(struct dig_server));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (srv == NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews fatal("Memory allocation failure.");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff strncpy(srv->servername, &rv[0][1], MXNAME-1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (is_batchfile && have_host) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (!lookup->use_my_server_list) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LIST_INIT (lookup->
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews my_server_list);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews lookup->use_my_server_list =
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_TRUE;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LIST_APPEND(lookup->my_server_list,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington srv, link);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews } else {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ISC_LIST_APPEND(server_list, srv, link);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews }
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley } else if ((strcmp(rv[0], "+vc") == 0)
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews && (!is_batchfile)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (have_host)
19d365e4448f1782611280b020987988b7ac3210Mark Andrews lookup->tcp_mode = ISC_TRUE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews else
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence tcpmode = ISC_TRUE;
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson } else if ((strcmp(rv[0], "+novc") == 0)
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson && (!is_batchfile)) {
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson if (have_host)
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews lookup->tcp_mode = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews else
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson tcpmode = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews } else if ((strcmp(rv[0], "+tcp") == 0)
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson && (!is_batchfile)) {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews if (have_host)
19d365e4448f1782611280b020987988b7ac3210Mark Andrews lookup->tcp_mode = ISC_TRUE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews else
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence tcpmode = ISC_TRUE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else if ((strcmp(rv[0], "+notcp") == 0)
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence && (!is_batchfile)) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (have_host)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff lookup->tcp_mode = ISC_FALSE;
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley else
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley tcpmode = ISC_FALSE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } else if (strncmp(rv[0], "+domain=", 8) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* Global option always */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff strncpy (fixeddomain, &rv[0][8], MXNAME);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews } else if (strncmp(rv[0], "+sea", 4) == 0) {
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence /* Global option always */
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence usesearch = ISC_TRUE;
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews } else if (strncmp(rv[0], "+nosea", 6) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews usesearch = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+defn", 5) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (have_host)
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson lookup->defname = ISC_TRUE;
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson else
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson defname = ISC_TRUE;
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson } else if (strncmp(rv[0], "+nodefn", 7) == 0) {
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson if (have_host)
3a16668468060842e847ea6556e80e1405d35cd6Brian Wellington lookup->defname = ISC_FALSE;
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson else
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington defname = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "+time=", 6) == 0) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington /* Global option always */
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews timeout = atoi(&rv[0][6]);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (timeout <= 0)
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington timeout = 1;
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington } else if (strncmp(rv[0], "+tries=", 7) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->retries = atoi(&rv[0][7]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (lookup->retries <= 0)
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->retries = 1;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews } else {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews tries = atoi(&rv[0][7]);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (tries <= 0)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews tries = 1;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington }
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else if (strncmp(rv[0], "+buf=", 5) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->udpsize = atoi(&rv[0][5]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (lookup->udpsize <= 0)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->udpsize = 0;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (lookup->udpsize > COMMSIZE)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->udpsize = COMMSIZE;
de5247ae1683ce145662180ee50272d2214a0232Andreas Gustafsson } else {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = atoi(&rv[0][5]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (bufsize <= 0)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = 0;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (bufsize > COMMSIZE)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = COMMSIZE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington }
f16495732753175e4a9fc144323a12fdcc29b561Brian Wellington } else if (strncmp(rv[0], "+bufsize=", 9) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->udpsize = atoi(&rv[0][9]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (lookup->udpsize <= 0)
e086935752b6e2f51ef2985fee21ccfff617b115David Lawrence lookup->udpsize = 0;
e086935752b6e2f51ef2985fee21ccfff617b115David Lawrence if (lookup->udpsize > COMMSIZE)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->udpsize = COMMSIZE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = atoi(&rv[0][9]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (bufsize <= 0)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = 0;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (bufsize > COMMSIZE)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington bufsize = COMMSIZE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington }
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson } else if (strncmp(rv[0], "+ndots=", 7) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington /* Global option always */
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington ndots = atoi(&rv[0][7]);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (ndots < 0)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington ndots = 0;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else if (strncmp(rv[0], "+rec", 4) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->recurse = ISC_TRUE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington else
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington recurse = ISC_TRUE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else if (strncmp(rv[0], "+norec", 6) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->recurse = ISC_FALSE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington else
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington recurse = ISC_FALSE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else if (strncmp(rv[0], "+aa", 3) == 0) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (have_host)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->aaonly = ISC_TRUE;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley else
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews aaonly = ISC_TRUE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington } else if (strncmp(rv[0], "+noaa", 5) == 0) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews if (have_host)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews lookup->aaonly = ISC_FALSE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff else
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews aaonly = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+ns", 3) == 0) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (have_host) {
f305d86668bfd4d4727c3e0f70e7e97a2fa1b772Bob Halley lookup->ns_search_only = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->recurse = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews lookup->identify = ISC_TRUE;
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence lookup->trace = ISC_TRUE;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence if (!forcecomment)
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews lookup->comments = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews lookup->section_additional = ISC_FALSE;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence lookup->section_authority = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews lookup->section_question = ISC_FALSE;
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington } else {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews ns_search_only = ISC_TRUE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews recurse = ISC_FALSE;
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews identify = ISC_TRUE;
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews if (!forcecomment)
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews comments = ISC_FALSE;
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews section_additional = ISC_FALSE;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews section_authority = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews section_question = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews } else if (strncmp(rv[0], "+nons", 6) == 0) {
228c679d7a269423019f7c528db92e855f08240bMark Andrews if (have_host)
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews lookup->ns_search_only = ISC_FALSE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews else
228c679d7a269423019f7c528db92e855f08240bMark Andrews ns_search_only = ISC_FALSE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington } else if (strncmp(rv[0], "+tr", 3) == 0) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (have_host) {
228c679d7a269423019f7c528db92e855f08240bMark Andrews lookup->trace = ISC_TRUE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews lookup->trace_root = ISC_TRUE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews lookup->recurse = ISC_FALSE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews lookup->identify = ISC_TRUE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews if (!forcecomment) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->comments = ISC_FALSE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews lookup->stats = ISC_FALSE;
228c679d7a269423019f7c528db92e855f08240bMark Andrews }
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews lookup->section_additional = ISC_FALSE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->section_authority = ISC_FALSE;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington lookup->section_question = ISC_FALSE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington show_details = ISC_TRUE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington } else {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington trace = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews recurse = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews identify = ISC_TRUE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (!forcecomment) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews comments = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews stats = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews section_additional = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews section_authority = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews section_question = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews show_details = ISC_TRUE;
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews }
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews } else if (strncmp(rv[0], "+notr", 6) == 0) {
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews if (have_host) {
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews lookup->trace = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews lookup->trace_root = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews else
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews trace = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else if (strncmp(rv[0], "+det", 4) == 0) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews show_details = ISC_TRUE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } else if (strncmp(rv[0], "+nodet", 6) == 0) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews show_details = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews } else if (strncmp(rv[0], "+cmd", 4) == 0) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews printcmd = ISC_TRUE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews } else if (strncmp(rv[0], "+nocmd", 6) == 0) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews printcmd = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews } else if (strncmp(rv[0], "+sho", 4) == 0) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff short_form = ISC_TRUE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews printcmd = ISC_FALSE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (have_host) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews lookup->section_additional = ISC_FALSE;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews lookup->section_authority = ISC_FALSE;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews lookup->section_question = ISC_FALSE;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews if (!forcecomment) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews lookup->comments = ISC_FALSE;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews lookup->stats = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff section_additional = ISC_FALSE;
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews section_authority = ISC_FALSE;
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews section_question = ISC_FALSE;
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews if (!forcecomment) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley comments = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews stats = ISC_FALSE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+nosho", 6) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews short_form = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+id", 3) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (have_host)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->identify = ISC_TRUE;
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley else
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley identify = ISC_TRUE;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews } else if (strncmp(rv[0], "+noid", 5) == 0) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (have_host)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews lookup->identify = ISC_FALSE;
471e0563c7965c556c759775882cd3448dae78eaMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews identify = ISC_FALSE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else if (strncmp(rv[0], "+com", 4) == 0) {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews if (have_host)
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence lookup->comments = ISC_TRUE;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence else
19d365e4448f1782611280b020987988b7ac3210Mark Andrews comments = ISC_TRUE;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence forcecomment = ISC_TRUE;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } else if (strncmp(rv[0], "+nocom", 6) == 0) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (have_host) {
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews lookup->comments = ISC_FALSE;
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews lookup->stats = ISC_FALSE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } else {
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews comments = ISC_FALSE;
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson stats = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews forcecomment = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "+sta", 4) == 0) {
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews if (have_host)
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->stats = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews stats = ISC_TRUE;
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews } else if (strncmp(rv[0], "+nosta", 6) == 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (have_host)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews lookup->stats = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews stats = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "+qr", 3) == 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews qr = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "+noqr", 5) == 0) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington qr = ISC_FALSE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington } else if (strncmp(rv[0], "+que", 4) == 0) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (have_host)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews lookup->section_question = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews section_question = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "+noque", 6) == 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (have_host)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews lookup->section_question = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews else
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews section_question = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+ans", 4) == 0) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (have_host)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence lookup->section_answer = ISC_TRUE;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson else
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews section_answer = ISC_TRUE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews } else if (strncmp(rv[0], "+noans", 6) == 0) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (have_host)
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews lookup->section_answer = ISC_FALSE;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence else
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence section_answer = ISC_FALSE;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } else if (strncmp(rv[0], "+add", 4) == 0) {
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson if (have_host)
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson lookup->section_additional = ISC_TRUE;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson else
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson section_additional = ISC_TRUE;
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley } else if (strncmp(rv[0], "+noadd", 6) == 0) {
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson if (have_host)
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson lookup->section_additional = ISC_FALSE;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff else
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson section_additional = ISC_FALSE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson } else if (strncmp(rv[0], "+aut", 4) == 0) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson if (have_host)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->section_authority = ISC_TRUE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews else
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews section_authority = ISC_TRUE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews } else if (strncmp(rv[0], "+noaut", 6) == 0) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (have_host)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence lookup->section_authority = ISC_FALSE;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence else
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence section_authority = ISC_FALSE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson } else if (strncmp(rv[0], "+all", 4) == 0) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson if (have_host) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->section_question = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->section_authority = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->section_answer = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson lookup->section_additional = ISC_TRUE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->comments = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson } else {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson section_question = ISC_TRUE;
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley section_authority = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson section_answer = ISC_TRUE;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson section_additional = ISC_TRUE;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff comments = ISC_TRUE;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews } else if (strncmp(rv[0], "+noall", 6) == 0) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews if (have_host) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews lookup->section_question = ISC_FALSE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff lookup->section_authority = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews lookup->section_answer = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews lookup->section_additional = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews lookup->comments = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews section_question = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews section_authority = ISC_FALSE;
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington section_answer = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews section_additional = ISC_FALSE;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews comments = ISC_FALSE;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#ifdef TWIDDLE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "+twiddle", 6) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews twiddle = ISC_TRUE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews#endif
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else if (strncmp(rv[0], "-c", 2) == 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (have_host) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rv[0][2] != 0) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews strncpy(lookup->rctext, &rv[0][2],
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews MXRD);
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews } else {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley strncpy(lookup->rctext, rv[1],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews MXRD);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff rv++;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rc--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (strncmp(rv[0], "-t", 2) == 0) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (have_host) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews if (rv[0][2] != 0) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff strncpy(lookup->rttext, &rv[0][2],
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews MXRD);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews strncpy(lookup->rttext, rv[1],
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews MXRD);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews rv++;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rc--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else if (strncmp(rv[0], "-f", 2) == 0) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (rv[0][2] != 0) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews batchname = &rv[0][2];
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews batchname = rv[1];
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews rv++;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews rc--;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews }
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews } else if (strncmp(rv[0], "-y", 2) == 0) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews if (rv[0][2] != 0)
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ptr = &rv[0][2];
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews else {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ptr = rv[1];
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff rv++;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley rc--;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ptr = strtok(ptr,":");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (ptr == NULL) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley show_usage();
d981ca645597116d227a48bf37cc5edc061c854dBob Halley exit (exitcode);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
d981ca645597116d227a48bf37cc5edc061c854dBob Halley strncpy(keynametext, ptr, MXNAME);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ptr = strtok(NULL, "");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (ptr == NULL) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley show_usage();
d981ca645597116d227a48bf37cc5edc061c854dBob Halley exit (exitcode);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews strncpy(keysecret, ptr, MXNAME);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley } else if (strncmp(rv[0], "-p", 2) == 0) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (rv[0][2] != 0) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley port = atoi(&rv[0][2]);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley port = atoi(rv[1]);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews rv++;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley rc--;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
d981ca645597116d227a48bf37cc5edc061c854dBob Halley } else if (strncmp(rv[0], "-b", 2) == 0) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (rv[0][2] != 0) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff strncpy(address, &rv[0][2],
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley MXRD);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } else {
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley strncpy(address, rv[1],
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews MXRD);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley rv++;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley rc--;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley }
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley get_address(address, 0, &bind_address);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley specified_source = ISC_TRUE;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley } else if (strncmp(rv[0], "-h", 2) == 0) {
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley show_usage();
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews exit (exitcode);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley } else if (strcmp(rv[0], "-memdebug") == 0) {
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley isc_mem_debugging = ISC_TRUE;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley } else if (strcmp(rv[0], "-debug") == 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews debugging = ISC_TRUE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews } else if (strncmp(rv[0], "-x", 2) == 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews /*
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews *XXXMWS Only works for ipv4 now.
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * Can't use inet_pton here, since we allow
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * partial addresses.
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley */
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley if (rc == 1) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff show_usage();
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff exit (exitcode);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
471e0563c7965c556c759775882cd3448dae78eaMark Andrews n = sscanf(rv[1], "%d.%d.%d.%d", &adrs[0], &adrs[1],
471e0563c7965c556c759775882cd3448dae78eaMark Andrews &adrs[2], &adrs[3]);
471e0563c7965c556c759775882cd3448dae78eaMark Andrews if (n == 0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff show_usage();
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff lookup = isc_mem_allocate(mctx,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence sizeof(struct dig_lookup));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (lookup == NULL)
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson fatal("Memory allocation failure.");
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->pending = ISC_FALSE;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->textname[0] = 0;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson for (i = n - 1; i >= 0; i--) {
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson snprintf(batchline, MXNAME/8, "%d.",
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson adrs[i]);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson strncat(lookup->textname, batchline, MXNAME);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson }
d56fa53141ef99613a998796b0858d6840db19f3Brian Wellington strncat(lookup->textname, "in-addr.arpa.", MXNAME);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson debug("Looking up %s", lookup->textname);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson strcpy(lookup->rttext, "ptr");
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson strcpy(lookup->rctext, "in");
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->namespace[0] = 0;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->sendspace[0] = 0;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->sendmsg = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->name = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->oname = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->timer = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->xfr_q = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->origin = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->querysig = NULL;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->use_my_server_list = ISC_FALSE;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->trace = ISC_TF(trace || ns_search_only);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->trace_root = trace;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->ns_search_only = ns_search_only;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->doing_xfr = ISC_FALSE;
d56fa53141ef99613a998796b0858d6840db19f3Brian Wellington lookup->ixfr_serial = 0;
d56fa53141ef99613a998796b0858d6840db19f3Brian Wellington lookup->defname = ISC_FALSE;
d56fa53141ef99613a998796b0858d6840db19f3Brian Wellington lookup->identify = identify;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->recurse = recurse;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->aaonly = aaonly;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->retries = tries;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->udpsize = bufsize;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->nsfound = 0;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->comments = comments;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->tcp_mode = tcpmode;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->stats = stats;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->section_question = section_question;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->section_answer = section_answer;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->section_authority = section_authority;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->section_additional = section_additional;
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson lookup->new_search = ISC_TRUE;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson ISC_LIST_INIT(lookup->q);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->origin = NULL;
d56fa53141ef99613a998796b0858d6840db19f3Brian Wellington ISC_LIST_INIT(lookup->my_server_list);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson ISC_LIST_APPEND(lookup_list, lookup, link);
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson have_host = ISC_TRUE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rv++;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson rc--;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (have_host) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson ENSURE(lookup != NULL);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (strncmp(rv[0],"ixfr=",5) == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strcpy(lookup->rttext, "ixfr");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff lookup->ixfr_serial =
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson atoi(&rv[0][5]);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson continue;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (istype(rv[0])) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strncpy(lookup->rttext, rv[0], MXRD);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff continue;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson } else if (isclass(rv[0])) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strncpy(lookup->rctext, rv[0],
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson MXRD);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson continue;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup = isc_mem_allocate(mctx,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson sizeof(struct dig_lookup));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (lookup == NULL)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson fatal("Memory allocation failure.");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->pending = ISC_FALSE;
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews strncpy(lookup->textname, rv[0], MXNAME-1);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->rttext[0] = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->rctext[0] = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lookup->namespace[0] = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->sendspace[0] = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->sendmsg = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->name = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->oname = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->timer = NULL;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->xfr_q = NULL;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence lookup->origin = NULL;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->querysig = NULL;
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence lookup->use_my_server_list = ISC_FALSE;
18360f880c46c8f0ca01703ae826c41ff8aca785Mark Andrews lookup->doing_xfr = ISC_FALSE;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->ixfr_serial = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->defname = ISC_FALSE;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->trace = ISC_TF(trace || ns_search_only);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->trace_root = trace;
fc024be774c7cdee938da018aa3994be746e36deDavid Lawrence lookup->ns_search_only = ns_search_only;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->identify = identify;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->recurse = recurse;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->aaonly = aaonly;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->retries = tries;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson lookup->udpsize = bufsize;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson lookup->nsfound = 0;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson lookup->comments = comments;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson lookup->tcp_mode = tcpmode;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson lookup->stats = stats;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->section_question = section_question;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->section_answer = section_answer;
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews lookup->section_authority = section_authority;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->section_additional = section_additional;
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews lookup->new_search = ISC_TRUE;
21ca3480cdcfe0c4c613e3e019e57c74d57ec994Mark Andrews ISC_LIST_INIT(lookup->q);
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews ISC_LIST_APPEND(lookup_list, lookup, link);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington lookup->origin = NULL;
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews ISC_LIST_INIT(lookup->my_server_list);
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews have_host = ISC_TRUE;
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews debug("Looking up %s", lookup->textname);
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews }
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews }
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews if (batchname != NULL) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington fp = fopen(batchname, "r");
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (fp == NULL) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington perror(batchname);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (exitcode < 10)
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff exitcode = 10;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff fatal("Couldn't open specified batch file.");
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington }
e6f17474cb43a138bf7fc9ad30c6b3a2847cb7a7Mark Andrews while (fgets(batchline, MXNAME, fp) != 0) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff debug ("Batch line %s", batchline);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff bargc = 1;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington bargv[bargc] = strtok(batchline, " \t\r\n");
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff while ((bargv[bargc] != NULL) && (bargc < 14 )) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff bargc++;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington bargv[bargc] = strtok(NULL, " \t\r\n");
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * This silliness (instead of ``bargv[0] = "dig";'')
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews * dances around the const string issue. If in
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * the future the 2nd argument to strncpy() is made
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * longer than three characters, don't forget to resize
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * bargv0 to accommodate it.
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews */
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews strncpy(bargv0, "dig", sizeof(bargv0));
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews bargv[0] = bargv0;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence reorder_args(bargc, (char **)bargv);
471e0563c7965c556c759775882cd3448dae78eaMark Andrews parse_args(ISC_TRUE, bargc, (char **)bargv);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (lookup_list.head == NULL) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (lookup == NULL)
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson fatal("Memory allocation failure.");
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->pending = ISC_FALSE;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->rctext[0] = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->namespace[0] = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->sendspace[0] = 0;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->sendmsg = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->name = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->oname = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->timer = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->xfr_q = NULL;
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews lookup->origin = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->querysig = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->use_my_server_list = ISC_FALSE;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->doing_xfr = ISC_FALSE;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews lookup->ixfr_serial = 0;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->defname = ISC_FALSE;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->trace = ISC_TF(trace || ns_search_only);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->trace_root = trace;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->ns_search_only = ns_search_only;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->identify = identify;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->recurse = recurse;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->aaonly = aaonly;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->retries = tries;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->udpsize = bufsize;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->nsfound = 0;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->comments = comments;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->tcp_mode = tcpmode;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->stats = stats;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->section_question = section_question;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->section_answer = section_answer;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->section_authority = section_authority;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->section_additional = section_additional;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson lookup->new_search = ISC_TRUE;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson ISC_LIST_INIT(lookup->q);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson ISC_LIST_INIT(lookup->my_server_list);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson strcpy(lookup->textname, ".");
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson strcpy(lookup->rttext, "NS");
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff lookup->rctext[0] = 0;
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley ISC_LIST_APPEND(lookup_list, lookup, link);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff }
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (!is_batchfile)
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff printgreeting (argc, argv);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews}
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffint
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffmain(int argc, char **argv) {
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff#ifdef TWIDDLE
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff FILE *fp;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff int i, p;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff#endif
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence ISC_LIST_INIT(lookup_list);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff ISC_LIST_INIT(server_list);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff ISC_LIST_INIT(search_list);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff debug ("dhmain()");
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff#ifdef TWIDDLE
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff fp = fopen("/dev/urandom", "r");
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff if (fp != NULL) {
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff fread (&i, sizeof(int), 1, fp);
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews srandom(i);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews }
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews else {
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews srandom ((int)&main);
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews }
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington p = getpid()%16+8;
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews for (i = 0 ; i<p; i++);
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews#endif
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews setup_libs();
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews parse_args(ISC_FALSE, argc, argv);
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews setup_system();
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews start_lookup();
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington isc_app_run();
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington free_lists(0);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington return (exitcode);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington}
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews