host.c revision 7949dbdae1db33e6263d754e5940daa1dfba59f9
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
69fe9aaafdd6a141610e86a777d325db75422070Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews#include <config.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <errno.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <stdio.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <stdlib.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <string.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <unistd.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int h_errno;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/types.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/app.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/assertions.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/error.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/mem.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/net.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/netdb.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/result.h>
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington#include <isc/sockaddr.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/socket.h>
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#include <isc/task.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/timer.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/time.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/buffer.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/list.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/util.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/commandline.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/types.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/message.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/name.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/fixedname.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdata.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatalist.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/rdataset.h>
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington#include <dns/rdataclass.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatatype.h>
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington#include <dns/result.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington#include <dig/dig.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonextern ISC_LIST(dig_lookup_t) lookup_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_server_t) server_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_searchlist_t) search_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_boolean_t tcp_mode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington recurse,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington have_ipv6;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern in_port_t port;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern unsigned int timeout;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_mem_t *mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_taskmgr_t *taskmgr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_task_t *task;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_timermgr_t *timermgr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_socketmgr_t *socketmgr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern dns_messageid_t id;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern dns_name_t rootorg;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern char *rootspace[BUFSIZE];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_buffer_t rootbuf;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int sendcount;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonextern int ndots;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonextern int tries;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellingtonisc_boolean_t short_form=ISC_TRUE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington filter=ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington showallsoa=ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic char *opcodetext[] = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "QUERY",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "IQUERY",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "STATUS",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED3",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "NOTIFY",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "UPDATE",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED6",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED7",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED8",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED9",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED10",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED11",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED12",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED15"
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence};
571688b02f955f6304649866e768b1f81739cbedBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic char *rcodetext[] = {
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "NOERROR",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "FORMERR",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "SERVFAIL",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "NXDOMAIN",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "NOTIMPL",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "REFUSED",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "YXDOMAIN",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "YXRRSET",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NXRRSET",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NOTAUTH",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NOTZONE",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED11",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED12",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED15",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "BADVERS"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonstatic char *rtypetext[] = {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "zero", /* 0 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "has address", /* 1 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "name server", /* 2 */
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington "MD", /* 3 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "MF", /* 4 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "is an alias for", /* 5 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "SOA", /* 6 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "MB", /* 7 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "MG", /* 8 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "MR", /* 9 */
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington "NULL", /* 10 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "has well known services", /* 11 */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "domain name pointer", /* 12 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "host information", /* 13 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "MINFO", /* 14 */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington "mail is handled by", /* 15 */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington "text", /* 16 */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington "RP", /* 17 */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington "AFSDB", /* 18 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "x25 address", /* 19 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isdn address", /* 20 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RT" /* 21 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NSAP", /* 22 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NSAP_PTR", /* 23 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has signature", /* 24 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has key", /* 25 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "PX", /* 26 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "GPOS", /* 27 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "has AAAA address", /* 28 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "LOC", /* 29 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has next record", /* 30 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has 31 record", /* 31 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has 32 record", /* 32 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "SRV", /* 33 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "has 34 record", /* 34 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NAPTR", /* 35 */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "KX", /* 36 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "CERT", /* 37 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "has v6 address", /* 38 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "DNAME", /* 39 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "has 40 record", /* 40 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "has optional information"}; /* 41 */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtoncheck_next_lookup (dig_lookup_t *lookup) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dig_lookup_t *next;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dig_query_t *query;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_boolean_t still_working=ISC_FALSE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("In check_next_lookup");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (query = ISC_LIST_HEAD(lookup->q);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington query != NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington query = ISC_LIST_NEXT(query, link)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->working) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("Still have a worker.");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington still_working=ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (still_working)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington next = ISC_LIST_NEXT(lookup, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug ("Have %d retries left for %s\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington lookup->retries, lookup->textname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((next == NULL)&&((lookup->retries <= 1)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ||tcp_mode)) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington debug("Shutting Down.",stderr);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_app_shutdown();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (tcp_mode) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington setup_lookup(next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington do_lookup_tcp(next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup->retries > 1) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->retries --;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington send_udp(lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington setup_lookup(next);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington do_lookup_udp(next);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#ifdef NEVER
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington next = ISC_LIST_NEXT (lookup, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (next == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug ("Shutting Down.");
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington isc_app_shutdown();
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington return;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington setup_lookup(next);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if (tcp_mode)
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington do_lookup_tcp(next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington do_lookup_udp(next);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#endif
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic void
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonshow_usage() {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington fputs (
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington"Usage: host [-aCdlrTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" [-R number] hostname [server]\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -a is equivalent to -v -t *\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -c specifies query class for non-IN data\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -C compares SOA records on authorative nameservers\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -d is equivalent to -v\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -l lists all hosts in a domain, using AXFR\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -N changes the number of dots allowed before root lookup is done\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -r disables recursive processing\n"
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington" -R specifies number of retries for UDP packets\n"
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington" -t specifies the query type\n"
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington" -T enables TCP/IP mode\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -v enables verbose output\n"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington" -w specifies to wait forever for a reply\n"
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington" -W specifies how long to wait for a reply\n",stderr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington exit (0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonvoid
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington UNUSED(query);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (!short_form)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington printf("Received %u bytes from %.*s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bytes, frmsize, frm);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonvoid
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington UNUSED (lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (!short_form)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington printf ("Trying \"%.*s\"\n", frmsize, frm);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonstatic void
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonsay_message(dns_name_t *name, char *msg, dns_rdata_t *rdata,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dig_query_t *query)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington{
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_buffer_t *b=NULL, *b2=NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_region_t r, r2;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_buffer_allocate(mctx, &b, BUFSIZE);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington check_result (result, "isc_buffer_allocate");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington check_result (result, "isc_buffer_allocate");
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington result = dns_name_totext(name, ISC_FALSE, b);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington check_result(result, "dns_name_totext");
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington isc_buffer_usedregion(b, &r);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington result = dns_rdata_totext(rdata, NULL, b2);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington check_result(result, "dns_rdata_totext");
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington isc_buffer_usedregion(b2, &r2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson msg, (int)r2.length, (char *)r2.base);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (query->lookup->identify) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf (" on server %s",query->servname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf ("\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_free(&b);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_free(&b2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t headers, dig_query_t *query)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *name, *print_name;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t target;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result, loopresult;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t r;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t empty_name;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char t[4096];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t first;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t no_rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *rtt;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (sectionid == DNS_SECTION_QUESTION)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington no_rdata = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington no_rdata = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (headers)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; %s SECTION:\n", section_name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&empty_name, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(msg, sectionid);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOMORE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_SUCCESS);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson for (;;) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson name = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_message_currentname(msg, sectionid, &name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_init(&target, t, sizeof(t));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson first = ISC_TRUE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson print_name = name;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset != NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset = ISC_LIST_NEXT(rdataset, link)) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (!short_form) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdataset_totext(rdataset,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson print_name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_FALSE,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson no_rdata,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson &target);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson#ifdef USEINITALWS
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (first) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson print_name = &empty_name;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson first = ISC_FALSE;
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson#endif
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson } else {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_first(rdataset);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson while (loopresult == ISC_R_SUCCESS) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_current(rdataset, &rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (rdata.type <= 41)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rtt=rtypetext[rdata.type];
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else if (rdata.type == 103)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rtt="unspecified data";
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else if (rdata.type == 249)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rtt="key";
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else if (rdata.type == 250)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rtt="signature";
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rtt="unknown";
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson say_message(print_name,
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews rtypetext[rdata.type],
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson &rdata, query);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews loopresult = dns_rdataset_next(
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington }
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (!short_form) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington isc_buffer_usedregion(&target, &r);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (no_rdata)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington printf(";%.*s", (int)r.length,
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington (char *)r.base);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)r.length, (char *)r.base);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_nextname(msg, sectionid);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOMORE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson break;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonstatic isc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *set_name, isc_boolean_t headers)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson{
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t target;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_region_t r;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson char t[4096];
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson UNUSED(msg);
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington if (headers)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf(";; %s SECTION:\n", set_name);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_init(&target, t, sizeof(t));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &target);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_usedregion(&target, &r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)r.length, (char *)r.base);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_SUCCESS);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_boolean_t did_flag = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *opt, *tsig = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *tsigname;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result = ISC_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED (headers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (msg->rcode != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf ("Host not found: %d(%s)\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->rcode, rcodetext[msg->rcode]);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (!short_form) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington opcodetext[msg->opcode], rcodetext[msg->rcode],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->id);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf(";; flags: ");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("qr");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%saa", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%stc", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%srd", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%sra", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%sad", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%scd", did_flag ? " " : "");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington did_flag = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("; QUERY: %u, ANSWER: %u, "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "AUTHORITY: %u, ADDITIONAL: %u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->counts[DNS_SECTION_QUESTION],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->counts[DNS_SECTION_ANSWER],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->counts[DNS_SECTION_AUTHORITY],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg->counts[DNS_SECTION_ADDITIONAL]);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington opt = dns_message_getopt(msg);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (opt != NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf(";; EDNS: version: %u, udp=%u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington (unsigned int)((opt->ttl & 0x00ff0000) >> 16),
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington (unsigned int)opt->rdclass);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington tsigname = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington tsig = dns_message_gettsig(msg, &tsigname);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (tsig != NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf(";; PSEUDOSECTIONS: TSIG\n");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson !short_form ) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_TRUE, query);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (!short_form)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson !short_form, query);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson !short_form ) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ISC_TRUE, query);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson !short_form ) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("\n");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = printsection(msg, DNS_SECTION_ADDITIONAL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "ADDITIONAL", ISC_TRUE, query);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((tsig != NULL) && !short_form) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = printrdata(msg, tsig, tsigname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "PSEUDOSECTION TSIG", ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson if (!short_form)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t have_host=ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington recursion=ISC_TRUE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington xfr_mode=ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nsfind=ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char hostname[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char querytype[32]="";
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char queryclass[32]="";
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dig_server_t *srv;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dig_lookup_t *lookup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int c;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(is_batchfile);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while ((c = isc_commandline_parse(argc, argv,"lvwrdt:c:aTCN:R:W:"))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington != EOF) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (c) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'l':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tcp_mode = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington xfr_mode = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington filter = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (querytype, "axfr");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington case 'v':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington short_form = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington case 'r':
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington recursion = ISC_FALSE;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington break;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington case 't':
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington strncpy (querytype, isc_commandline_argument, 32);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'c':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (queryclass, isc_commandline_argument, 32);
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'a':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (querytype, "any");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington short_form = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'w':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXXMWS This should be a system-indep.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington thing! */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = 32767;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'W':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = atoi(isc_commandline_argument);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (timeout < 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'R':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tries = atoi(isc_commandline_argument);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (tries < 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tries = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'T':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tcp_mode = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'C':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug ("Showing all SOA's");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (querytype[0] == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (querytype, "soa");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (queryclass[0] == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (queryclass, "in");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nsfind = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington showallsoa = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'N':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug ("Setting NDOTS to %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_commandline_argument);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ndots = atoi(isc_commandline_argument);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (isc_commandline_index >= argc) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington show_usage();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (hostname, argv[isc_commandline_index], MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (argc > isc_commandline_index+1) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington srv=isc_mem_allocate(mctx, sizeof(struct dig_server));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (srv == NULL)
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews fatal ("Memory allocation failure.");
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews strncpy(srv->servername,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington argv[isc_commandline_index+1],MXNAME-1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("Server is %s",srv->servername);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(server_list, srv, link);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (querytype[0] == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (querytype, "a");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (queryclass[0] == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy (queryclass, "in");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup = isc_mem_allocate (mctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof(struct dig_lookup));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal ("Memory allocation failure.");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->pending = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (lookup->textname, hostname, MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (lookup->rttext, querytype, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (lookup->rctext,queryclass, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->namespace[0]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendspace[0]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->sendmsg=NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->name=NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->oname=NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->timer = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->xfr_q = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->doing_xfr = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->identify = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->ns_search_only = showallsoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->use_my_server_list = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->retries = tries;
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews ISC_LIST_INIT(lookup->q);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup_list, lookup, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->origin = NULL;
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews ISC_LIST_INIT(lookup->my_server_list);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington have_host = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington