1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include "libbb.h"
30
31static void pipe_out(int fd)
32{
33 FILE *fp;
34 char buf[1024];
35
36 fp = xfdopen_for_read(fd);
37 while (fgets(buf, sizeof(buf), fp)) {
38 char *p = strpbrk(buf, "\r\n");
39 if (p)
40 *p = '\0';
41 puts(buf);
42 }
43
44 fclose(fp);
45}
46
47int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
48int whois_main(int argc UNUSED_PARAM, char **argv)
49{
50 int port = 43;
51 const char *host = "whois-servers.net";
52
53 opt_complementary = "-1:p+";
54 getopt32(argv, "h:p:", &host, &port);
55
56 argv += optind;
57 do {
58 int fd = create_and_connect_stream_or_die(host, port);
59 fdprintf(fd, "%s\r\n", *argv);
60 pipe_out(fd);
61 }
62 while (*++argv);
63
64 return EXIT_SUCCESS;
65}
66