host.c revision 77ab862dca0158f88a107e105f868ba0f157a7e8
/*
* Copyright (C) 2004-2007 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.112 2007/02/26 23:46:54 tbox Exp $ */
/*! \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 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", 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);
}
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];
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:vwCDN:R:TW:";
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': break;
case '6': 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 'w': break;
case 'C': break;
case 'D': 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();
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':
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':
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;
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();
setup_system();
isc_app_run();
cancel_all();
destroy_libs();
return ((seen_error == 0) ? 0 : 1);
}