[PATCH] whois, new applet

walter harms wharms at bfs.de
Mon Feb 28 13:22:08 UTC 2011



Am 27.02.2011 23:40, schrieb Denys Vlasenko:
> On Tuesday 22 February 2011 14:51, gotrunks at gmail.com wrote:
>> Slightly updated version of the patch attached.
> 
> How about simpler version?
> 
> 
> static void pipe_out(int fd)
> {
>         FILE *fp;
>         char buf[1024];
> 
>         fp = xfdopen_for_read(fd);
>         while (fgets(buf, sizeof(buf), fp)) {
>                 char *p = strpbrk(buf, "\r\n");
>                 if (p)
>                         *p = '\0';
>                 puts(buf);
>         }
> 
>         fclose(fp); /* closes fd too */
> }
> 

perhaps we can use xmalloc_fgetline() here ?
that would avoid having a fixed buffer.

re,
 wh

> 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";
> 
>         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);
>         }
>         while (*++argv);
> 
>         return EXIT_SUCCESS;
> }
> 


More information about the busybox mailing list