home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / MSWATTCP.ZIP / APPS / FINGER.C next >
Encoding:
C/C++ Source or Header  |  1993-07-16  |  3.1 KB  |  136 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. void finger(char *userid, longword host, char *hoststring)
  34. {
  35.     tcp_Socket *s;
  36.     int status;
  37.     int len;
  38.  
  39.  
  40.     s = &fingersock;
  41.     if (!tcp_open( s, 0, host, FINGER_PORT, NULL )) {
  42.     puts("Sorry, unable to connect to that machine right now!");
  43.     return;
  44.     }
  45.  
  46.     printf("waiting...\r");
  47.     sock_wait_established( (sock_type *)s, sock_delay, NULL, &status );
  48.  
  49.     if (*userid)
  50.     printf("'%s' is looking for '%s'...\n\n\n", hoststring, userid);
  51.  
  52.     strcpy( buffer, userid );
  53.     rip( buffer );                      /* kill all \n and \r's */
  54.     strcat( buffer , "\r\n");
  55.  
  56.     sock_puts( (sock_type *)s, (byte *)buffer );
  57.  
  58.     while ( 1 ) {
  59.     sock_wait_input( (sock_type *)s, 30, NULL, &status );
  60.     len = sock_fastread( (sock_type *)s, buffer, 512 );
  61.     buffer[ len ] = 0;
  62.     printf( "%s", buffer );
  63.     }
  64.  
  65. sock_err:
  66.     switch (status) {
  67.     case 1 : /* foreign host closed */
  68.          break;
  69.     case -1: /* timeout */
  70.          printf("ERROR: %s\n", sockerr(s));
  71.          break;
  72.     case 2 : /* CLOSWT and no more data */
  73.          sock_close( (sock_type *)s );
  74.          /* printf("Closing case status 2\n"); */
  75.          break;
  76.     }
  77.     printf("\n");
  78. }
  79.  
  80. void help(void) {
  81.     puts("   FINGER  [-d|/d] [userid]@server");
  82.     exit(3);
  83.     }
  84.  
  85. void main(int argc, char **argv )
  86. {
  87.     char *user, *server, buf[30];
  88.     longword host;
  89.     int i, status;
  90.  
  91.  /*   dbuginit();*/
  92.     sock_init();
  93.  
  94.     /* process args */
  95.     if ( argc < 2 ) 
  96.     help();
  97.  
  98.     for ( i = 1; i < argc ; i++ ) {
  99.     if ( !strcmp( argv[i], "-d") || !strcmp( argv[i], "/d") ) {
  100.         if ( argc == 2 ) 
  101.             help();
  102.         puts("Debug is on");
  103.         tcp_set_debug_state( 1 );
  104.         }
  105.     else {                
  106.         user = argv[i];
  107.         if (server = strchr( user, '@'))
  108.         break;
  109.         else 
  110.         help(); 
  111.         }
  112.        }
  113.     
  114.   /*  do {
  115.     if (argc == 2) {
  116.         user = argv[1];
  117.         if (server = strchr( user, '@'))
  118.         break;
  119.     }
  120.     puts("   FINGER  [userid]@server");
  121.     exit( 3 );
  122.     } while ( 0 ); */
  123.  
  124.     *server ++ = 0;
  125.  
  126.     if (host = resolve( server )) {
  127.     if (!debug_on) 
  128.         printf("\nResolved %s = %s \n\n",server,w_inet_ntoa(buf,host));
  129.     status = finger( user, host, server);
  130.     } else {
  131.     printf("Could not resolve host '%s'\n", server );
  132.     exit( 3 );
  133.     }
  134.     exit( status );
  135. }
  136.