[svn] commit: r239 - in /branches/f2f200910/src/bin/host: README host.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Oct 30 18:11:43 UTC 2009
Author: jreed
Date: Fri Oct 30 18:11:43 2009
New Revision: 239
Log:
Some code cleanup.
Now verbose is off (but non-verbouse output is not enabled yet).
Options added:
-v verbose and elapsed time
-t type
-r clear recursive bit
Modified:
branches/f2f200910/src/bin/host/README
branches/f2f200910/src/bin/host/host.cc
Modified: branches/f2f200910/src/bin/host/README
==============================================================================
--- branches/f2f200910/src/bin/host/README (original)
+++ branches/f2f200910/src/bin/host/README Fri Oct 30 18:11:43 2009
@@ -4,10 +4,11 @@
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.
-Default name server used is 127.0.0.1.
-
-NO SWITCHES ARE IMPLEMENTED YET.
+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
Modified: branches/f2f200910/src/bin/host/host.cc
==============================================================================
--- branches/f2f200910/src/bin/host/host.cc (original)
+++ branches/f2f200910/src/bin/host/host.cc Fri Oct 30 18:11:43 2009
@@ -14,8 +14,9 @@
char* dns_type = NULL; // not set, so A, AAAA, MX
std::string server = "127.0.0.1";
-int verbose = 1; // later make this an option and default to 0
+int verbose = 0;
int first_time = 1;
+bool recursive_bit = true;
struct timeval before_time, after_time;
int
@@ -27,7 +28,7 @@
msg.setQid(0); // does this matter?
// TODO: add switch for this
- msg.setRD(true); // set recursive bit
+ msg.setRD(recursive_bit); // set recursive bit
msg.addQuestion(Name(name),
RRClass::IN, // IN class only for now
@@ -86,34 +87,30 @@
if (verbose) {
gettimeofday(&after_time, NULL);
- }
-// This is for verbose too
-// no check yet until non-verbose way is done
- // HEADER and QUESTION SECTION:
- std::cout << rmsg.toText() << std::endl;
-// ;; ANSWER SECTION:
-// std::cout << rmsg.getBuffer().getSection(SECTION_ANSWER).toText();
-// SECTION_AUTHORITY
-// SECTION_ADDITIONAL
+ // HEADER and QUESTION, ANSWER, AUTHORITY, and ADDITIONAL
+ std::cout << rmsg.toText() << std::endl;
- if (before_time.tv_usec > after_time.tv_usec) {
- after_time.tv_usec += 1000000;
- --after_time.tv_sec;
- }
+ if (before_time.tv_usec > after_time.tv_usec) {
+ after_time.tv_usec += 1000000;
+ --after_time.tv_sec;
+ }
- int elapsed_time =
- (after_time.tv_sec - before_time.tv_sec)
- + ((after_time.tv_usec - before_time.tv_usec))/1000;
+ int elapsed_time =
+ (after_time.tv_sec - before_time.tv_sec)
+ + ((after_time.tv_usec - before_time.tv_usec))/1000;
// 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
- std::cout << "Received " <<
- boost::lexical_cast<string>(rmsg.getBuffer().getSize()) <<
- " bytes in " << elapsed_time << " ms\n";
-// TODO: " bytes from 127.0.0.1#53 in 0 ms
+ std::cout << "Received " <<
+ boost::lexical_cast<string>(rmsg.getBuffer().getSize()) <<
+ " bytes in " << elapsed_time << " ms\n";
+ // TODO: " bytes from 127.0.0.1#53 in 0 ms
+
+ } //verbose
+
} catch (...) {
std::cerr << "parse failed for " << type << std::endl;
}
@@ -127,24 +124,42 @@
main(int argc, char* argv[])
{
- if (argc < 2) {
- cout << "Usage: host hostname [server]\n";
- }
- else {
+ int c;
- if (argc >= 3) {
- server = argv[2];
- }
+ while ((c = getopt(argc, argv, "rt:v")) != -1)
+ switch (c) {
- if (!dns_type) {
- host_lookup(argv[1], "A");
-// TODO: don't do next if A doesn't exist
- host_lookup(argv[1], "AAAA");
- host_lookup(argv[1], "MX");
- }
+ case 'r':
+ recursive_bit = false;
+ break;
+ case 't':
+ dns_type = optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
}
+ argc -= optind;
+ argv += optind;
+ if (argc < 1) {
+ cout << "Usage: host [-vr] [-t type] hostname [server]\n";
+ exit(1);
+ }
+
+ if (argc >= 2) {
+ server = argv[1];
+ }
+
+ if (!dns_type) {
+ host_lookup(argv[0], "A");
+// TODO: don't do next if A doesn't exist
+ host_lookup(argv[0], "AAAA");
+ host_lookup(argv[0], "MX");
+ } else {
+ host_lookup(argv[0], dns_type);
+ }
return (0);
}
More information about the bind10-changes
mailing list