host.c revision 0819ae2ca51571d205df061b52d8468889f3a0df
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000 Internet Software Consortium.
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington *
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User * SOFTWARE.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* $Id: host.c,v 1.36 2000/07/06 01:02:42 mws Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User#include <config.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <stdlib.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <limits.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int h_errno;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <isc/app.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <isc/commandline.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <isc/string.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <isc/util.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <isc/task.h>
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/message.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/name.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/rdata.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/rdataset.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dig/dig.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox Userextern ISC_LIST(dig_lookup_t) lookup_list;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern ISC_LIST(dig_server_t) server_list;
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox Userextern ISC_LIST(dig_searchlist_t) search_list;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern isc_boolean_t have_ipv6, show_details, debugging;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern in_port_t port;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern unsigned int timeout;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern isc_mem_t *mctx;
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox Userextern dns_messageid_t id;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern dns_name_t rootorg;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern char *rootspace[BUFSIZE];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern isc_buffer_t rootbuf;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int sendcount;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int ndots;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int tries;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int lookup_counter;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int exitcode;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern isc_taskmgr_t *taskmgr;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern char *progname;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinisc_boolean_t
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User short_form = ISC_TRUE,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein filter = ISC_FALSE,
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User showallsoa = ISC_FALSE,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein tcpmode = ISC_FALSE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox Userstatic const char *opcodetext[] = {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "QUERY",
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User "IQUERY",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "STATUS",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED3",
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User "NOTIFY",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "UPDATE",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED6",
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User "RESERVED7",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED8",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED9",
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User "RESERVED10",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED11",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED12",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED13",
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington "RESERVED14",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED15"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington};
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonstatic const char *rcodetext[] = {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "NOERROR",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "FORMERR",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "SERVFAIL",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "NXDOMAIN",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "NOTIMPL",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "REFUSED",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "YXDOMAIN",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "YXRRSET",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NXRRSET",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NOTAUTH",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NOTZONE",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED11",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED12",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED13",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED14",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "RESERVED15",
47ad4fad771b9c570bcf57793d6a931e0ca9856cAndreas Gustafsson "BADVERS"
47ad4fad771b9c570bcf57793d6a931e0ca9856cAndreas Gustafsson};
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonstatic const char *rtypetext[] = {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "zero", /* 0 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has address", /* 1 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "name server", /* 2 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "MD", /* 3 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "MF", /* 4 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "is an alias for", /* 5 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "SOA", /* 6 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "MB", /* 7 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "MG", /* 8 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "MR", /* 9 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "NULL", /* 10 */
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews "has well known services", /* 11 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "domain name pointer", /* 12 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "host information", /* 13 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "MINFO", /* 14 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "mail is handled by", /* 15 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "text", /* 16 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "RP", /* 17 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "AFSDB", /* 18 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "x25 address", /* 19 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "isdn address", /* 20 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "RT", /* 21 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "NSAP", /* 22 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "NSAP_PTR", /* 23 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "has signature", /* 24 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "has key", /* 25 */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "PX", /* 26 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "GPOS", /* 27 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has AAAA address", /* 28 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "LOC", /* 29 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has next record", /* 30 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "EID", /* 31 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "NIMLOC", /* 32 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "SRV", /* 33 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "ATMA", /* 34 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "NAPTR", /* 35 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "KX", /* 36 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "CERT", /* 37 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has v6 address", /* 38 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "DNAME", /* 39 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has optional information", /* 41 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 42 record", /* 42 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 43 record", /* 43 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 44 record", /* 44 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 45 record", /* 45 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 46 record", /* 46 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 47 record", /* 47 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 48 record", /* 48 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 49 record", /* 49 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 50 record", /* 50 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 51 record", /* 51 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 52 record", /* 52 */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington "has 53 record", /* 53 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 54 record", /* 54 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 55 record", /* 55 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 56 record", /* 56 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 57 record", /* 57 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 58 record", /* 58 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 59 record", /* 59 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 60 record", /* 60 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 61 record", /* 61 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 62 record", /* 62 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 63 record", /* 63 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 64 record", /* 64 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 65 record", /* 65 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 66 record", /* 66 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 67 record", /* 67 */
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington "has 68 record", /* 68 */
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User "has 69 record", /* 69 */
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington "has 70 record", /* 70 */
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington "has 71 record", /* 71 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 72 record", /* 72 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 73 record", /* 73 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 74 record", /* 74 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 75 record", /* 75 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 76 record", /* 76 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "has 77 record", /* 77 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 78 record", /* 78 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 79 record", /* 79 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 80 record", /* 80 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 81 record", /* 81 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 82 record", /* 82 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 83 record", /* 83 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 84 record", /* 84 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 85 record", /* 85 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 86 record", /* 86 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 87 record", /* 87 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 88 record", /* 88 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 89 record", /* 89 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 90 record", /* 90 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 91 record", /* 91 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson "has 92 record", /* 92 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 93 record", /* 93 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 94 record", /* 94 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 95 record", /* 95 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 96 record", /* 96 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 97 record", /* 97 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 98 record", /* 98 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "has 99 record", /* 99 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "UNIFO", /* 100 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "UID", /* 101 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "GID", /* 102 */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington "UNSPEC"}; /* 103 */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonstatic void
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonshow_usage(void) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington fputs(
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington"Usage: host [-aCdlrTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" [-R number] hostname [server]\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -a is equivalent to -v -t *\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -c specifies query class for non-IN data\n"
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson" -C compares SOA records on authorative nameservers\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -d is equivalent to -v\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -l lists all hosts in a domain, using AXFR\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -N changes the number of dots allowed before root lookup is done\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -r disables recursive processing\n"
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt" -R specifies number of retries for UDP packets\n"
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt" -t specifies the query type\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -T enables TCP/IP mode\n"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington" -v enables verbose output\n"
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson" -w specifies to wait forever for a reply\n"
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson" -W specifies how long to wait for a reply\n", stderr);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington exit(exitcode);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonvoid
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtondighost_shutdown(void) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington free_lists();
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington isc_app_shutdown();
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonvoid
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington isc_time_t now;
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt isc_result_t result;
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt int diff;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if ((!short_form) || (show_details)) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = isc_time_now(&now);
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews check_result(result, "isc_time_now");
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("Received %u bytes from %.*s in %d ms\n",
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington bytes, frmsize, frm, diff/1000);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonvoid
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews UNUSED(lookup);
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (!short_form)
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews printf ("Trying \"%.*s\"\n", frmsize, frm);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonstatic void
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinsay_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington dig_query_t *query)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington{
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington isc_buffer_t *b = NULL, *b2 = NULL;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews isc_region_t r, r2;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews isc_result_t result;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews result = isc_buffer_allocate(mctx, &b, BUFSIZE);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews check_result(result, "isc_buffer_allocate");
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews check_result(result, "isc_buffer_allocate");
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = dns_name_totext(name, ISC_FALSE, b);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews check_result(result, "dns_name_totext");
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews isc_buffer_usedregion(b, &r);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews result = dns_rdata_totext(rdata, NULL, b2);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews check_result(result, "dns_rdata_totext");
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews isc_buffer_usedregion(b2, &r2);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews msg, (int)r2.length, (char *)r2.base);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (query->lookup->identify) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf (" on server %s", query->servname);
fd091cb3cd17e4e3a7b8c49454db0863a31a7e7dBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf ("\n");
isc_buffer_free(&b);
isc_buffer_free(&b2);
}
static isc_result_t
printsection(dns_message_t *msg, dns_section_t sectionid,
const char *section_name, isc_boolean_t headers,
dig_query_t *query)
{
dns_name_t *name, *print_name;
dns_rdataset_t *rdataset;
dns_rdata_t rdata;
isc_buffer_t target;
isc_result_t result, loopresult;
isc_region_t r;
dns_name_t empty_name;
char t[4096];
isc_boolean_t first;
isc_boolean_t no_rdata;
const char *rtt;
if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE;
else
no_rdata = ISC_FALSE;
if (headers)
printf(";; %s SECTION:\n", section_name);
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, sectionid);
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
name = NULL;
dns_message_currentname(msg, sectionid, &name);
isc_buffer_init(&target, t, sizeof(t));
first = ISC_TRUE;
print_name = name;
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) {
if (!short_form) {
result = dns_rdataset_totext(rdataset,
print_name,
ISC_FALSE,
no_rdata,
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
first = ISC_FALSE;
}
#else
UNUSED(first); /* Shut up compiler. */
#endif
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
if (rdata.type <= 103)
rtt=rtypetext[rdata.type];
else if (rdata.type == 249)
rtt = "key";
else if (rdata.type == 250)
rtt = "signature";
else
rtt = "unknown";
say_message(print_name, rtt,
&rdata, query);
loopresult =
dns_rdataset_next(rdataset);
}
}
}
if (!short_form) {
isc_buffer_usedregion(&target, &r);
if (no_rdata)
printf(";%.*s", (int)r.length,
(char *)r.base);
else
printf("%.*s", (int)r.length, (char *)r.base);
}
result = dns_message_nextname(msg, sectionid);
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
const char *set_name, isc_boolean_t headers)
{
isc_buffer_t target;
isc_result_t result;
isc_region_t r;
char t[4096];
UNUSED(msg);
if (headers)
printf(";; %s SECTION:\n", set_name);
isc_buffer_init(&target, t, sizeof(t));
result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
printf("%.*s", (int)r.length, (char *)r.base);
return (ISC_R_SUCCESS);
}
isc_result_t
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
isc_boolean_t did_flag = ISC_FALSE;
dns_rdataset_t *opt, *tsig = NULL;
dns_name_t *tsigname;
isc_result_t result = ISC_R_SUCCESS;
isc_buffer_t *b = NULL;
isc_region_t r;
UNUSED(headers);
/*
* Exitcode 9 means we timed out, but if we're printing a message,
* we much have recovered. Go ahead and reset it to code 0, and
* call this a success.
*/
if (exitcode == 9)
exitcode = 0;
if (msg->rcode != 0) {
result = isc_buffer_allocate(mctx, &b, MXNAME);
check_result(result, "isc_buffer_allocate");
result = dns_name_totext(query->lookup->name, ISC_FALSE,
b);
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
printf("Host %.*s not found: %d(%s)\n",
(int)r.length, (char *)r.base,
msg->rcode, rcodetext[msg->rcode]);
isc_buffer_free(&b);
return (ISC_R_SUCCESS);
}
if (!short_form) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
opcodetext[msg->opcode], rcodetext[msg->rcode],
msg->id);
printf(";; flags: ");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
printf("qr");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
printf("%saa", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
printf("%stc", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
printf("%srd", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
printf("%sra", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
printf("%sad", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
printf("%scd", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
printf("; QUERY: %u, ANSWER: %u, "
"AUTHORITY: %u, ADDITIONAL: %u\n",
msg->counts[DNS_SECTION_QUESTION],
msg->counts[DNS_SECTION_ANSWER],
msg->counts[DNS_SECTION_AUTHORITY],
msg->counts[DNS_SECTION_ADDITIONAL]);
opt = dns_message_getopt(msg);
if (opt != NULL)
printf(";; EDNS: version: %u, udp=%u\n",
(unsigned int)((opt->ttl & 0x00ff0000) >> 16),
(unsigned int)opt->rdclass);
tsigname = NULL;
tsig = dns_message_gettsig(msg, &tsigname);
if (tsig != NULL)
printf(";; PSEUDOSECTIONS: TSIG\n");
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
if (!short_form)
printf("\n");
result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
ISC_TF(!short_form), query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_ADDITIONAL,
"ADDITIONAL", ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if ((tsig != NULL) && !short_form) {
printf("\n");
result = printrdata(msg, tsig, tsigname,
"PSEUDOSECTION TSIG", ISC_TRUE);
if (result != ISC_R_SUCCESS)
return (result);
}
if (!short_form)
printf("\n");
return (result);
}
static void
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
isc_boolean_t recursion = ISC_TRUE;
char hostname[MXNAME];
char querytype[32] = "";
char queryclass[32] = "";
dig_server_t *srv;
dig_lookup_t *lookup;
int i, c, n, adrs[4];
char store[MXNAME];
UNUSED(is_batchfile);
while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
!= EOF) {
switch (c) {
case 'l':
tcpmode = ISC_TRUE;
filter = ISC_TRUE;
strcpy(querytype, "axfr");
break;
case 'v':
case 'd':
short_form = ISC_FALSE;
break;
case 'r':
recursion = ISC_FALSE;
break;
case 't':
strncpy (querytype, isc_commandline_argument, 32);
break;
case 'c':
strncpy (queryclass, isc_commandline_argument, 32);
break;
case 'a':
strcpy (querytype, "any");
short_form = ISC_FALSE;
break;
case 'w':
/*
* The timer routines are coded such that
* timeout==MAXINT doesn't enable the timer
*/
timeout = INT_MAX;
break;
case 'W':
timeout = atoi(isc_commandline_argument);
if (timeout < 1)
timeout = 1;
break;
case 'R':
tries = atoi(isc_commandline_argument);
if (tries < 1)
tries = 1;
break;
case 'T':
tcpmode = ISC_TRUE;
break;
case 'C':
debug("showing all SOAs");
if (querytype[0] == 0)
strcpy(querytype, "soa");
if (queryclass[0] == 0)
strcpy(queryclass, "in");
showallsoa = ISC_TRUE;
show_details = ISC_TRUE;
break;
case 'N':
debug("setting NDOTS to %s",
isc_commandline_argument);
ndots = atoi(isc_commandline_argument);
break;
case 'D':
debugging = ISC_TRUE;
break;
}
}
if (isc_commandline_index >= argc) {
show_usage();
}
strncpy(hostname, argv[isc_commandline_index], MXNAME);
if (argc > isc_commandline_index + 1) {
srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
if (srv == NULL)
fatal("Memory allocation failure.");
strncpy(srv->servername,
argv[isc_commandline_index+1], MXNAME-1);
debug("server is %s", srv->servername);
ISC_LIST_APPEND(server_list, srv, link);
}
lookup = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
if (lookup == NULL)
fatal("Memory allocation failure.");
lookup->pending = ISC_FALSE;
/*
* XXXMWS Add IPv6 translation here, probably using inet_pton
* to extract the formatted text.
*/
if (strspn(hostname, "0123456789.") == strlen(hostname)) {
lookup->textname[0] = 0;
n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
show_usage();
exit(exitcode);
}
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);
if (querytype[0] == 0)
strcpy(querytype, "ptr");
} else {
strncpy(lookup->textname, hostname, MXNAME);
}
if (querytype[0] == 0)
strcpy(querytype, "a");
if (queryclass[0] == 0)
strcpy(queryclass, "in");
strncpy(lookup->rttext, querytype, 32);
strncpy(lookup->rctext, queryclass, 32);
lookup->namespace[0] = 0;
lookup->sendspace[0] = 0;
lookup->sendmsg = NULL;
lookup->name = NULL;
lookup->oname = NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->querysig = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->ixfr_serial = 0;
lookup->defname = ISC_FALSE;
lookup->identify = ISC_FALSE;
lookup->recurse = recursion;
lookup->ns_search_only = showallsoa;
lookup->use_my_server_list = ISC_FALSE;
lookup->retries = tries;
lookup->udpsize = 0;
lookup->nsfound = 0;
lookup->trace = ISC_FALSE;
lookup->trace_root = showallsoa;
lookup->tcp_mode = tcpmode;
lookup->new_search = ISC_TRUE;
lookup->aaonly = ISC_FALSE;
lookup->adflag = ISC_FALSE;
lookup->cdflag = ISC_FALSE;
ISC_LIST_INIT(lookup->q);
ISC_LIST_APPEND(lookup_list, lookup, link);
lookup->origin = NULL;
ISC_LIST_INIT(lookup->my_server_list);
}
int
main(int argc, char **argv) {
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug("main()");
progname = argv[0];
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
start_lookup();
isc_app_run();
/*
* XXXMWS This code should really NOT be bypassed. However,
* until the proper code can be added to handle SIGTERM/INT
* correctly, just exit out "hard" and deal as best we can.
*/
#if 0
if (taskmgr != NULL) {
debug("freeing taskmgr");
isc_taskmgr_destroy(&taskmgr);
}
if (isc_mem_debugging)
isc_mem_stats(mctx, stderr);
isc_app_finish();
if (mctx != NULL)
isc_mem_destroy(&mctx);
#endif
return (0);
}