Commit d8468516 authored by Jeremy C. Reed's avatar Jeremy C. Reed
Browse files

Merged jreed-host branch. See trac #872. This includes code updates, new...

Merged jreed-host branch. See trac #872. This includes code updates, new manual page, but no unit tests.
parents 50ebc839 372a2f03
......@@ -10,17 +10,20 @@ endif
CLEANFILES = *.gcno *.gcda
bin_PROGRAMS = host
host_SOURCES = host.cc
host_LDADD = $(top_builddir)/src/lib/dns/libdns++.la
host_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
#man_MANS = host.1
#EXTRA_DIST = $(man_MANS) host.xml
#
#if ENABLE_MAN
#
#host.1: host.xml
# xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/host.xml
#
#endif
bin_PROGRAMS = b10-host
b10_host_SOURCES = host.cc
b10_host_LDADD = $(top_builddir)/src/lib/dns/libdns++.la
b10_host_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
man_MANS = b10-host.1
EXTRA_DIST = $(man_MANS) b10-host.xml
.PHONY: man
if ENABLE_MAN
man: b10-host.1
b10-host.1: b10-host.xml
xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-host.xml
endif
Rewriting host(1) in C++ from scratch using BIND 10's libdns.
Rewriting host(1) in C++ from scratch using BIND 10's libdns++.
Initial functionality:
host _hostname_ [server]
By default, it looks up the A, AAAA, and MX record sets.
Note it doesn't use /etc/resolv.conf at this time.
The default name server used is 127.0.0.1.
-r disable recursive processing
-t _type_ specific query type
-v enable verbose output mode, including elapsed time
The bugs and incompatibilities are listed in the manual page
and in the source code.
'\" t
.\" Title: b10-host
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: May 4, 2011
.\" Manual: BIND10
.\" Source: BIND10
.\" Language: English
.\"
.TH "B10\-HOST" "1" "May 4, 2011" "BIND10" "BIND10"
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
b10-host \- DNS lookup utility
.SH "SYNOPSIS"
.HP \w'\fBb10\-host\fR\ 'u
\fBb10\-host\fR [\fB\-a\fR] [\fB\-c\ \fR\fB\fIclass\fR\fR] [\fB\-d\fR] [\fB\-p\ \fR\fB\fIport\fR\fR] [\fB\-r\fR] [\fB\-t\ \fR\fB\fItype\fR\fR] [\fB\-v\fR] [\fIname\fR] [\fB\fIserver\fR\fR]
.SH "DESCRIPTION"
.PP
The
\fBb10\-host\fR
utility does DNS lookups\&. Its initial goal is to be a
\fBhost\fR(1)
clone, but also add a few features useful for BIND 10 development testing\&.
.PP
By default, it looks up the A, AAAA, and MX record sets for the
\fIname\fR\&. Optionally, you may select a name server to query against by adding the
\fIserver\fR
argument\&.
.SH "OPTIONS"
.PP
The arguments are as follows:
.PP
\fB\-a\fR
.RS 4
Enable verbose mode and do a query for type ANY\&. (If the
\fB\-t\fR
option is also set, then the ANY query is not done, but it still uses verbose mode\&.)
.RE
.PP
\fB\-c \fR\fB\fIclass\fR\fR
.RS 4
Define the class for the query\&. The default is IN (Internet)\&.
.RE
.PP
\fB\-d\fR
.RS 4
Enable verbose output mode, including elapsed time in milliseconds\&. Verbose mode shows the header, question, answer, authority, and additional sections (if provided)\&. (Same as
\fB\-v\fR\&.)
.RE
.PP
\fB\-p \fR\fB\fIport\fR\fR
.RS 4
Select an alternative port for the query\&. This may be a number or a service name\&. The default is 53 (domain)\&. This is not a standard feature of
\fBhost\fR(1)\&.
.RE
.PP
\fB\-r\fR
.RS 4
Disable recursive processing by not setting the Recursion Desired flag in the query\&.
.RE
.PP
\fB\-t \fR\fB\fItype\fR\fR
.RS 4
Select a specific resource record type for the query\&. By default, it looks up the A, AAAA, and MX record sets\&.
(This overrides the
\fB\-a\fR
option\&.)
.RE
.PP
\fB\-v\fR
.RS 4
Same as
\fB\-d\fR
option\&.
.RE
.SH "COMPATIBILITY / BUGS"
.PP
\fBb10\-host\fR
does not do reverse lookups by default yet (by detecting if name is a IPv4 or IPv6 address)\&.
.PP
Unknown
\fB\-c\fR
class or
\fB\-t\fR
type causes
\fBb10\-host\fR
to Abort\&.
.PP
Not all types are supported yet for formatting\&. Not all switches are supported yet\&.
.PP
It doesn\'t use
/etc/resolv\&.conf
at this time\&. The default name server used is 127\&.0\&.0\&.1\&.
.PP
\fBb10\-host\fR
does not do reverse lookups by default yet (by detecting if name is a IPv4 or IPv6 address)\&.
.PP
\fB\-p\fR
is not a standard feature\&.
.SH "HISTORY"
.PP
The C++ version of
\fBb10\-host\fR
was started in October 2009 by Jeremy C\&. Reed of ISC\&. Its usage and output were based on the standard
\fBhost\fR
command\&.
.SH "COPYRIGHT"
.br
Copyright \(co 2011 Internet Systems Consortium, Inc. ("ISC")
.br
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
-
- Permission to use, copy, modify, and/or 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$ -->
<refentry>
<refentryinfo>
<date>May 4, 2011</date>
</refentryinfo>
<refmeta>
<refentrytitle>b10-host</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo>BIND10</refmiscinfo>
</refmeta>
<refnamediv>
<refname>b10-host</refname>
<refpurpose>DNS lookup utility</refpurpose>
</refnamediv>
<docinfo>
<copyright>
<year>2011</year>
<holder>Internet Systems Consortium, Inc. ("ISC")</holder>
</copyright>
</docinfo>
<refsynopsisdiv>
<cmdsynopsis>
<command>b10-host</command>
<arg><option>-a</option></arg>
<arg><option>-c <replaceable>class</replaceable></option></arg>
<arg><option>-d</option></arg>
<arg><option>-p <replaceable>port</replaceable></option></arg>
<arg><option>-r</option></arg>
<arg><option>-t <replaceable>type</replaceable></option></arg>
<arg><option>-v</option></arg>
<arg><replaceable>name</replaceable></arg>
<arg><option><replaceable>server</replaceable></option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
The <command>b10-host</command> utility does DNS lookups.
Its initial goal is to be a
<citerefentry><refentrytitle>host</refentrytitle>
<manvolnum>1</manvolnum></citerefentry>
clone, but also add a few features useful for BIND 10 development
testing.
</para>
<para>
By default, it looks up the A, AAAA, and MX record sets for the
<replaceable>name</replaceable>.
Optionally, you may select a name server to query against by adding
the <replaceable>server</replaceable> argument.
</para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
<para>The arguments are as follows:</para>
<variablelist>
<varlistentry>
<term><option>-a</option></term>
<listitem><para>
Enable verbose mode and do a query for type ANY.
(If the <option>-t</option> option is also set, then the
ANY query is not done, but it still uses verbose mode.)
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-c <replaceable>class</replaceable></option></term>
<listitem><para>
Define the class for the query.
The default is IN (Internet).
<!-- TODO: bug if class is unknown causes seg fault and possible core dump -->
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-d</option></term>
<listitem><para>
Enable verbose output mode, including elapsed time in
milliseconds.
Verbose mode shows the header, question, answer, authority,
and additional sections (if provided).
(Same as <option>-v</option>.)
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-p <replaceable>port</replaceable></option></term>
<listitem><para>
Select an alternative port for the query.
This may be a number or a service name.
The default is 53 (domain).
This is not a standard feature of
<citerefentry><refentrytitle>host</refentrytitle>
<manvolnum>1</manvolnum></citerefentry>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-r</option></term>
<listitem><para>
Disable recursive processing by not setting the
Recursion Desired flag in the query.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-t <replaceable>type</replaceable></option></term>
<listitem><para>
Select a specific resource record type for the query.
By default, it looks up the A, AAAA, and MX record sets.
<!-- TODO: bug if class is unknown causes seg fault and possible core dump -->
(This overrides the <option>-a</option> option.)
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<listitem><para>
Same as <option>-d</option> option.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>COMPATIBILITY / BUGS</title>
<para>
<command>b10-host</command> does not do reverse lookups by
default yet (by detecting if name is a IPv4 or IPv6 address).
</para>
<para>
Unknown <option>-c</option> class or <option>-t</option> type
causes <command>b10-host</command> to Abort.
</para>
<para>
Not all types are supported yet for formatting.
Not all switches are supported yet.
</para>
<para>
It doesn't use <filename>/etc/resolv.conf</filename> at this time.
The default name server used is 127.0.0.1.
</para>
<para>
<command>b10-host</command> does not do reverse lookups by
default yet (by detecting if name is a IPv4 or IPv6 address).
</para>
<para>
<option>-p</option> is not a standard feature.
</para>
</refsect1>
<refsect1>
<title>HISTORY</title>
<para>
The C++ version of <command>b10-host</command> was started in
October 2009 by Jeremy C. Reed of ISC.
Its usage and output were based on the standard <command>host</command>
command.
</para>
</refsect1>
</refentry><!--
- Local variables:
- mode: sgml
- End:
-->
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2010-2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -44,13 +44,16 @@ namespace {
char* dns_type = NULL; // not set, so A, AAAA, MX
const char* server = "127.0.0.1";
const char* server_port = "53";
int verbose = 0;
int first_time = 1;
bool recursive_bit = true;
const char* dns_class = "IN";
bool verbose = false;
bool dns_any = false;
int first_time = 1;
bool recursive_bit = true;
struct timeval before_time, after_time;
int
host_lookup(const char* const name, const char* const type) {
host_lookup(const char* const name, const char* const dns_class,
const char* const type, bool any) {
Message msg(Message::RENDER);
......@@ -64,8 +67,8 @@ host_lookup(const char* const name, const char* const type) {
}
msg.addQuestion(Question(Name(name),
RRClass::IN(), // IN class only for now
RRType(type))); // if NULL then:
RRClass(dns_class),
any ? RRType::ANY() : RRType(type))); // if NULL then:
OutputBuffer obuffer(512);
MessageRenderer renderer(obuffer);
......@@ -127,18 +130,29 @@ host_lookup(const char* const name, const char* const type) {
rmsg.fromWire(ibuffer);
if (!verbose) {
string description = "";
for (RRsetIterator it =
rmsg.beginSection(Message::SECTION_ANSWER);
it != rmsg.endSection(Message::SECTION_ANSWER);
++it) {
if ((*it)->getType() != RRType::A()) {
continue;
if ((*it)->getType() == RRType::A()) {
description = "has address";
}
else if ((*it)->getType() == RRType::AAAA()) {
description = "has IPv6 address";
}
else if ((*it)->getType() == RRType::MX()) {
description = "mail is handled by";
}
else if ((*it)->getType() == RRType::TXT()) {
description = "descriptive text";
}
RdataIteratorPtr rit = (*it)->getRdataIterator();
for (; !rit->isLast(); rit->next()) {
// instead of using my name, maybe use returned label?
cout << name << " has address " <<
cout << name << " " << description << " " <<
(*rit).getCurrent().toText() << endl;
}
}
......@@ -159,13 +173,19 @@ host_lookup(const char* const name, const char* const type) {
// TODO: if NXDOMAIN, host(1) doesn't show HEADER
// Host hsdjkfhksjhdfkj not found: 3(NXDOMAIN)
// TODO: figure out the new libdns way to test if NXDOMAIN
// TODO: test if NXDOMAIN
std::cout << "Received " << cc <<
" bytes in " << elapsed_time << " ms\n";
// TODO: " bytes from 127.0.0.1#53 in 0 ms
} //verbose
/*
TODO: handle InvalidRRClass
TODO: handle invalid type exception
} catch (InvalidType ivt) {
std::cerr << "invalid type:" << ivt.what();
*/
} catch (const exception& ex) {
std::cerr << "parse failed for " <<
string(name) << "/" << type << ": " << ex.what() << std::endl;
......@@ -184,26 +204,36 @@ int
main(int argc, char* argv[]) {
int c;
while ((c = getopt(argc, argv, "p:rt:v")) != -1)
while ((c = getopt(argc, argv, "ac:dp:rt:v")) != -1)
switch (c) {
case 'a':
dns_any = true;
verbose = true;
break;
case 'c':
dns_class = optarg;
break;
// p for port is a non-standard switch
case 'p':
server_port = optarg;
break;
case 'r':
recursive_bit = false;
break;
case 't':
dns_type = optarg;
break;
case 'p':
server_port = optarg;
break;
case 'd':
// drop through to v, because debug and verbose are equivalent
case 'v':
verbose = 1;
verbose = true;
break;
}
argc -= optind;
argv += optind;
if (argc < 1) {
cout << "Usage: host [-vr] [-t type] hostname [server]\n";
cout << "Usage: host [-adprv] [-c class] [-t type] hostname [server]\n";
exit(1);
}
......@@ -212,12 +242,13 @@ main(int argc, char* argv[]) {
}
if (dns_type == NULL) {
host_lookup(argv[0], "A");
host_lookup(argv[0], dns_class, "A", dns_any);
// TODO: don't do next if A doesn't exist
host_lookup(argv[0], "AAAA");
host_lookup(argv[0], "MX");
host_lookup(argv[0], dns_class, "AAAA", dns_any);
host_lookup(argv[0], dns_class, "MX", dns_any);
} else {
host_lookup(argv[0], dns_type);
// -t overrides -a, regardless of order
host_lookup(argv[0], dns_class, dns_type, false);
}
return (0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment