aboutsummaryrefslogtreecommitdiff
path: root/networking/whois.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-07-06 17:16:27 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-07-06 17:16:27 +0200
commit0844b5afe2cd60d46b7f2ad0fac8c2818d0780b3 (patch)
tree12b43f35838bc8716cc8c2b4d925aa8d60e9fdb1 /networking/whois.c
parent1035c92e2d1c017eab7cb10badb7e3b407aeba2d (diff)
downloadbusybox-0844b5afe2cd60d46b7f2ad0fac8c2818d0780b3.tar.gz
whois: implement -i
function old new delta whois_main 654 675 +21 packed_usage 30355 30356 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/whois.c')
-rw-r--r--networking/whois.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/networking/whois.c b/networking/whois.c
index 5ef83672d..6ba8dfd20 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -21,13 +21,18 @@
//kbuild:lib-$(CONFIG_WHOIS) += whois.o
//usage:#define whois_trivial_usage
-//usage: "[-h SERVER] [-p PORT] NAME..."
+//usage: "[-i] [-h SERVER] [-p PORT] NAME..."
//usage:#define whois_full_usage "\n\n"
//usage: "Query WHOIS info about NAME\n"
+//usage: "\n -i Show redirect results too"
//usage: "\n -h,-p Server to query"
#include "libbb.h"
+enum {
+ OPT_i = (1 << 0),
+};
+
static char *query(const char *host, int port, const char *domain)
{
int fd;
@@ -53,6 +58,7 @@ static char *query(const char *host, int port, const char *domain)
buf = xrealloc(buf, bufpos + len + 1);
memcpy(buf + bufpos, linebuf, len);
bufpos += len;
+ buf[bufpos] = '\0';
if (!redir || !success) {
trim(linebuf);
@@ -73,7 +79,7 @@ static char *query(const char *host, int port, const char *domain)
fclose(fp); /* closes fd too */
if (!success && !pfx[0]) {
/*
- * Looking at jwhois.conf, some whois servers use
+ * Looking at /etc/jwhois.conf, some whois servers use
* "domain = DOMAIN", "DOMAIN ID <DOMAIN>"
* and "domain=DOMAIN_WITHOUT_LAST_COMPONENT"
* formats, but those are rare.
@@ -91,11 +97,9 @@ static char *query(const char *host, int port, const char *domain)
free(redir);
redir = NULL;
}
- if (!redir) {
+ if (!redir || (option_mask32 & OPT_i)) {
/* Output saved text */
- printf("[%s]\n", host);
- buf[bufpos] = '\0';
- fputs(buf, stdout);
+ printf("[%s]\n%s", host, buf ? buf : "");
}
free(buf);
return redir;
@@ -164,7 +168,7 @@ int whois_main(int argc UNUSED_PARAM, char **argv)
const char *host = "whois.iana.org";
opt_complementary = "-1:p+";
- getopt32(argv, "h:p:", &host, &port);
+ getopt32(argv, "ih:p:", &host, &port);
argv += optind;
do {