ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

void netfinger ( char name)

Definition at line 40 of file net.c.

Referenced by userlist().

{
    extern int lflag;
    char c, lastc;
    struct in_addr defaddr;
    struct hostent *hp, def;
    struct servent *sp;
    struct sockaddr_in sin;
    SOCKET s;
    char *alist[1], *host;

    /* If this is a local request */
    if (!(host = rindex(name, '@')))
        return;

    *host++ = '\0';
    if (isdigit(*host) && (defaddr.s_addr = inet_addr(host)) != (unsigned long)-1) {
        def.h_name = host;
        def.h_addr_list = alist;
        def.h_addr = (char *)&defaddr;
        def.h_length = sizeof(struct in_addr);
        def.h_addrtype = AF_INET;
        def.h_aliases = 0;
        hp = &def;
    } else if (!(hp = gethostbyname(host))) {
        (void)fprintf(stderr,
            "finger: unknown host: %s\n", host);
        return;
    }
    if (!(sp = getservbyname("finger", "tcp"))) {
        (void)fprintf(stderr, "finger: tcp/finger: unknown service\n");
        return;
    }
    sin.sin_family = hp->h_addrtype;
    bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
    sin.sin_port = sp->s_port;
    if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) == INVALID_SOCKET) {
        perror("finger: socket");
        return;
    }

    /* have network connection; identify the host connected with */
    (void)printf("[%s]\n", hp->h_name);
    if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        fprintf(stderr, "finger: connect rc = %d", WSAGetLastError());
        (void)closesocket(s);
        return;
    }

    /* -l flag for remote fingerd  */
    if (lflag)
        send(s, "/W ", 3, 0);
    /* send the name followed by <CR><LF> */
    send(s, name, strlen(name), 0);
    send(s, "\r\n", 2, 0);

    /*
     * Read from the remote system; once we're connected, we assume some
     * data.  If none arrives, we hang until the user interrupts.
     *
     * If we see a <CR> or a <CR> with the high bit set, treat it as
     * a newline; if followed by a newline character, only output one
     * newline.
     *
     * Otherwise, all high bits are stripped; if it isn't printable and
     * it isn't a space, we can simply set the 7th bit.  Every ASCII
     * character with bit 7 set is printable.
     */
    lastc = 0;
    while (recv(s, &c, 1, 0) == 1) {
        c &= 0x7f;
        if (c == 0x0d) {
            if (lastc == '\r')  /* ^M^M - skip dupes */
                continue;
            c = '\n';
            lastc = '\r';
        } else {
            if (!isprint(c) && !isspace(c))
                c |= 0x40;
            if (lastc != '\r' || c != '\n')
                lastc = c;
            else {
                lastc = '\n';
                continue;
            }
        }
        putchar(c);
    }
    if (lastc != '\n')
        putchar('\n');
    putchar('\n');
}

Generated on Sun May 27 2012 04:42:33 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.