[BusyBox] bug#1182: [PATCH] - add explicit name server option to nslookup.c + minor other fix
Benjamin Zeckel
bzeckel at cisco.com
Tue Jun 12 21:45:03 MDT 2001
Package: busybox
Version: CVS
Severity: wishlist
This is a different patch than the one I just sent a few days ago.
This patch alters nslookup.c and usage.h to add a explicit nameserver
option to nslookup
nslookup www.site.com = lookup www.site.com using /etc/resolv.conf DNS servers
nslookup www.site.com my.dns.server.net = lookup www.site.com with explicit
DNS server my.dns.server.net
nslookup a b c ... = show usage for more than 2 arguments as according to
standard nslookup, that is an error
It's output is the same as gnu (with minor whitespace variations which were
in the original cvs version).
I have tested it against multibuild.pl script and it breaks nothing new
It increases the binary size (as compared to vanilla nslookup busybox
version) by about 70 bytes
I tried to follow the style guide a little more closely this time around
(as the first applied patch had been slightly altered which
is fine by me but a waste of time for someone)
Thanks much
Ben Zeckel
bzeckel at hmc.edu
bzeckel at cisco.com
-------------- next part --------------
Index: nslookup.c
===================================================================
RCS file: /var/cvs/busybox/nslookup.c,v
retrieving revision 1.23
diff -b -w -u -r1.23 nslookup.c
--- nslookup.c 2001/06/12 22:21:24 1.23
+++ nslookup.c 2001/06/13 02:18:24
@@ -5,6 +5,9 @@
* Copyright (C) 1999,2000,2001 by Lineo, inc.
* Written by John Beppu <beppu at lineo.com>
*
+ * Correct default name server display and explicit name server option
+ * added by Ben Zeckel <bzeckel at hmc.edu> June 2001
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -38,9 +41,6 @@
/*
| I'm only implementing non-interactive mode;
| I totally forgot nslookup even had an interactive mode.
- |
- | [ TODO ]
- | + find out how to use non-default name servers
*/
/* only works for IPv4 */
@@ -138,6 +138,19 @@
printf("\n");
}
+/* alter the global _res nameserver structure to use
+ an explicit dns server instead of what is in /etc/resolv.h */
+static inline void set_default_dns(char *server)
+{
+ struct in_addr server_in_addr;
+
+ if(inet_aton(server,&server_in_addr))
+ {
+ _res.nscount = 1;
+ _res.nsaddr_list[0].sin_addr = server_in_addr;
+ }
+}
+
/* naive function to check whether char *s is an ip address */
static int is_ip_address(const char *s)
{
@@ -156,11 +169,30 @@
{
struct hostent *host;
+ /*
+ * initialize DNS structure _res used in printing the default
+ * name server and in the explicit name server option feature.
+ */
+
+ res_init();
+
+ /*
+ * We allow 1 or 2 arguments.
+ * The first is the name to be looked up and the second is an
+ * optional DNS server with which to do the lookup.
+ * More than 3 arguments is an error to follow the pattern of the
+ * standard nslookup
+ */
+
+
if (argc < 2 || *argv[1]=='-') {
show_usage();
+ } else if(argc == 3) {
+ set_default_dns(argv[2]);
+ } else if(argc > 3) {
+ show_usage();
}
- res_init();
server_print();
if (is_ip_address(argv[1])) {
host = gethostbyaddr_wrapper(argv[1]);
Index: usage.h
===================================================================
RCS file: /var/cvs/busybox/usage.h,v
retrieving revision 1.49
diff -b -w -u -r1.49 usage.h
--- usage.h 2001/06/03 05:41:59 1.49
+++ usage.h 2001/06/13 02:18:25
@@ -1154,9 +1154,10 @@
"221 foobar closing connection\n"
#define nslookup_trivial_usage \
- "[HOST]"
+ "[HOST] [SERVER]"
#define nslookup_full_usage \
- "Queries the nameserver for the IP address of the given HOST"
+ "Queries the nameserver for the IP address of the given HOST\n" \
+ "optionally using a specified DNS server"
#define nslookup_example_usage \
"$ nslookup localhost\n" \
"Server: default\n" \
More information about the busybox
mailing list