host.c revision 2a23a625246acfbf6ff92b86a6b8b9df59dbeaa4
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: host.c,v 1.97 2004/04/13 02:54:14 marka Exp $ */
#include <config.h>
#include <limits.h>
#include <isc/commandline.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
extern dig_serverlist_t server_list;
extern isc_boolean_t usesearch;
extern isc_boolean_t debugging;
extern unsigned int timeout;
extern int ndots;
extern int tries;
extern char *progname;
extern isc_task_t *global_task;
extern int fatalexit;
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 void
show_usage(void) {
"Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
" [-R number] hostname [server]\n"
" -a is equivalent to -v -t *\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"
" -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", 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 t[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 (;;) {
isc_buffer_init(&target, t, sizeof(t));
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 t[4096];
if (headers)
isc_buffer_init(&target, t, sizeof(t));
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
return (ISC_R_SUCCESS);
}
int force_error;
/*
* We get called multiple times.
* Preserve any existing error status.
*/
seen_error = 1;
if (listed_server) {
char sockstr[ISC_SOCKADDR_FORMATSIZE];
printf("Using domain server:\n");
sizeof(sockstr));
printf("Aliases: \n\n");
}
char namestr[DNS_NAME_FORMATSIZE];
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 void
int c;
isc_uint32_t serial = 0;
lookup = make_empty_lookup();
!= EOF) {
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",
}
if (rdtype == dns_rdatatype_axfr) {
/* -l -t any -v */
} else if (rdtype == dns_rdatatype_ixfr) {
} else
break;
case 'c':
(isc_textregion_t *)&tr);
if (result != ISC_R_SUCCESS) {
fatalexit = 2;
fatal("invalid class: %s\n",
} else {
}
break;
case 'a':
break;
case 'i':
break;
case 'n':
/* deprecated */
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':
break;
case '4':
if (have_ipv4) {
} else
fatal("can't find IPv4 networking");
break;
case '6':
if (have_ipv6) {
} else
fatal("can't find IPv6 networking");
break;
}
}
if (isc_commandline_index >= argc)
show_usage();
}
} else {
}
}
int
tries = 2;
fatalexit = 1;
debug("main()");
result = isc_app_start();
setup_libs();
setup_system();
isc_app_run();
cancel_all();
destroy_libs();
return ((seen_error == 0) ? 0 : 1);
}