~ubuntu-branches/ubuntu/utopic/busybox/utopic

« back to all changes in this revision

Viewing changes to networking/whois.c

  • Committer: Package Import Robot
  • Author(s): Steve Langasek
  • Date: 2012-05-01 03:35:20 UTC
  • mfrom: (2.1.29 sid)
  • Revision ID: package-import@ubuntu.com-20120501033520-3nb8wjf4bp524txp
Tags: 1:1.19.3-7ubuntu1
* Merge from Debian unstable, remaining changes:
  - [udeb] Enable chvt, killall, losetup, NFS mount, od, ping, ping6, and
    stat.
  - [deb, static] Enable CGI support for httpd.
  - Enable 'mount -f' and mount helpers for all targets.
  - Add busybox-initramfs.
  - test-bin.patch: Move test and friends to /bin.
  - static-sh-alias.patch: Add static-sh alias name for ash, and install
    /bin/static-sh symlink to busybox in busybox-static.
  - debian/patches/fix-64-bit-permissions.patch: mkdir: fix permissions
    on 64-bit platforms.  Taken from upstream.
  - Filter out -Werror=format-security from CFLAGS passed by
    dpkg-buildpackage, at least for now.
* Dropped changes, included in Debian:
  - [deb] Enable mdev.
  - Add cross-compiling support.
* Disable NFS mount in the static build; needs a newer upstream version of
  busybox for compatibility with glibc 2.15.
* Set V=1 in debian/rules, to get more meaningful build logs.
* Export the dpkg-buildflags to the environment, so we pick up hardening
  now that dpkg doesn't export them for us.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vi: set sw=4 ts=4: */
 
2
/*
 
3
 * whois - tiny client for the whois directory service
 
4
 *
 
5
 * Copyright (c) 2011 Pere Orga <gotrunks@gmail.com>
 
6
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 
7
 */
 
8
/* TODO
 
9
 * Add ipv6 support
 
10
 * Add proxy support
 
11
 */
 
12
 
 
13
//config:config WHOIS
 
14
//config:       bool "whois"
 
15
//config:       default y
 
16
//config:       help
 
17
//config:         whois is a client for the whois directory service
 
18
 
 
19
//applet:IF_WHOIS(APPLET(whois, BB_DIR_USR_BIN, BB_SUID_DROP))
 
20
 
 
21
//kbuild:lib-$(CONFIG_WHOIS) += whois.o
 
22
 
 
23
//usage:#define whois_trivial_usage
 
24
//usage:       "[-h SERVER] [-p PORT] NAME..."
 
25
//usage:#define whois_full_usage "\n\n"
 
26
//usage:       "Query WHOIS info about NAME\n"
 
27
//usage:     "\n        -h,-p   Server to query"
 
28
 
 
29
#include "libbb.h"
 
30
 
 
31
static 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); /* closes fd too */
 
45
}
 
46
 
 
47
int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 
48
int 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
}