home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rxtelnet.zip / nvt / tnvt.c < prev    next >
C/C++ Source or Header  |  1997-08-15  |  2KB  |  110 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "nvt.h"
  6.  
  7. HNVT hnvt;
  8. int  inuse = 0;
  9.  
  10.  
  11. void input(void)
  12. {
  13.   int   count;
  14.   char  buf[MAXLINESIZE];
  15.   int   bufsize;
  16.  
  17.   puts( "\n stdin ready" );
  18.  
  19.   while ( inuse )
  20.   {
  21.     gets( buf );
  22.     bufsize = strlen( buf );
  23.  
  24.     buf[bufsize+1] = '\0';
  25.  
  26.     count = nvtputs( hnvt, buf, bufsize );
  27.  
  28.     if ( count != bufsize )
  29.       puts( "\n nvtputs error" );
  30.   }
  31. }
  32.  
  33. void output(void)
  34. {
  35.   int   count;
  36.   char  buf[MAXLINESIZE];
  37.  
  38.   puts( "\n stdout ready" );
  39.  
  40.   while ( inuse )
  41.   {
  42.     count = nvtgets( hnvt, buf, sizeof(buf) - 1 );
  43.  
  44.     if ( !count )
  45.       break;
  46.     else
  47.     {
  48.       if ( count < 0 )
  49.         puts( "\n nvtgets error" );
  50.       else
  51.       {
  52.         buf[count] = '\0';
  53.         puts( buf );
  54.       }
  55.     }
  56.   }
  57. }
  58.  
  59. void task( void *parm )
  60. {
  61.   input();
  62.   _endthread();
  63. }
  64.  
  65. int main( int argc, char *argv[] )
  66. {
  67.   char *host;
  68.   int   port;
  69.   int   tid;
  70.  
  71.   if ( argc < 2 || argc > 3 )
  72.   {
  73.     puts( "syntax:   TNVT  hostname  [ port ]" );
  74.     return 1;
  75.   }
  76.  
  77.   host = argv[1];
  78.   port = 0;
  79.  
  80.   if ( argc > 2 )
  81.   {
  82.     port = atoi( argv[2] );
  83.  
  84.     if ( !port )
  85.       printf( "port parameter '%s' ignored \n", argv[2] );
  86.   }
  87.  
  88.   hnvt = nvtopen( host, port );
  89.  
  90.   if ( !hnvt )
  91.     puts( "\n nvtopen failed" );
  92.   else
  93.   {
  94.     inuse = 1;
  95.     tid = _beginthread( task, 0, 16*1024, 0 );
  96.  
  97.     if ( !tid )
  98.       puts( "\n unable to start subtask" );
  99.     else
  100.       output();
  101.  
  102.     inuse = 0;
  103.  
  104.     nvtclose( hnvt );
  105.   }
  106.  
  107.   puts( "\n ending" );
  108.   return 0;
  109. }
  110.