home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / FINGER.C < prev    next >
C/C++ Source or Header  |  1992-01-13  |  2KB  |  108 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.     while ( 1 ) {
  61.     sock_wait_input( s, 30, NULL, &status );
  62.     len = sock_fastread( s, buffer, 512 );
  63.     buffer[ len ] = 0;
  64.     printf( "%s", buffer );
  65.     }
  66.  
  67. sock_err:
  68.     switch (status) {
  69.     case 1 : /* foreign host closed */
  70.          break;
  71.     case -1: /* timeout */
  72.                  printf("ERROR: %s\n", sockerr(s));
  73.          break;
  74.     }
  75.     printf("\n");
  76. }
  77.  
  78.  
  79. main(int argc, char **argv )
  80. {
  81.     char *user,*server;
  82.     longword host;
  83.     int status;
  84.  
  85.     sock_init();
  86.  
  87.     /* process args */
  88.     do {
  89.     if (argc == 2) {
  90.         user = argv[1];
  91.         if (server = strchr( user, '@'))
  92.         break;
  93.     }
  94.     puts("   FINGER  [userid]@server");
  95.     exit( 3 );
  96.     } while ( 0 );
  97.  
  98.     *server ++ = 0;
  99.  
  100.     if (host = resolve( server )) {
  101.     status = finger( user, host, server);
  102.     } else {
  103.     printf("Could not resolve host '%s'\n", server );
  104.     exit( 3 );
  105.     }
  106.     exit( status );
  107. }
  108.