[Bug 9076] Whois using a non working host for queries by default
bugzilla at busybox.net
bugzilla at busybox.net
Mon Jul 4 19:45:36 UTC 2016
https://bugs.busybox.net/show_bug.cgi?id=9076
--- Comment #3 from Vito Mule <mulevito at gmail.com> ---
fixed typos, stopped using strcpy, added a separate function to create the name
for the whois server and also supporting, as it was before, more than one query
at the time.
Signed-off-by: vmule <mulevito at gmail.com>
diff --git a/networking/whois.c b/networking/whois.c
index bf33033..908a032 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -44,22 +44,56 @@ static void pipe_out(int fd)
fclose(fp); /* closes fd too */
}
+void whois_host(char* host, char *argv_host, const char *unqualified_host)
+{
+ char domain[49];
+ char* token;
+ size_t query_len = strlen(argv_host);
+ char *str_token = malloc(query_len+1 * sizeof(char));
+
+ if (strlen(host) >= 1) {
+ memset(&host[0], 0, strlen(host));
+ }
+
+ strncpy(str_token, argv_host, query_len+1);
+
+ token = strtok(str_token, ".");
+ while (token != NULL) {
+ strncpy(domain, token, strlen(token)+1);
+ token = strtok(NULL, ".");
+ }
+ strncpy(host, domain, strlen(domain));
+ strncat(host, unqualified_host, 19);
+}
+
int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int whois_main(int argc UNUSED_PARAM, char **argv)
{
+
+ char *host = malloc(67 * sizeof(char));
int port = 43;
- const char *host = "whois-servers.net";
+ const char *unqualified_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);
+
+ if (strlen(host) < 1) {
+ do {
+ whois_host(host, *argv, unqualified_host);
+ int fd = create_and_connect_stream_or_die(host, port);
+ fdprintf(fd, "%s\r\n", *argv);
+ pipe_out(fd);
+ }
+ while (*++argv);
+ } else {
+ do {
+ int fd = create_and_connect_stream_or_die(host, port);
+ fdprintf(fd, "%s\r\n", *argv);
+ pipe_out(fd);
+ }
+ while (*++argv);
}
- while (*++argv);
return EXIT_SUCCESS;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the busybox-cvs
mailing list