Created attachment 6501 [details] patch to use a working whois default server The query hangs trying to use thi host by default: whois-servers.net (204.74.78.75) >> recvfrom(3, "\254g\201\200\0\1\0\1\0\0\0\0\rwhois-servers\3net\0\0"..., >> 1024, 0, {sa_family=AF_INET, sin_port=htons(53), >> sin_addr=inet_addr("8.8.8.8")}, [16]) = 51 >> close(3) = 0 >> socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 >> setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 >> connect(3, {sa_family=AF_INET, sin_port=htons(43), >> sin_addr=inet_addr("204.74.78.75")}, 16 vmule@agent4:~/busybox$ git diff 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);
Disregard my previous patch, this should work better. I added some logic to use $domain.whois-servers.net as server based on the query's domain. diff --git a/networking/whois.c b/networking/whois.c index bf33033..9a73bbc 100644 --- a/networking/whois.c +++ b/networking/whois.c @@ -47,13 +47,32 @@ static void pipe_out(int fd) 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)); + char domain[49]; + char* token; + 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; + + if (strlen(host) < 1) { + size_t query_len = strlen(*argv); + char *str_token = malloc(query_len * sizeof(char)); + strncpy(str_token, *argv, query_len); + + token = strtok(str_token, "."); + while (token != NULL) { + strcpy(domain, token); + token = strtok(NULL, "."); + } + strncpy(host, domain, strlen(domain)); + strncat(host, unqualified_host, 18); + } + do { int fd = create_and_connect_stream_or_die(host, port); fdprintf(fd, "%s\r\n", *argv);
Created attachment 6506 [details] patch V2 to use a working whois default server
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@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; }
Created attachment 6511 [details] patch V3 to use a working whois default server
Created attachment 6516 [details] whois_fix_default_server_V4 Final Patch: Dealing with names that are too long, respecting the length used by original whois, to avoid segfaults.
Created attachment 6521 [details] whois_fix_default_server_V5 removed sizeof(char) and shorter code using strdup. Thanks
Created attachment 6526 [details] whois_fix_default_server_V6 minor fixes, added comment for func whois_host()
Created attachment 6531 [details] whois_fix_default_server_V7 added bloat-o-meter output and name to the initial comments
Created attachment 6536 [details] whois_fix_default_server_V8 Now whois server hostname is requested to "whois.iana.org" querying the tld. This will improve toll resilience.
Created attachment 6546 [details] whois_fix_default_server_V9 function old new delta whois_server - 225 +225 whois_main 133 242 +109 WHOIS_HOST - 15 +15 pipe_out 85 - -85 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/0 up/down: 349/-85) Total: 264 bytes
solved in https://git.busybox.net/busybox/commit/?id=1035c92e2d1c017eab7cb10badb7e3b407aeba2d