home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / MINITEL / MINITEL.C
C/C++ Source or Header  |  1991-06-27  |  5KB  |  184 lines

  1. /*
  2. *    MINITEL.C
  3. *
  4. *   Example TCP/IP program for the NCSA TCP/IP kernel
  5. *
  6. ***************************************************************************
  7. *                                                                         *
  8. *     part of:                                                            *
  9. *     TCP/IP kernel for NCSA Telnet                                       *
  10. *     by Tim Krauskopf                                                    *
  11. *                                                                         *
  12. *     National Center for Supercomputing Applications                     *
  13. *     152 Computing Applications Building                                 *
  14. *     605 E. Springfield Ave.                                             *
  15. *     Champaign, IL  61820                                                *
  16. *                                                                         *
  17. ***************************************************************************
  18. *
  19. *    Revision history:
  20. *
  21. *    10/87  Initial source release, Tim Krauskopf
  22. *    2/88  typedefs of integer lengths, TK
  23. *    5/88    clean up for 2.3 release, JKM    
  24. *
  25. */
  26.  
  27. #define MINITEL
  28. /*
  29. *    Includes
  30. */
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <conio.h>
  35. #ifdef MEMORY_DEBUG
  36. #include "memdebug.h"
  37. #endif
  38. #ifdef __TURBOC__
  39. #include "turboc.h"
  40. #endif
  41. #include "whatami.h"
  42. #include "hostform.h"
  43. #include "externs.h"
  44.  
  45. /*
  46. *    Global variables
  47. */
  48. int    bypass_passwd=0;        /* whether to bypass the password check, not used */
  49. unsigned char path_name[_MAX_DRIVE+_MAX_DIR],    /* character storage for the path name */
  50.     temp_str[100],temp_data[100];        /* temporary character storage */
  51. struct machinfo *mp;
  52. char buf[256];
  53. char *config;
  54.  
  55. /*
  56. *    main ( argc, argv )
  57. *
  58. *    Entry : 
  59. *
  60. *        parameter 1 : machine name
  61. *
  62. */
  63.  
  64. void main(argc,argv)
  65. int argc;
  66. char *argv[];
  67. {
  68.     int i,cnt,ev,pnum,what,dat;
  69.     char *errmsg;
  70.     char c;
  71.  
  72. #ifdef __TURBOC__
  73.     fnsplit(argv[0],path_name,buf,temp_str,temp_data);
  74. #else
  75.     _splitpath(argv[0],path_name,buf,temp_str,temp_data);   /* split the full path name of telbin.exe into it's components */
  76. #endif
  77.     strcat(path_name,buf);    /* append the real path name to the drive specifier */
  78.  
  79.     config = (getenv("CONFIG.TEL"));
  80.     if (config) Shostfile(config);
  81.  
  82.     puts("National Center for Supercomputing Applications");
  83.     puts("Mini-telnet example program");
  84.     puts("January 1989\n");
  85.     if(argc<2)
  86.         exit(1);
  87.     if(Snetinit()) {            /* call session initialization */
  88.         errhandle();            /* Snetinit() reads config.tel file */
  89.         exit(1);
  90.       }
  91.     mp=Sgethost(argv[1]);        /* look up in hosts cache */
  92.     if(!mp)
  93.         Sdomain(argv[1]);        /* not in hosts, try domain */
  94.     else {
  95.         if(0>(pnum=Snetopen(mp,23))) {
  96.             errhandle();
  97.             netshut();
  98.             exit(1);
  99.           }
  100.       }
  101.     c = 0;
  102.     do {
  103.         if(kbhit()){                /* has key been pressed */
  104.             c=(char)getch();
  105.             netwrite(pnum,&c,1);    /* user input sent on connection */
  106.           }
  107. /*
  108. *  get event from network, these two classes return all of the events
  109. *  of user interest.
  110. */
  111.         ev=Sgetevent(USERCLASS | CONCLASS | ERRCLASS,&what,&dat);
  112.         if(!ev)
  113.             continue;
  114.         if(what==ERRCLASS) {                /* error event */
  115.             errmsg=neterrstring(dat);
  116.             puts(errmsg);
  117.           }
  118.         else 
  119.             if(what==CONCLASS) {        /* event of user interest */
  120.                 switch (ev) {
  121.                     case CONOPEN:                /* connection opened or closed */
  122.                         netpush(dat);            /* negotiation */
  123.                         netwrite(dat,"\377\375\001\377\375\003\377\374\030",9);
  124.                         break;
  125.  
  126.                     default:
  127.                         break;
  128.  
  129.                     case CONDATA:                /* data arrived for me */
  130.                         cnt=netread(dat,buf,80);
  131.                         for(i=0; i<cnt; i++) 
  132.                         if(buf[i]<128)
  133.                             putchar(buf[i]);
  134.                         break;
  135.  
  136.                     case CONFAIL:
  137.                         puts("Connection attempt failed");
  138.                                         /* drop through to exit */
  139.  
  140.                     case CONCLOSE:
  141.                         netshut();
  142.                         exit(1);
  143.                   }
  144.               }
  145.             else 
  146.                 if(what==USERCLASS) {
  147.                     switch (ev) {
  148.                         case DOMOK:                            /* domain worked */
  149.                             mp=Slooknum(dat);                /* get machine info */
  150.                             pnum=Snetopen(mp,23);            /* open to host name */
  151.                             break;
  152.  
  153.                         case DOMFAIL:    /* domain failed */
  154.                             n_puts("domain failed");
  155.                             netshut();
  156.                             exit(1);
  157.                             default:
  158.  
  159.                         break;
  160.                       }
  161.                   }
  162.       }while(c!=16);            /* Ctrl-P, arbitrary escape */
  163.     netclose(pnum);
  164.     netshut();
  165.     exit(0);
  166. }
  167.  
  168. /*
  169. *    errhandle ()
  170. *
  171. *    Write error messages to the console window
  172. *
  173. */
  174. void errhandle(void )
  175. {
  176.     char *errmsg;
  177.     int i,j;
  178.  
  179.     while(ERR1==Sgetevent(ERRCLASS,&i,&j)) {
  180.         errmsg=neterrstring(j);
  181.         puts(errmsg);
  182.       }
  183. }
  184.