host.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000-2007, 2009-2016 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 int seen_error = -1;
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 *
{
static char buf[sizeof("?65535")];
union {
const char *consttext;
char *deconsttext;
} totext;
} else
return totext.deconsttext;
}
ISC_PLATFORM_NORETURN_PRE static void
static void
show_usage(void) {
"Usage: host [-aCdlriTwv] [-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"
" -l lists all hosts in a domain, using AXFR\n"
" -i IP6.INT reverse lookups\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"
" -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"
" -m set memory debugging flag (trace|record|usage)\n"
" -V print version number and exit\n", stderr);
exit(1);
}
void
dighost_shutdown(void) {
}
void
int diff;
if (!short_form) {
char fromtext[ISC_SOCKADDR_FORMATSIZE];
printf("Received %u bytes from %s in %d ms\n",
}
}
void
if (!short_form)
}
static void
{
isc_buffer_t *b = NULL;
char namestr[DNS_NAME_FORMATSIZE];
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 */
{
return(ISC_FALSE);
}
#endif
static isc_result_t
{
isc_region_t r;
char tbuf[4096];
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;
char typebuf[DNS_RDATATYPE_FORMATSIZE];
+ 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;
char tbuf[4096];
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;
}
}
int force_error;
/*
* We get called multiple times.
* Preserve any existing error status.
*/
seen_error = 1;
if (listed_server && !printed_server) {
char sockstr[ISC_SOCKADDR_FORMATSIZE];
printf("Using domain server:\n");
sizeof(sockstr));
printf("Aliases: \n\n");
}
char namestr[DNS_NAME_FORMATSIZE];
printf("Nameserver %s:\n\t%s not found: %d(%s)\n",
else
printf("Host %s not found: %d(%s)\n",
return (ISC_R_SUCCESS);
}
char namestr[DNS_NAME_FORMATSIZE];
/* 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 &&
char namestr[DNS_NAME_FORMATSIZE];
char typestr[DNS_RDATATYPE_FORMATSIZE];
sizeof(typestr));
}
return (result);
}
static const char * optstring = "46ac:dilnm:rst:vVwCDN:R:TW:";
/*% 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;
isc_uint32_t serial = 0;
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) {
#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 '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
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);
}