host.c revision 68f0d29d61a730222ec6c370ea1aff7ab0c36a4e
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2000 Internet Software Consortium.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Permission to use, copy, modify, and distribute this software for any
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * purpose with or without fee is hereby granted, provided that the above
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington/* $Id: host.c,v 1.43 2000/07/19 17:52:27 mws Exp $ */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern isc_boolean_t have_ipv6, show_details, debugging;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyextern unsigned int timeout;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic const char *opcodetext[] = {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED3",
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews "RESERVED7",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED8",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED9",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED10",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED11",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED12",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED13",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED14",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED15"
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic const char *rcodetext[] = {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED11",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED12",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED13",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley "RESERVED14",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "RESERVED15",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic const char *rtypetext[] = {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley"Usage: host [-aCdlrTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" [-R number] hostname [server]\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -a is equivalent to -v -t *\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -c specifies query class for non-IN data\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -C compares SOA records on authorative nameservers\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -d is equivalent to -v\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -l lists all hosts in a domain, using AXFR\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -N changes the number of dots allowed before root lookup is done\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -r disables recursive processing\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -R specifies number of retries for UDP packets\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -t specifies the query type\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -T enables TCP/IP mode\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -v enables verbose output\n"
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff" -w specifies to wait forever for a reply\n"
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley" -W specifies how long to wait for a reply\n", stderr);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleyreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley diff = isc_time_microdiff(&now, &query->time_sent);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleytrying(int frmsize, char *frm, dig_lookup_t *lookup) {
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halleysay_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson check_result(result, "dns_rdata_totext");
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson printf (" on server %s", query->servname);
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyprintsection(dns_message_t *msg, dns_section_t sectionid,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence const char *section_name, isc_boolean_t headers,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley char t[4096];
1ccbfca64ae86ace521053773001cb995352f96fBob Halley const char *rtt;
739ccd81b011ec3f7b8029000704b1a925df7e65Bob Halleyprintrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence char t[4096];
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halleyprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Exitcode 9 means we timed out, but if we're printing a message,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * we much have recovered. Go ahead and reset it to code 0, and
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * call this a success.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = dns_name_totext(query->lookup->name, ISC_FALSE,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley "AUTHORITY: %u, ADDITIONAL: %u\n",
6bb7b678f50a61dccad0bb3db4c26f73b59d8c16Bob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
1ccbfca64ae86ace521053773001cb995352f96fBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = printsection(msg, DNS_SECTION_ADDITIONAL,
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halleyparse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D"))
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * The timer routines are coded such that
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * timeout==MAXINT doesn't enable the timer
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff strncpy(hostname, argv[isc_commandline_index], MXNAME);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff srv = make_server(argv[isc_commandline_index+1]);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff * XXXMWS Add IPv6 translation here, probably using inet_pton
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff * to extract the formatted text.
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (strspn(hostname, "0123456789.") == strlen(hostname)) {
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington if (n == 0) {
adrs[i]);
setup_libs();
setup_system();
isc_app_run();
cancel_all();
destroy_libs();