Hi,

I've added the host applet in nslookup.c and changed the output of
nslookup to be more standard, plus minor changes.

$ ./busybox_old nslookup www.google.com
Server:    80.58.61.250
Address 1: 80.58.61.250 250.Red-80-58-61.staticIP.rima-tde.net

Name:      www.google.com
Address 1: 74.125.39.103 fx-in-f103.1e100.net
Address 2: 74.125.39.106 fx-in-f106.1e100.net
Address 3: 74.125.39.147 fx-in-f147.1e100.net
Address 4: 74.125.39.99 fx-in-f99.1e100.net
Address 5: 74.125.39.105 fx-in-f105.1e100.net
Address 6: 74.125.39.104 fx-in-f104.1e100.net


$ ./busybox nslookup www.google.com
Server:  80.58.61.250
Address: 80.58.61.250 250.Red-80-58-61.staticIP.rima-tde.net

Name:    www.google.com
Address: 74.125.39.103 fx-in-f103.1e100.net
Name:    www.google.com
Address: 74.125.39.106 fx-in-f106.1e100.net
Name:    www.google.com
Address: 74.125.39.147 fx-in-f147.1e100.net
Name:    www.google.com
Address: 74.125.39.99 fx-in-f99.1e100.net
Name:    www.google.com
Address: 74.125.39.105 fx-in-f105.1e100.net
Name:    www.google.com
Address: 74.125.39.104 fx-in-f104.1e100.net


$ ./busybox host www.google.com
www.google.com has address 74.125.39.103
www.google.com has address 74.125.39.106
www.google.com has address 74.125.39.147
www.google.com has address 74.125.39.99
www.google.com has address 74.125.39.105
www.google.com has address 74.125.39.104


!ENABLE_HOST && ENABLE_NSLOOKUP
$ make bloatcheck
function                                             old     new   delta
packed_usage                                       28561   28550     -11
.rodata                                           148940  148927     -13
print_host                                           214     189     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-49)             Total: -49 bytes
   text    data     bss     dec     hex filename
 936792    4146    9552  950490   e80da busybox_old
 936754    4146    9552  950452   e80b4 busybox_unstripped


ENABLE_HOST && ENABLE_NSLOOKUP
$ make bloatcheck
function                                             old     new   delta
.rodata                                           148940  148962     +22
nslookup_main                                        195     207     +12
print_host                                           214     223      +9
applet_main                                         2808    2816      +8
applet_names                                        2411    2416      +5
applet_nameofs                                       702     704      +2
packed_usage                                       28561   28559      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/1 up/down: 58/-2)              Total: 56 bytes
   text    data     bss     dec     hex filename
 936792    4146    9552  950490   e80da busybox_old
 936835    4146    9552  950533   e8105 busybox_unstripped


Patch attached.

Regards,
-- 
Pere
From 73e29a2befecc774efe7a0c243090c52286c331a Mon Sep 17 00:00:00 2001
From: Pere Orga <[email protected]>
Date: Thu, 18 Aug 2011 12:14:13 +0200
Subject: [PATCH] host: new applet. nslookup: changed output to be more standard


Signed-off-by: Pere Orga <[email protected]>
---
 include/applets.src.h |    1 -
 networking/Config.src |    6 ------
 networking/Kbuild.src |    1 -
 networking/nslookup.c |   48 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/include/applets.src.h b/include/applets.src.h
index a5866d8..a4950c8 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -268,7 +268,6 @@ IF_NC(APPLET(nc, BB_DIR_USR_BIN, BB_SUID_DROP))
 IF_NETSTAT(APPLET(netstat, BB_DIR_BIN, BB_SUID_DROP))
 IF_NICE(APPLET(nice, BB_DIR_BIN, BB_SUID_DROP))
 IF_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP))
-IF_NSLOOKUP(APPLET(nslookup, BB_DIR_USR_BIN, BB_SUID_DROP))
 IF_NTPD(APPLET(ntpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_OD(APPLET(od, BB_DIR_USR_BIN, BB_SUID_DROP))
 IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP))
diff --git a/networking/Config.src b/networking/Config.src
index 8aeba0e..0b01e3b 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -635,12 +635,6 @@ config FEATURE_NETSTAT_PRG
 	  Add support for -p flag to print out PID and program name.
 	  +700 bytes of code.
 
-config NSLOOKUP
-	bool "nslookup"
-	default y
-	help
-	  nslookup is a tool to query Internet name servers.
-
 config NTPD
 	bool "ntpd"
 	default y
diff --git a/networking/Kbuild.src b/networking/Kbuild.src
index 944f27b..62b7741 100644
--- a/networking/Kbuild.src
+++ b/networking/Kbuild.src
@@ -28,7 +28,6 @@ lib-$(CONFIG_IPCALC)       += ipcalc.o
 lib-$(CONFIG_NAMEIF)       += nameif.o
 lib-$(CONFIG_NC)           += nc.o
 lib-$(CONFIG_NETSTAT)      += netstat.o
-lib-$(CONFIG_NSLOOKUP)     += nslookup.o
 lib-$(CONFIG_NTPD)         += ntpd.o
 lib-$(CONFIG_PSCAN)        += pscan.o
 lib-$(CONFIG_ROUTE)        += route.o
diff --git a/networking/nslookup.c b/networking/nslookup.c
index f4fd407..96ea5cc 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -11,8 +11,26 @@
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
+//config:config NSLOOKUP
+//config:      bool "nslookup"
+//config:      default y
+//config:      help
+//config:        nslookup is a tool to query Internet name servers.
+
+//config:config HOST
+//config:      bool "host"
+//config:      default y
+//config:      help
+//config:        host is a DNS lookup utility.
+
+//applet:IF_NSLOOKUP(APPLET(nslookup, BB_DIR_USR_BIN, BB_SUID_DROP))
+//applet:IF_HOST(APPLET_ODDNAME(host, nslookup, BB_DIR_USR_BIN, BB_SUID_DROP, host))
+
+//kbuild:lib-$(CONFIG_NSLOOKUP) += nslookup.o
+//kbuild:lib-$(CONFIG_HOST) += nslookup.o
+
 //usage:#define nslookup_trivial_usage
-//usage:       "[HOST] [SERVER]"
+//usage:       "HOST [SERVER]"
 //usage:#define nslookup_full_usage "\n\n"
 //usage:       "Query the nameserver for the IP address of the given HOST\n"
 //usage:       "optionally using a specified DNS server"
@@ -25,6 +43,16 @@
 //usage:       "Name:       debian\n"
 //usage:       "Address:    127.0.0.1\n"
 
+//usage:#define host_trivial_usage
+//usage:       "NAME [SERVER]"
+//usage:#define host_full_usage "\n\n"
+//usage:       "Lookup for NAME, "
+//usage:       "optionally using a specified DNS server"
+//usage:
+//usage:#define host_example_usage
+//usage:       "$ host busybox.net\n"
+//usage:       "busybox.net has address 140.211.167.224\n"
+
 #include <resolv.h>
 #include "libbb.h"
 
@@ -82,18 +110,18 @@ static int print_host(const char *hostname, const char *header)
 
 	if (rc == 0) {
 		struct addrinfo *cur = result;
-		unsigned cnt = 0;
 
-		printf("%-10s %s\n", header, hostname);
-		// puts(cur->ai_canonname); ?
 		while (cur) {
 			char *dotted, *revhost;
 			dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr);
-			revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr);
 
-			printf("Address %u: %s%c", ++cnt, dotted, revhost ? ' ' : '\n');
-			if (revhost) {
-				puts(revhost);
+			if (ENABLE_HOST && (!ENABLE_NSLOOKUP || applet_name[0] == 'h'))
+				printf("%s has address %s\n", hostname, dotted);
+			else {
+				revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr);
+				printf("%-8s %s\nAddress: %s%s%s\n", header, hostname,
+					dotted, revhost ? " " : "", revhost ? revhost : "");
+				// puts(cur->ai_canonname); ?
 				if (ENABLE_FEATURE_CLEAN_UP)
 					free(revhost);
 			}
@@ -184,6 +212,8 @@ int nslookup_main(int argc, char **argv)
 	if (argv[2])
 		set_default_dns(argv[2]);
 
-	server_print();
+	if (!(ENABLE_HOST && (!ENABLE_NSLOOKUP || applet_name[0] == 'h')))
+		server_print();
+
 	return print_host(argv[1], "Name:");
 }
-- 
1.7.2.5

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to