[PATCH] Bug 9076 - Whois using a non working host for queries by default
Vito Mulè
mule.vito at gmail.com
Mon Jul 4 19:47:02 UTC 2016
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;
}
On 4 July 2016 at 17:24, Vito Mulè <mule.vito at gmail.com> wrote:
> Patch attached in the bug:
> https://bugs.busybox.net/show_bug.cgi?id=9076
>
> Signed-off-by: vmule <mulevito at gmail.com>
>
> diff --git a/networking/whois.c b/networking/whois.c
> index bf33033..5a3dc51 100644
> --- a/networking/whois.c
> +++ b/networking/whois.c
> @@ -48,7 +48,7 @@ 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";
> + const char *host = "whois.nic.it.";
>
> opt_complementary = "-1:p+";
> getopt32(argv, "h:p:", &host, &port);
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20160704/f90eba05/attachment-0001.html>
More information about the busybox
mailing list