host.c revision 7949dbdae1db33e6263d754e5940daa1dfba59f9
69fe9aaafdd6a141610e86a777d325db75422070Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
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 * 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
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_searchlist_t) search_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern unsigned int timeout;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic char *opcodetext[] = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "RESERVED10",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED11",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED12",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic char *rcodetext[] = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED11",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED12",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED15",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonstatic char *rtypetext[] = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((next == NULL)&&((lookup->retries <= 1)
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);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington printf ("Trying \"%.*s\"\n", frmsize, frm);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonsay_message(dns_name_t *name, char *msg, dns_rdata_t *rdata,
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 result = dns_rdata_totext(rdata, NULL, b2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char t[4096];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(msg, sectionid);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_message_currentname(msg, sectionid, &name);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset = ISC_LIST_NEXT(rdataset, link)) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)r.length, (char *)r.base);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_nextname(msg, sectionid);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)r.length, (char *)r.base);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington opcodetext[msg->opcode], rcodetext[msg->rcode],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "AUTHORITY: %u, ADDITIONAL: %u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington (unsigned int)((opt->ttl & 0x00ff0000) >> 16),
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington tsig = dns_message_gettsig(msg, &tsigname);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = printsection(msg, DNS_SECTION_ADDITIONAL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while ((c = isc_commandline_parse(argc, argv,"lvwrdt:c:aTCN:R:W:"))
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington strncpy (querytype, isc_commandline_argument, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (queryclass, isc_commandline_argument, 32);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXXMWS This should be a system-indep.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (hostname, argv[isc_commandline_index], MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington srv=isc_mem_allocate(mctx, sizeof(struct dig_server));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof(struct dig_lookup));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy (lookup->textname, hostname, MXNAME);