[git commit master 1/1] whois: new applet

Denys Vlasenko vda.linux at googlemail.com
Sun Feb 27 22:38:52 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=251962f20737c5138c7d33e90c68dfca856361e1
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
whois_main                                             -     118    +118
pipe_out                                               -      80     +80
packed_usage                                       28084   28095     +11
applet_names                                        2385    2391      +6
applet_main                                         1388    1392      +4
applet_nameofs                                       694     696      +2
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 4/0 up/down: 221/0)             Total: 221 bytes

Signed-off-by: Pere Orga <gotrunks at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/whois.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 networking/whois.c

diff --git a/networking/whois.c b/networking/whois.c
new file mode 100644
index 0000000..4eab9e5
--- /dev/null
+++ b/networking/whois.c
@@ -0,0 +1,66 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * whois - tiny client for the whois directory service
+ *
+ * Copyright (c) 2011 Pere Orga <gotrunks at gmail.com>
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+/* TODO
+ * Add ipv6 support
+ * Add proxy support
+ */
+
+//config:config WHOIS
+//config:	bool "whois"
+//config:	default y
+//config:	help
+//config:	  whois is a client for the whois directory service
+
+//applet:IF_WHOIS(APPLET(whois, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_WHOIS) += whois.o
+
+//usage:#define whois_trivial_usage
+//usage:       "[-h SERVER] [-p PORT] NAME..."
+//usage:#define whois_full_usage "\n\n"
+//usage:       "Query WHOIS info about NAME\n"
+//usage:     "\nOptions:"
+//usage:     "\n	-h,-p	Server to query"
+
+#include "libbb.h"
+
+static void pipe_out(int fd)
+{
+	FILE *fp;
+	char buf[1024];
+
+	fp = xfdopen_for_read(fd);
+	while (fgets(buf, sizeof(buf), fp)) {
+		char *p = strpbrk(buf, "\r\n");
+		if (p)
+			*p = '\0';
+		puts(buf);
+	}
+
+	fclose(fp); /* closes fd too */
+}
+
+int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int whois_main(int argc UNUSED_PARAM, char **argv)
+{
+	int port = 43;
+	const char *host = "whois-servers.net";
+
+	opt_complementary = "-1:p+";
+	getopt32(argv, "h:p:", &host, &port);
+
+	argv += optind;
+	do {
+		int fd = create_and_connect_stream_or_die(host, port);
+		fdprintf(fd, "%s\r\n", *argv);
+		pipe_out(fd);
+	}
+	while (*++argv);
+
+	return EXIT_SUCCESS;
+}
-- 
1.7.3.4



More information about the busybox-cvs mailing list