home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / apps / finger.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  2.5 KB  |  110 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     FINGER - display user/system information
  5.  
  6.     Copyright (C) 1991, University of Waterloo
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it, but you may not sell it.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but without any warranty; without even the implied warranty of
  13.     merchantability or fitness for a particular purpose.
  14.  
  15.         Erick Engelke                   or via E-Mail
  16.         Faculty of Engineering
  17.         University of Waterloo          Erick@development.watstar.uwaterloo.ca
  18.         200 University Ave.,
  19.         Waterloo, Ont., Canada
  20.         N2L 3G1
  21.  
  22. ******************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <tcp.h>
  27.  
  28. #define FINGER_PORT 79
  29.  
  30. tcp_Socket fingersock;
  31. char buffer[ 513 ];
  32.  
  33. finger(userid, host, hoststring)
  34. char *userid, *hoststring;
  35. longword host;
  36. {
  37.     tcp_Socket *s;
  38.     int status;
  39.     int len;
  40.  
  41.  
  42.     s = &fingersock;
  43.     if (!tcp_open( s, 0, host, FINGER_PORT, NULL )) {
  44.     puts("Sorry, unable to connect to that machine right now!");
  45.     return;
  46.     }
  47.  
  48.     printf("waiting...\r");
  49.     sock_wait_established(s, sock_delay, NULL, &status);
  50.  
  51.     if (*userid)
  52.     printf("'%s' is looking for '%s'...\n\n\n", hoststring, userid);
  53.  
  54.     strcpy( buffer, userid );
  55.     rip( buffer );            /* kill all \n and \r's */
  56.     strcat( buffer , "\r\n");
  57.  
  58.     sock_puts( s, buffer );
  59.  
  60.     sock_close( s );                    /* close sending side.... */
  61.  
  62.     while ( 1 ) {
  63.     sock_wait_input( s, 30, NULL, &status );
  64.     len = sock_fastread( s, buffer, 512 );
  65.     buffer[ len ] = 0;
  66.     printf( "%s", buffer );
  67.     }
  68.  
  69. sock_err:
  70.     switch (status) {
  71.     case 1 : /* foreign host closed */
  72.          break;
  73.     case -1: /* timeout */
  74.                  printf("ERROR: %s\n", sockerr(s));
  75.          break;
  76.     }
  77.     printf("\n");
  78. }
  79.  
  80.  
  81. main(int argc, char **argv )
  82. {
  83.     char *user,*server;
  84.     longword host;
  85.     int status;
  86.     dbug_init();
  87.     sock_init();
  88.  
  89.     /* process args */
  90.     do {
  91.     if (argc == 2) {
  92.         user = argv[1];
  93.         if (server = strchr( user, '@'))
  94.         break;
  95.     }
  96.     puts("   FINGER  [userid]@server");
  97.     exit( 3 );
  98.     } while ( 0 );
  99.  
  100.     *server ++ = 0;
  101.  
  102.     if (host = resolve( server )) {
  103.     status = finger( user, host, server);
  104.     } else {
  105.     printf("Could not resolve host '%s'\n", server );
  106.     exit( 3 );
  107.     }
  108.     exit( status );
  109. }
  110.