host.c revision 68f0d29d61a730222ec6c370ea1aff7ab0c36a4e
1ccbfca64ae86ace521053773001cb995352f96fBob Halley/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Permission to use, copy, modify, and distribute this software for any
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * purpose with or without fee is hereby granted, provided that the above
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * 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.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington/* $Id: host.c,v 1.43 2000/07/19 17:52:27 mws Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <config.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <stdlib.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <limits.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyextern int h_errno;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff#include <isc/app.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/commandline.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/string.h>
1ccbfca64ae86ace521053773001cb995352f96fBob Halley#include <isc/util.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/task.h>
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff#include <dns/message.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/name.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/rdata.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/rdataclass.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/rdataset.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/rdatatype.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dig/dig.h>
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffextern ISC_LIST(dig_lookup_t) lookup_list;
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrewsextern ISC_LIST(dig_server_t) server_list;
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halleyextern ISC_LIST(dig_searchlist_t) search_list;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern isc_boolean_t have_ipv6, show_details, debugging;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern in_port_t port;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern unsigned int timeout;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern isc_mem_t *mctx;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern dns_messageid_t id;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern dns_name_t rootorg;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern char *rootspace[BUFSIZE];
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern isc_buffer_t rootbuf;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern int sendcount;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern int ndots;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern int tries;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern int lookup_counter;
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyextern int exitcode;
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyextern isc_taskmgr_t *taskmgr;
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halleyextern char *progname;
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyextern isc_task_t *global_task;
68e4926b2262571e004b4be00b905ec776c01d9cMichael Graff
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_boolean_t
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halleyshort_form = ISC_TRUE;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic const char *opcodetext[] = {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "QUERY",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "IQUERY",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "STATUS",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED3",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "NOTIFY",
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff "UPDATE",
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence "RESERVED6",
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "RESERVED7",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED8",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED9",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED10",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED11",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED12",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED13",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED14",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED15"
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley};
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic const char *rcodetext[] = {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "NOERROR",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "FORMERR",
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "SERVFAIL",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "NXDOMAIN",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NOTIMPL",
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff "REFUSED",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "YXDOMAIN",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "YXRRSET",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NXRRSET",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NOTAUTH",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NOTZONE",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED11",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED12",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED13",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED14",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED15",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "BADVERS"
1ccbfca64ae86ace521053773001cb995352f96fBob Halley};
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic const char *rtypetext[] = {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "zero", /* 0 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has address", /* 1 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "name server", /* 2 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "MD", /* 3 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "MF", /* 4 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "is an alias for", /* 5 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "SOA", /* 6 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "MB", /* 7 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "MG", /* 8 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "MR", /* 9 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NULL", /* 10 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has well known services", /* 11 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "domain name pointer", /* 12 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "host information", /* 13 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "MINFO", /* 14 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "mail is handled by", /* 15 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "text", /* 16 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RP", /* 17 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "AFSDB", /* 18 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "x25 address", /* 19 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "isdn address", /* 20 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "RT", /* 21 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "NSAP", /* 22 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "NSAP_PTR", /* 23 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "has signature", /* 24 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "has key", /* 25 */
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister "PX", /* 26 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "GPOS", /* 27 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has AAAA address", /* 28 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "LOC", /* 29 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has next record", /* 30 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "EID", /* 31 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "NIMLOC", /* 32 */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "SRV", /* 33 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "ATMA", /* 34 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "NAPTR", /* 35 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "KX", /* 36 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "CERT", /* 37 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has v6 address", /* 38 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "DNAME", /* 39 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has optional information", /* 41 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 42 record", /* 42 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 43 record", /* 43 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 44 record", /* 44 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 45 record", /* 45 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 46 record", /* 46 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 47 record", /* 47 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 48 record", /* 48 */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "has 49 record", /* 49 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 50 record", /* 50 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 51 record", /* 51 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 52 record", /* 52 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 53 record", /* 53 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 54 record", /* 54 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 55 record", /* 55 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 56 record", /* 56 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 57 record", /* 57 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 58 record", /* 58 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 59 record", /* 59 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 60 record", /* 60 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 61 record", /* 61 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 62 record", /* 62 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 63 record", /* 63 */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "has 64 record", /* 64 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 65 record", /* 65 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 66 record", /* 66 */
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "has 67 record", /* 67 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 68 record", /* 68 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 69 record", /* 69 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 70 record", /* 70 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 71 record", /* 71 */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "has 72 record", /* 72 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 73 record", /* 73 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 74 record", /* 74 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 75 record", /* 75 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 76 record", /* 76 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 77 record", /* 77 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 78 record", /* 78 */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "has 79 record", /* 79 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 80 record", /* 80 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 81 record", /* 81 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 82 record", /* 82 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 83 record", /* 83 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 84 record", /* 84 */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley "has 85 record", /* 85 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 86 record", /* 86 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 87 record", /* 87 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 88 record", /* 88 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 89 record", /* 89 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 90 record", /* 90 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 91 record", /* 91 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 92 record", /* 92 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 93 record", /* 93 */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "has 94 record", /* 94 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 95 record", /* 95 */
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley "has 96 record", /* 96 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "has 97 record", /* 97 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "has 98 record", /* 98 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "has 99 record", /* 99 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "UNIFO", /* 100 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "UID", /* 101 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "GID", /* 102 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley "UNSPEC"}; /* 103 */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley
48481c9b6e19501457bcbc2995555412f352b99fBob Halley
48481c9b6e19501457bcbc2995555412f352b99fBob Halleystatic void
48481c9b6e19501457bcbc2995555412f352b99fBob Halleyshow_usage(void) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff fputs(
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley"Usage: host [-aCdlrTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" [-R number] hostname [server]\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -a is equivalent to -v -t *\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -c specifies query class for non-IN data\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -C compares SOA records on authorative nameservers\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -d is equivalent to -v\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -l lists all hosts in a domain, using AXFR\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -N changes the number of dots allowed before root lookup is done\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -r disables recursive processing\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -R specifies number of retries for UDP packets\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -t specifies the query type\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -T enables TCP/IP mode\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -v enables verbose output\n"
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff" -w specifies to wait forever for a reply\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -W specifies how long to wait for a reply\n", stderr);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley exit(exitcode);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley}
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleyvoid
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleydighost_shutdown(void) {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley isc_app_shutdown();
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley}
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleyvoid
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleyreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_time_t now;
bad8294771671374e811afac79a20cc6927e3e2fBob Halley isc_result_t result;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff int diff;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley if ((!short_form) || (show_details)) {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley result = isc_time_now(&now);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley check_result(result, "isc_time_now");
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley diff = isc_time_microdiff(&now, &query->time_sent);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley printf("Received %u bytes from %.*s in %d ms\n",
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley bytes, frmsize, frm, diff/1000);
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley }
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley}
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleyvoid
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleytrying(int frmsize, char *frm, dig_lookup_t *lookup) {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley UNUSED(lookup);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley if (!short_form)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff printf ("Trying \"%.*s\"\n", frmsize, frm);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley}
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley
0380c44d0238a88e167526954d630d071739ed28Mark Andrewsstatic void
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halleysay_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley dig_query_t *query)
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley{
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley isc_buffer_t *b = NULL, *b2 = NULL;
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley isc_region_t r, r2;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley isc_result_t result;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley result = isc_buffer_allocate(mctx, &b, BUFSIZE);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley check_result(result, "isc_buffer_allocate");
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley check_result(result, "isc_buffer_allocate");
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley result = dns_name_totext(name, ISC_FALSE, b);
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley check_result(result, "dns_name_totext");
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_buffer_usedregion(b, &r);
bad8294771671374e811afac79a20cc6927e3e2fBob Halley result = dns_rdata_totext(rdata, NULL, b2);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson check_result(result, "dns_rdata_totext");
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_usedregion(b2, &r2);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson msg, (int)r2.length, (char *)r2.base);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (query->lookup->identify) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson printf (" on server %s", query->servname);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson printf ("\n");
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_free(&b);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley isc_buffer_free(&b2);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley}
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic isc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyprintsection(dns_message_t *msg, dns_section_t sectionid,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence const char *section_name, isc_boolean_t headers,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley dig_query_t *query)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley{
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley dns_name_t *name, *print_name;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_rdataset_t *rdataset;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_rdata_t rdata;
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley isc_buffer_t target;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley isc_result_t result, loopresult;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_region_t r;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_name_t empty_name;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley char t[4096];
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_boolean_t first;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_boolean_t no_rdata;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley const char *rtt;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (sectionid == DNS_SECTION_QUESTION)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley no_rdata = ISC_TRUE;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley else
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley no_rdata = ISC_FALSE;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley if (headers)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley printf(";; %s SECTION:\n", section_name);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_name_init(&empty_name, NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = dns_message_firstname(msg, sectionid);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley if (result == ISC_R_NOMORE)
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley return (ISC_R_SUCCESS);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley else if (result != ISC_R_SUCCESS)
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley return (result);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley for (;;) {
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley name = NULL;
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley dns_message_currentname(msg, sectionid, &name);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley isc_buffer_init(&target, t, sizeof(t));
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley first = ISC_TRUE;
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley print_name = name;
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley for (rdataset = ISC_LIST_HEAD(name->list);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley rdataset != NULL;
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley rdataset = ISC_LIST_NEXT(rdataset, link)) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (!short_form) {
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley result = dns_rdataset_totext(rdataset,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley print_name,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ISC_FALSE,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley no_rdata,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley &target);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (result != ISC_R_SUCCESS)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (result);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#ifdef USEINITALWS
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (first) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley print_name = &empty_name;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley first = ISC_FALSE;
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley }
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#else
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley UNUSED(first); /* Shut up compiler. */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#endif
1ccbfca64ae86ace521053773001cb995352f96fBob Halley } else {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley loopresult = dns_rdataset_first(rdataset);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley while (loopresult == ISC_R_SUCCESS) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_rdataset_current(rdataset, &rdata);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (rdata.type <= 103)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley rtt=rtypetext[rdata.type];
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley else if (rdata.type == 249)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley rtt = "key";
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff else if (rdata.type == 250)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley rtt = "signature";
1ccbfca64ae86ace521053773001cb995352f96fBob Halley else
1ccbfca64ae86ace521053773001cb995352f96fBob Halley rtt = "unknown";
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley say_message(print_name, rtt,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley &rdata, query);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley loopresult =
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley dns_rdataset_next(rdataset);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley }
1ccbfca64ae86ace521053773001cb995352f96fBob Halley }
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley }
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (!short_form) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_buffer_usedregion(&target, &r);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley if (no_rdata)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf(";%.*s", (int)r.length,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley (char *)r.base);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff else
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley printf("%.*s", (int)r.length, (char *)r.base);
63e6086ef99eca768a4cd69871038181251905bbBob Halley }
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley result = dns_message_nextname(msg, sectionid);
d2615909402705135d0560ad9d11f4302053c17cBob Halley if (result == ISC_R_NOMORE)
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley break;
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley else if (result != ISC_R_SUCCESS)
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley return (result);
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley }
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley return (ISC_R_SUCCESS);
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley}
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halleystatic isc_result_t
739ccd81b011ec3f7b8029000704b1a925df7e65Bob Halleyprintrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley const char *set_name, isc_boolean_t headers)
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence{
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence isc_buffer_t target;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley isc_result_t result;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley isc_region_t r;
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence char t[4096];
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley
63e6086ef99eca768a4cd69871038181251905bbBob Halley UNUSED(msg);
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley if (headers)
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley printf(";; %s SECTION:\n", set_name);
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_buffer_init(&target, t, sizeof(t));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley &target);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley if (result != ISC_R_SUCCESS)
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley return (result);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley isc_buffer_usedregion(&target, &r);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley printf("%.*s", (int)r.length, (char *)r.base);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley return (ISC_R_SUCCESS);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley}
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halleyisc_result_t
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halleyprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley isc_boolean_t did_flag = ISC_FALSE;
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley dns_rdataset_t *opt, *tsig = NULL;
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence dns_name_t *tsigname;
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley isc_result_t result = ISC_R_SUCCESS;
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley isc_buffer_t *b = NULL;
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley isc_region_t r;
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley UNUSED(headers);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /*
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Exitcode 9 means we timed out, but if we're printing a message,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * we much have recovered. Go ahead and reset it to code 0, and
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * call this a success.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (exitcode == 9)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley exitcode = 0;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (msg->rcode != 0) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = isc_buffer_allocate(mctx, &b, MXNAME);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley check_result(result, "isc_buffer_allocate");
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = dns_name_totext(query->lookup->name, ISC_FALSE,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley b);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley check_result(result, "dns_name_totext");
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_buffer_usedregion(b, &r);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf("Host %.*s not found: %d(%s)\n",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley (int)r.length, (char *)r.base,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley msg->rcode, rcodetext[msg->rcode]);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley isc_buffer_free(&b);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (ISC_R_SUCCESS);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley }
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (!short_form) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley opcodetext[msg->opcode], rcodetext[msg->rcode],
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley msg->id);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley printf(";; flags: ");
1ccbfca64ae86ace521053773001cb995352f96fBob Halley if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf("qr");
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff did_flag = ISC_TRUE;
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley }
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley printf("%saa", did_flag ? " " : "");
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley did_flag = ISC_TRUE;
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley }
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley printf("%stc", did_flag ? " " : "");
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley did_flag = ISC_TRUE;
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley }
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley printf("%srd", did_flag ? " " : "");
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley did_flag = ISC_TRUE;
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley }
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley printf("%sra", did_flag ? " " : "");
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley did_flag = ISC_TRUE;
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley }
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley printf("%sad", did_flag ? " " : "");
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley did_flag = ISC_TRUE;
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley }
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley printf("%scd", did_flag ? " " : "");
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley did_flag = ISC_TRUE;
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley }
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley printf("; QUERY: %u, ANSWER: %u, "
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley "AUTHORITY: %u, ADDITIONAL: %u\n",
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley msg->counts[DNS_SECTION_QUESTION],
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley msg->counts[DNS_SECTION_ANSWER],
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley msg->counts[DNS_SECTION_AUTHORITY],
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff msg->counts[DNS_SECTION_ADDITIONAL]);
6bb7b678f50a61dccad0bb3db4c26f73b59d8c16Bob Halley opt = dns_message_getopt(msg);
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley if (opt != NULL)
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley printf(";; EDNS: version: %u, udp=%u\n",
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley (unsigned int)((opt->ttl & 0x00ff0000) >> 16),
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley (unsigned int)opt->rdclass);
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley tsigname = NULL;
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley tsig = dns_message_gettsig(msg, &tsigname);
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley if (tsig != NULL)
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley printf(";; PSEUDOSECTIONS: TSIG\n");
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley }
6bb7b678f50a61dccad0bb3db4c26f73b59d8c16Bob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley !short_form) {
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley printf("\n");
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ISC_TRUE, query);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (result != ISC_R_SUCCESS)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (result);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff }
1ccbfca64ae86ace521053773001cb995352f96fBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley if (!short_form)
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley printf("\n");
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley ISC_TF(!short_form), query);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (result != ISC_R_SUCCESS)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (result);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley }
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
1ccbfca64ae86ace521053773001cb995352f96fBob Halley !short_form) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf("\n");
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ISC_TRUE, query);
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence if (result != ISC_R_SUCCESS)
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley return (result);
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley }
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley !short_form) {
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence printf("\n");
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = printsection(msg, DNS_SECTION_ADDITIONAL,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley "ADDITIONAL", ISC_TRUE, query);
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley if (result != ISC_R_SUCCESS)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley return (result);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley }
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if ((tsig != NULL) && !short_form) {
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley printf("\n");
63e6086ef99eca768a4cd69871038181251905bbBob Halley result = printrdata(msg, tsig, tsigname,
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley "PSEUDOSECTION TSIG", ISC_TRUE);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley if (result != ISC_R_SUCCESS)
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley return (result);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley }
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley if (!short_form)
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley printf("\n");
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley return (result);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley}
63e6086ef99eca768a4cd69871038181251905bbBob Halley
63e6086ef99eca768a4cd69871038181251905bbBob Halleystatic void
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halleyparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley char hostname[MXNAME];
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff dig_server_t *srv;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dig_lookup_t *lookup;
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley int i, c, n, adrs[4];
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley char store[MXNAME];
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_textregion_t tr;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley isc_result_t result;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley dns_rdatatype_t rdtype;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley dns_rdataclass_t rdclass;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley UNUSED(is_batchfile);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
5c6d49484bf5600e3c2bcb3165e168bd058d167bBob Halley lookup = make_empty_lookup();
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley != EOF) {
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence switch (c) {
302d9bebb54ad8c5a3e2108698215a0e98e06a32Bob Halley case 'l':
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley lookup->tcp_mode = ISC_TRUE;
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley lookup->rdtype = dns_rdatatype_axfr;
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence break;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley case 'v':
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley case 'd':
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley short_form = ISC_FALSE;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley break;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley case 'r':
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->recurse = ISC_FALSE;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley break;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley case 't':
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley tr.base = isc_commandline_argument;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley tr.length = strlen(isc_commandline_argument);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley result = dns_rdatatype_fromtext(&rdtype,
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley (isc_textregion_t *)&tr);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley if (result != ISC_R_SUCCESS)
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley fprintf (stderr,"Warning: invalid type: %s\n",
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley isc_commandline_argument);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley else
b687c057fbd8b88738300a5038538e589677fe18Bob Halley lookup->rdtype = rdtype;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley break;
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence case 'c':
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley tr.base = isc_commandline_argument;
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley tr.length = strlen(isc_commandline_argument);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley result = dns_rdataclass_fromtext(&rdclass,
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence (isc_textregion_t *)&tr);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley if (result != ISC_R_SUCCESS)
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley fprintf (stderr,"Warning: invalid class: %s\n",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_commandline_argument);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley else
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lookup->rdclass = rdclass;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley break;
6cac2e0f7a1ab207a64127bef11bb93404523c15Brian Wellington case 'a':
6cac2e0f7a1ab207a64127bef11bb93404523c15Brian Wellington lookup->rdtype = dns_rdatatype_any;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley short_form = ISC_FALSE;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley break;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley case 'w':
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * The timer routines are coded such that
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * timeout==MAXINT doesn't enable the timer
1ccbfca64ae86ace521053773001cb995352f96fBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley timeout = INT_MAX;
a3e2ec2dfec1a8171eaf584bb957b80c04de1e0bBob Halley break;
a3e2ec2dfec1a8171eaf584bb957b80c04de1e0bBob Halley case 'W':
1ccbfca64ae86ace521053773001cb995352f96fBob Halley timeout = atoi(isc_commandline_argument);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (timeout < 1)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence timeout = 1;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley break;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff case 'R':
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff tries = atoi(isc_commandline_argument);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (tries < 1)
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff tries = 1;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff break;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff case 'T':
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff lookup->tcp_mode = ISC_TRUE;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff break;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff case 'C':
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff debug("showing all SOAs");
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews lookup->rdtype = dns_rdatatype_soa;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence lookup->rdclass = dns_rdataclass_in;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff lookup->ns_search_only = ISC_TRUE;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff lookup->trace_root = ISC_TRUE;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff show_details = ISC_TRUE;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff break;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff case 'N':
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff debug("setting NDOTS to %s",
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_commandline_argument);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff ndots = atoi(isc_commandline_argument);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff break;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence case 'D':
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff debugging = ISC_TRUE;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff break;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff }
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff }
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (isc_commandline_index >= argc) {
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff show_usage();
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff }
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff strncpy(hostname, argv[isc_commandline_index], MXNAME);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (argc > isc_commandline_index + 1) {
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff srv = make_server(argv[isc_commandline_index+1]);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff debug("server is %s", srv->servername);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff ISC_LIST_APPEND(server_list, srv, link);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff }
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff lookup->pending = ISC_FALSE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /*
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff * XXXMWS Add IPv6 translation here, probably using inet_pton
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff * to extract the formatted text.
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff */
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (strspn(hostname, "0123456789.") == strlen(hostname)) {
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington lookup->textname[0] = 0;
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington &adrs[2], &adrs[3]);
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington if (n == 0) {
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington show_usage();
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington exit(exitcode);
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington }
for (i = n - 1; i >= 0; i--) {
snprintf(store, MXNAME/8, "%d.",
adrs[i]);
strncat(lookup->textname, store, MXNAME);
}
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
lookup->rdtype = dns_rdatatype_ptr;
} else {
strncpy(lookup->textname, hostname, MXNAME);
}
lookup->new_search = ISC_TRUE;
ISC_LIST_APPEND(lookup_list, lookup, link);
}
int
main(int argc, char **argv) {
isc_result_t result;
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug("main()");
progname = argv[0];
result = isc_app_start();
check_result(result, "isc_app_start");
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
check_result(result, "isc_app_onrun");
isc_app_run();
cancel_all();
destroy_libs();
isc_app_finish();
return (0);
}