aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPere Orga <gotrunks@gmail.com>2011-02-27 23:38:52 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-27 23:38:52 +0100
commit251962f20737c5138c7d33e90c68dfca856361e1 (patch)
tree1399a95fd99732366c2544baf05307cb8166ab40
parent9beb68e3e2dc1c6f457acfb307cfed73cce65cd9 (diff)
downloadbusybox-w32-251962f20737c5138c7d33e90c68dfca856361e1.tar.gz
busybox-w32-251962f20737c5138c7d33e90c68dfca856361e1.tar.bz2
busybox-w32-251962f20737c5138c7d33e90c68dfca856361e1.zip
whois: new applet
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@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/whois.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/networking/whois.c b/networking/whois.c
new file mode 100644
index 000000000..4eab9e5fe
--- /dev/null
+++ b/networking/whois.c
@@ -0,0 +1,66 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * whois - tiny client for the whois directory service
4 *
5 * Copyright (c) 2011 Pere Orga <gotrunks@gmail.com>
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 */
8/* TODO
9 * Add ipv6 support
10 * Add proxy support
11 */
12
13//config:config WHOIS
14//config: bool "whois"
15//config: default y
16//config: help
17//config: whois is a client for the whois directory service
18
19//applet:IF_WHOIS(APPLET(whois, BB_DIR_USR_BIN, BB_SUID_DROP))
20
21//kbuild:lib-$(CONFIG_WHOIS) += whois.o
22
23//usage:#define whois_trivial_usage
24//usage: "[-h SERVER] [-p PORT] NAME..."
25//usage:#define whois_full_usage "\n\n"
26//usage: "Query WHOIS info about NAME\n"
27//usage: "\nOptions:"
28//usage: "\n -h,-p Server to query"
29
30#include "libbb.h"
31
32static void pipe_out(int fd)
33{
34 FILE *fp;
35 char buf[1024];
36
37 fp = xfdopen_for_read(fd);
38 while (fgets(buf, sizeof(buf), fp)) {
39 char *p = strpbrk(buf, "\r\n");
40 if (p)
41 *p = '\0';
42 puts(buf);
43 }
44
45 fclose(fp); /* closes fd too */
46}
47
48int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
49int whois_main(int argc UNUSED_PARAM, char **argv)
50{
51 int port = 43;
52 const char *host = "whois-servers.net";
53
54 opt_complementary = "-1:p+";
55 getopt32(argv, "h:p:", &host, &port);
56
57 argv += optind;
58 do {
59 int fd = create_and_connect_stream_or_die(host, port);
60 fdprintf(fd, "%s\r\n", *argv);
61 pipe_out(fd);
62 }
63 while (*++argv);
64
65 return EXIT_SUCCESS;
66}