home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / CEREBRUM / WAT9609.ZIP / APPS / FINGER.C < prev    next >
Text File  |  1994-11-28  |  3KB  |  112 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 <stdlib.h>
  26. #include <string.h>
  27. #include <tcp.h>
  28.  
  29. #define FINGER_PORT 79
  30.  
  31. tcp_Socket fingersock;
  32. char buffer[ 513 ];
  33.  
  34. int finger(char *userid, longword host, char *hoststring)
  35. {
  36.     tcp_Socket *s;
  37.     int status;
  38.     int len;
  39.  
  40.  
  41.     s = &fingersock;
  42.     if (!tcp_open( s, 0, host, FINGER_PORT, NULL )) {
  43.     puts("Sorry, unable to connect to that machine right now!");
  44.     return (1);
  45.     }
  46.  
  47.     printf("waiting...\r");
  48.     sock_wait_established(s, sock_delay, NULL, &status);
  49.  
  50.     if (*userid)
  51.     printf("'%s' is looking for '%s'...\n\n\n", hoststring, userid);
  52.  
  53.     strcpy( buffer, userid );
  54.     rip( buffer );            /* kill all \n and \r's */
  55.     strcat( buffer , "\r\n");
  56.  
  57.     sock_puts( s, buffer );
  58.  
  59.     sock_close( s );                    /* close sending side.... */
  60.  
  61.     while ( 1 ) {
  62.     sock_wait_input( s, 30, NULL, &status );
  63.     len = sock_fastread( s, buffer, 512 );
  64.     buffer[ len ] = 0;
  65.     printf( "%s", buffer );
  66.     }
  67.  
  68. sock_err:
  69.     switch (status) {
  70.     case 1 : /* foreign host closed */
  71.                  printf("\n");
  72.                  exit(2);
  73.     case -1: /* timeout */
  74.                  printf("ERROR: %s\n\n", sockerr(s));
  75.          exit(3);
  76.     }
  77.     printf("\n");
  78.     return (0);  /* not reached */
  79. }
  80.  
  81. int main(int argc, char **argv )
  82. {
  83.     char *user,*server;
  84.     longword host;
  85.     int status;
  86.  
  87.     dbug_init();
  88.     sock_init();
  89.  
  90.     /* process args */
  91.     do {
  92.     if (argc == 2) {
  93.         user = argv[1];
  94.         if ( (server = strchr( user, '@')) != NULL )
  95.         break;
  96.     }
  97.     puts("   FINGER  [userid]@server");
  98.     exit( 3 );
  99.     } while ( 0 );
  100.  
  101.     *server ++ = 0;
  102.  
  103.     if ( (host = resolve( server )) != 0uL ) {
  104.     status = finger( user, host, server);
  105.     } else {
  106.     printf("Could not resolve host '%s'\n", server );
  107.     exit( 3 );
  108.     }
  109.     exit( status );
  110.     return (0);  /* not reached */
  111. }
  112.