home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / mscwattc / apps / finger.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-21  |  2.4 KB  |  109 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.     dbuginit();
  86.     sock_init();
  87.  
  88.     /* process args */
  89.     do {
  90.     if (argc == 2) {
  91.         user = argv[1];
  92.         if (server = strchr( user, '@'))
  93.         break;
  94.     }
  95.     puts("   FINGER  [userid]@server");
  96.     exit( 3 );
  97.     } while ( 0 );
  98.  
  99.     *server ++ = 0;
  100.  
  101.     if (host = resolve( server )) {
  102.     status = finger( user, host, server);
  103.     } else {
  104.     printf("Could not resolve host '%s'\n", server );
  105.     exit( 3 );
  106.     }
  107.     exit( status );
  108. }
  109.