/*
* Copyright (C) 2000-2007, 2009-2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <stdlib.h>
#include <limits.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef WITH_IDN
#endif
#include <isc/commandline.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#include <dns/rdatastruct.h>
static const char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
static const char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
struct rtype {
unsigned int type;
const char *text;
};
{ 1, "has address" },
{ 2, "name server" },
{ 5, "is an alias for" },
{ 11, "has well known services" },
{ 12, "domain name pointer" },
{ 13, "host information" },
{ 15, "mail is handled by" },
{ 16, "descriptive text" },
{ 19, "x25 address" },
{ 20, "ISDN address" },
{ 24, "has signature" },
{ 25, "has key" },
{ 28, "has IPv6 address" },
{ 29, "location" },
{ 0, NULL }
};
static char *
{
union {
const char *consttext;
char *deconsttext;
} totext;
} else
return totext.deconsttext;
}
ISC_PLATFORM_NORETURN_PRE static void
static void
show_usage(void) {
"Usage: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time]\n"
" [-R number] [-m flag] hostname [server]\n"
" -a is equivalent to -v -t ANY\n"
" -c specifies query class for non-IN data\n"
" -C compares SOA records on authoritative nameservers\n"
" -d is equivalent to -v\n"
" -i IP6.INT reverse lookups\n"
" -l lists all hosts in a domain, using AXFR\n"
" -m set memory debugging flag (trace|record|usage)\n"
" -N changes the number of dots allowed before root lookup is done\n"
" -r disables recursive processing\n"
" -R specifies number of retries for UDP packets\n"
" -s a SERVFAIL response should stop query\n"
" -t specifies the query type\n"
" -v enables verbose output\n"
" -V print version number and exit\n"
" -w specifies to wait forever for a reply\n"
" -W specifies how long to wait for a reply\n"
" -4 use IPv4 query transport only\n"
" -6 use IPv6 query transport only\n", stderr);
exit(1);
}
static void
host_shutdown(void) {
(void) isc_app_shutdown();
}
static void
int diff;
if (!short_form) {
printf("Received %u bytes from %s in %d ms\n",
}
}
static void
if (!short_form)
}
static void
{
isc_buffer_t *b = NULL;
isc_region_t r;
if (result == ISC_R_NOSPACE) {
isc_buffer_free(&b);
bufsize *= 2;
goto retry;
}
isc_buffer_usedregion(b, &r);
printf("Nameserver %s:\n\t",
}
}
printf("\n");
isc_buffer_free(&b);
}
#ifdef DIG_SIGCHASE
/* Just for compatibility : not use in host program */
static isc_result_t
{
return(ISC_FALSE);
}
#endif
static isc_result_t
{
isc_region_t r;
if (sectionid == DNS_SECTION_QUESTION)
else
if (headers)
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
print_name = name;
!((!list_addresses &&
(list_type == dns_rdatatype_any ||
(list_addresses &&
continue;
if (!short_form) {
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
}
#else
#endif
} else {
while (loopresult == ISC_R_SUCCESS) {
struct rtype *t;
const char *rtt;
+ 20];
goto found;
}
}
sizeof(typebuf));
"has %s record", typebuf);
}
}
}
if (!short_form) {
isc_buffer_usedregion(&target, &r);
if (no_rdata)
(char *)r.base);
else
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
{
isc_region_t r;
if (headers)
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
return (ISC_R_SUCCESS);
}
static void
while (i-- > 0) {
dns_rdatatype_cname, 0, NULL,
&rdataset);
if (result != ISC_R_SUCCESS)
return;
}
}
static isc_result_t
int force_error;
/*
* We get called multiple times.
* Preserve any existing error status.
*/
seen_error = 1;
if (listed_server && !printed_server) {
printf("Using domain server:\n");
sizeof(sockstr));
printf("Aliases: \n\n");
}
printf("Nameserver %s:\n\t%s not found: %d(%s)\n",
else
printf("Host %s not found: %d(%s)\n",
return (ISC_R_SUCCESS);
}
/* Add AAAA and MX lookups. */
}
}
}
if (!short_form) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
printf(";; flags: ");
printf("qr");
}
}
}
}
}
}
}
printf("; QUERY: %u, ANSWER: %u, "
"AUTHORITY: %u, ADDITIONAL: %u\n",
printf(";; EDNS: version: %u, udp=%u\n",
printf(";; PSEUDOSECTIONS: TSIG\n");
}
!short_form) {
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
if (!short_form)
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
!short_form) {
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
!short_form) {
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
"PSEUDOSECTION TSIG", ISC_TRUE);
if (result != ISC_R_SUCCESS)
return (result);
}
if (!short_form)
printf("\n");
if (short_form && !default_lookups &&
sizeof(typestr));
}
return (result);
}
/*% version */
static void
version(void) {
}
static void
int c;
switch (c) {
case 'm':
else if (strcasecmp("record",
isc_commandline_argument) == 0)
else if (strcasecmp("usage",
isc_commandline_argument) == 0)
break;
case '4':
if (ipv6only)
fatal("only one of -4 and -6 allowed");
break;
case '6':
if (ipv4only)
fatal("only one of -4 and -6 allowed");
break;
case 'a': break;
case 'c': break;
case 'd': break;
case 'i': break;
case 'l': break;
case 'n': break;
case 'r': break;
case 's': break;
case 't': break;
case 'v': break;
case 'V':
version();
exit(0);
break;
case 'w': break;
case 'C': break;
case 'D':
if (debugging)
break;
case 'N': break;
case 'R': break;
case 'T': break;
case 'W': break;
default:
show_usage();
}
}
}
static void
int c;
lookup = make_empty_lookup();
short_form = !verbose;
switch (c) {
case 'l':
fatalexit = 3;
break;
case 'v':
case 'd':
break;
case 'r':
break;
case 't':
"ixfr=", 5) == 0) {
/* XXXMPA add error checking */
NULL, 10);
} else {
(isc_textregion_t *)&tr);
}
if (result != ISC_R_SUCCESS) {
fatalexit = 2;
fatal("invalid type: %s\n",
}
#ifdef WITH_IDN
idnoptions = 0;
#endif
if (rdtype == dns_rdatatype_axfr) {
/* -l -t any -v */
} else if (rdtype == dns_rdatatype_ixfr) {
} else if (rdtype == dns_rdatatype_any) {
if (!lookup->tcp_mode_set)
#ifdef WITH_IDN
} else if (rdtype == dns_rdatatype_a ||
rdtype == dns_rdatatype_aaaa ||
rdtype == dns_rdatatype_mx) {
#endif
} else
break;
case 'c':
(isc_textregion_t *)&tr);
if (result != ISC_R_SUCCESS) {
fatalexit = 2;
fatal("invalid class: %s\n",
} else {
}
break;
case 'a':
#ifdef WITH_IDN
idnoptions = 0;
#endif
break;
case 'i':
break;
case 'n':
/* deprecated */
break;
case 'm':
/* Handled by pre_parse_args(). */
break;
case 'w':
/*
* The timer routines are coded such that
* timeout==MAXINT doesn't enable the timer
*/
break;
case 'W':
if (timeout < 1)
timeout = 1;
break;
case 'R':
if (tries < 2)
tries = 2;
break;
case 'T':
break;
case 'U':
break;
case 'C':
debug("showing all SOAs");
break;
case 'N':
debug("setting NDOTS to %s",
break;
case 'D':
/* Handled by pre_parse_args(). */
break;
case '4':
/* Handled by pre_parse_args(). */
break;
case '6':
/* Handled by pre_parse_args(). */
break;
case 's':
break;
}
}
if (isc_commandline_index >= argc)
show_usage();
} else
} else {
}
}
int
tries = 2;
fatalexit = 1;
#ifdef WITH_IDN
#endif
/* setup dighost callbacks */
#ifdef DIG_SIGCHASE
#endif
debug("main()");
result = isc_app_start();
setup_libs();
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
isc_app_run();
cancel_all();
destroy_libs();
return ((seen_error == 0) ? 0 : 1);
}