home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / cknnbi.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  23KB  |  920 lines

  1. char *cknnbiv = "Win32 NetBios support, 8.0.001, 6 Feb 97";
  2.  
  3. /*  C K N N B I  --  Win32-specific NetBios support  */
  4.  
  5. /*
  6.   COPYRIGHT NOTICE:
  7.  
  8.   Copyright (C) 1985, 2004, Trustees of Columbia University in the City of New
  9.   York.
  10. */
  11.  
  12. /*
  13.    developed by Jeffrey Altman <jaltman@secure-endpoints.com>
  14. */
  15.  
  16. #ifdef CK_NETBIOS
  17. #include <windows.h>
  18. #include "ckcdeb.h"
  19. #include "ckcker.h"
  20. #include "ckonbi.h"
  21.  
  22. #define No 0
  23. #define Yes 1
  24.  
  25. static USHORT Netbeui_Handle[NB_ADAPTERS]={0,0,0,0};
  26. static USHORT Netentries=0;
  27.  
  28. extern int pid ;
  29. extern int ttyfd ;
  30. extern USHORT netbiosAvail ;
  31. extern BOOL NetbeuiAPI = 0 ;
  32.  
  33. UCHAR  NetBiosRemote[NETBIOS_NAME_LEN+1] = "                \0" ;
  34. UCHAR  NetBiosName[NETBIOS_NAME_LEN+1] = "                \0" ;
  35. UCHAR  NetBiosAdapter = 0 ;
  36. BYTE   NetBiosLSN = 0 ;
  37. HANDLE hevNetBiosLSN = 0 ;
  38. PNCB   pWorkNCB = 0 ;
  39. PNCB   pListenNCB = 0 ;
  40. PNCB   pRecvNCB = 0 ;
  41. PNCB   pSendNCB[MAXWS] ;
  42. HANDLE ListenThreadID = -1 ;
  43. BYTE   NetBiosRecvBuf[MAXRP]="" ;
  44. BYTE * NetBiosSendBuf[MAXWS] ;
  45. USHORT MaxCmds=0,MaxSess=0,MaxNames=0,MaxWs=0 ;
  46.  
  47. USHORT
  48. NCBReset( BOOL Netbeui, PNCB Ncb, USHORT lana,USHORT  sessions,
  49.                   USHORT  commands,USHORT names )
  50. {
  51.     int i,rc=NB_INADEQUATE_RESOURCES,nrc=0;
  52.     if(!Netbeui)
  53.     {
  54.         memset( Ncb, 0, BNCBSIZE ) ;
  55.         Ncb->ncb_command  = NB_RESET_WAIT;
  56.         Ncb->ncb_lana_num = lana;
  57.         Ncb->req_sessions = sessions;
  58.         Ncb->req_commands = commands;
  59.         Ncb->req_names = names;
  60.  
  61.         nrc = Netbios(Ncb );
  62.  
  63.         rc=Ncb->ncb_retcode;
  64.     } /* end if */
  65.     return rc;
  66. }
  67.  
  68. USHORT
  69. NCBConfig(BOOL Netbeui, PNCB Ncb, USHORT lana, PUSHORT sessions,
  70.            PUSHORT commands, PUSHORT names )
  71. {
  72.     SHORT rc;
  73.  
  74.     *sessions=0;
  75.     *commands=0;
  76.     *names=   0;
  77.  
  78.     if(!Netbeui)
  79.     {
  80.         debug(F100,"ckonbi:NCBConfig: About to NCBReset","",0);
  81.         rc=NCBReset(Netbeui, Ncb, lana, 255, 255,255 );
  82.         debug(F111,"ckonbi: NCBConfig","NCBReset",rc);
  83.         if ( rc == NB_COMMAND_SUCCESSFUL ||
  84.              rc == NB_INADEQUATE_RESOURCES ) {
  85.             *sessions=Ncb->act_sessions;
  86.             *commands=Ncb->act_commands;
  87.             *names=   Ncb->act_names;
  88.         }
  89.         if ( rc == NB_COMMAND_SUCCESSFUL ) {
  90.             debug(F100,"ckonbi:NCBConfig: About to NCBClose","",0);
  91.             NCBClose(Netbeui,Ncb,lana);
  92.         }
  93.     } /* end if */
  94.  
  95.     return rc;
  96. }
  97.  
  98. USHORT
  99. GetNCBConfig(BOOL Netbeui,USHORT Adapter,PUSHORT S,PUSHORT C, PUSHORT N)
  100. {
  101.     NCB TempNCB;
  102.     return NCBConfig(Netbeui,&TempNCB,Adapter,S,C,N);
  103. }
  104.  
  105. void
  106. os2_netbiosinit( void ) {
  107.     int rc = 1, i ;
  108.  
  109.     if (deblog)
  110.     {
  111.         printf( "  NetBIOS support..." ) ;
  112.         debug(F101,"NetBIOS support...","",NetBiosAdapter);
  113.     }
  114.  
  115.     if ( NetBiosAdapter < 0 ) {
  116.         /* NetBios support has been disabled */
  117.         if (deblog)
  118.         {
  119.             printf( "has been disabled\n" ) ;
  120.             debug(F100,"has been disabled","",0);
  121.         }
  122.         return ;
  123.     }
  124.  
  125.     /* Initialize Send NCBs to zero */
  126.     for ( i=0; i<MAXWS ; i++ )
  127.     {
  128.         pSendNCB[i] = 0 ;
  129.         NetBiosSendBuf[i] = malloc( MAXSP ) ;
  130.     }
  131.  
  132.     rc = netbios_avail( NetbeuiAPI=0 ) ;  /* Microsoft Windows NETBIOS 3.0  */
  133.  
  134.     if ( !rc ) {
  135.         char semname[19] ;
  136.  
  137.         if (deblog)
  138.         {
  139.             printf( "NETBIOS 3.0 OK\n") ;
  140.             debug(F100,"NETBIOS 3.0 OK","",0);
  141.         }
  142.  
  143. #ifdef COMMENT
  144.         DosCreateEventSem( NULL, &hevNetBiosLSN, 0, 0 );
  145.  
  146.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"W");
  147.         if ( pWorkNCB = (PNCB) malloc( NCBSIZE ) )
  148.             rc = Dos16CreateSem( DC_SEM_SHARED,
  149.                                  (PHSEM16) &(pWorkNCB->ncb_semaphore),
  150.                                  semname ) ;
  151.  
  152.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"L");
  153.         if ( pListenNCB = (PNCB) malloc( NCBSIZE ) )
  154.             rc = Dos16CreateSem( DC_SEM_SHARED,
  155.                                  (PHSEM16) &(pListenNCB->ncb_semaphore),
  156.                                  semname ) ;
  157.  
  158.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"R");
  159.         if ( pRecvNCB = (PNCB) malloc( NCBSIZE ) )
  160.             rc = Dos16CreateSem( DC_SEM_SHARED,
  161.                                  (PHSEM16) &(pRecvNCB->ncb_semaphore),
  162.                                  semname ) ;
  163.  
  164.         for ( i=0 ; i < MAXWS ; i++ ) {
  165.             sprintf(semname,"\\SEM\\%#6.6X.%s%2d",pid,"S",i);
  166.             if ( pSendNCB[i] = (PNCB) malloc( NCBSIZE ) )
  167.                 rc = Dos16CreateSem( DC_SEM_SHARED,
  168.                                      (PHSEM16) &(pSendNCB[i]->ncb_semaphore),
  169.                                      semname ) ;
  170.         }
  171. #endif /* COMMENT */
  172.  
  173.         debug(F111,"os2_netbiosinit - About to GetNCBConfig","",0);
  174.         GetNCBConfig( NetbeuiAPI, NetBiosAdapter, &MaxSess,
  175.                       &MaxCmds, &MaxNames ) ;
  176.         debug( F101,"MaxSess","",MaxSess ) ;
  177.         debug( F101, "MaxCmds", "", MaxCmds ) ;
  178.         debug( F101, "MaxNames", "", MaxNames ) ;
  179.  
  180.         if ( NB_LSN < MaxSess )
  181.             MaxSess = NB_LSN ;
  182.         if ( NB_NCB < MaxCmds )
  183.             MaxCmds = NB_NCB ;
  184.         MaxWs = MaxCmds - 3 ;
  185.         if ( MAXWS  < MaxWs )
  186.             MaxWs = MAXWS ;
  187.         if ( NB_NAMES < MaxNames )
  188.             MaxNames = NB_NAMES ;
  189.  
  190.         rc = NCBReset( NetbeuiAPI, pWorkNCB, NetBiosAdapter,
  191.                        MaxSess, MaxCmds, MaxNames ) ;
  192.  
  193.         if ( rc ) {
  194.             if (deblog)
  195.             {
  196.                 printf( "NetBIOS Adapter Reset failed\n" ) ;
  197.                 debug(F100,"NetBIOS Adapter Reset failed","",0);
  198.             }
  199.         }
  200.         else {
  201.             netbiosAvail = 1 ;
  202.             if (deblog)
  203.             {
  204.                 printf( "NetBIOS Adapter Reset successful\n" ) ;
  205.                 debug(F100,"NetBIOS Adapter Reset successful","",0);
  206.             }
  207.         }
  208.     }
  209.     else if (deblog)
  210.     {
  211.         printf( "Not installed\n" ) ;
  212.         debug(F100,"Not installed","",0);
  213.     }
  214. }
  215.  
  216. void
  217. os2_netbioscleanup( void ) {
  218.     if ( netbiosAvail )
  219.     {
  220.         int i ;
  221.  
  222.         if (strcmp( NetBiosName, "                " ) )
  223.             NCBDeleteName( NetbeuiAPI, pWorkNCB, NetBiosAdapter, NetBiosName ) ;
  224.  
  225.         NCBClose( NetbeuiAPI, pWorkNCB, NetBiosAdapter ) ;
  226.  
  227. #ifdef COMMENT
  228.         if ( pWorkNCB )
  229.         {
  230.             Dos16CloseSem( pWorkNCB->ncb_semaphore ) ;
  231.             free( pWorkNCB ) ;
  232.             pWorkNCB = 0 ;
  233.          }
  234.  
  235.         if ( pListenNCB )
  236.         {
  237.             Dos16CloseSem( pListenNCB->ncb_semaphore ) ;
  238.             free( pListenNCB ) ;
  239.             pListenNCB = 0 ;
  240.         }
  241.  
  242.         if ( pRecvNCB )
  243.         {
  244.             Dos16CloseSem( pRecvNCB->ncb_semaphore ) ;
  245.             free( pRecvNCB ) ;
  246.             pRecvNCB = 0 ;
  247.         }
  248.  
  249.         for ( i=0 ; i<MAXWS ; i++ ) {
  250.             if ( pSendNCB[i] )
  251.             {
  252.                 Dos16CloseSem( pSendNCB[i]->ncb_semaphore ) ;
  253.                 free( pSendNCB[i] ) ;
  254.                 pSendNCB[i] = 0 ;
  255.  
  256.                 if ( NetBiosSendBuf[i] )
  257.                 {
  258.                     free( NetBiosSendBuf[i] ) ;
  259.                     NetBiosSendBuf[i] = 0 ;
  260.                 }
  261.             }
  262.         }
  263.  
  264.         DosCloseEventSem( hevNetBiosLSN );
  265. #endif /* COMMENT */
  266.     }
  267. }
  268.  
  269. #pragma stack16(256)
  270. VOID CDECL16
  271. ncbpost(USHORT Junk, PNCB16 NcbPointer)
  272. {
  273.     APIRET rc = 0 ;
  274.     NCB ncb = *NcbPointer ;
  275.     rc = Dos16SemClear(NcbPointer->ncb_semaphore);
  276. }
  277.  
  278.  
  279. USHORT
  280. NCBClose( BOOL Netbeui, PNCB Ncb, USHORT lana)
  281. {
  282.     USHORT rc;
  283.     if(!Netbeui)
  284.     {
  285.         memset( Ncb, 0, BNCBSIZE ) ;
  286.         Ncb->ncb_command  = NB_RESET_WAIT;
  287.         Ncb->ncb_lsn=255;
  288.         Ncb->ncb_lana_num = lana;
  289.         rc=Netbios(Ncb);
  290.     } /* end if */
  291.     debug(F111,"ckonbi:NCBClose","rc",rc);
  292.     return rc;
  293. }
  294. USHORT
  295. NCBAddName( BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  296. {
  297.     memset( Ncb, 0, BNCBSIZE ) ;
  298.     Ncb->bncb.ncb_command  = NB_ADD_NAME_WAIT;
  299.     Ncb->bncb.ncb_lana_num = lana;
  300.     strncpy( Ncb->bncb.ncb_name, name, NETBIOS_NAME_LEN );
  301.     if(!Netbeui)
  302.     {
  303.         Netbios(Ncb );
  304.     } /* end else */
  305.  
  306.     return (Ncb->bncb.ncb_retcode);
  307. }
  308.  
  309. USHORT
  310. NCBDeleteName(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE name )
  311. {
  312.     memset( Ncb, 0, BNCBSIZE ) ;
  313.     Ncb->bncb.ncb_command  = NB_DELETE_NAME_WAIT;
  314.     Ncb->bncb.ncb_lana_num = lana;
  315.     strncpy( Ncb->bncb.ncb_name, name, NETBIOS_NAME_LEN );
  316.  
  317.     if(!Netbeui)
  318.     {
  319.         Netbios(Ncb );
  320.     }
  321.  
  322.     return (Ncb->bncb.ncb_retcode);
  323. }
  324. USHORT
  325. NCBAddGroupName(BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  326. {
  327.     memset( Ncb, 0, BNCBSIZE ) ;
  328.     Ncb->bncb.ncb_command  = NB_ADD_GROUP_NAME_WAIT;
  329.     Ncb->bncb.ncb_lana_num = lana;
  330.     strncpy( Ncb->bncb.ncb_name, name, NETBIOS_NAME_LEN );
  331.  
  332.     if(!Netbeui)
  333.     {
  334.         Netbios(Ncb );
  335.     }
  336.  
  337.     return (Ncb->bncb.ncb_retcode);
  338. }
  339.  
  340. USHORT
  341. NCBCall(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname,
  342.          PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  343. {
  344.     int rc;
  345.     ;
  346.  
  347.     memset( Ncb, 0, BNCBSIZE ) ;
  348.     Ncb->bncb.ncb_command  = (wait)?NB_CALL_WAIT:NB_CALL;
  349.     Ncb->bncb.ncb_lana_num = lana;
  350.     Ncb->bncb.ncb_rto      = recv_timeout*2;  /* times 2 since in   */
  351.     Ncb->bncb.ncb_sto      = send_timeout*2;  /* steps of 500 msecs */
  352.  
  353.     if ( !Netbeui )
  354.     {
  355.         Ncb->bncb.off44.ncb_post_address=
  356.             (address)((!wait)?ncbpost:NULL);
  357.     }
  358.  
  359.     strncpy( Ncb->bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  360.     strncpy( Ncb->bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  361.     if(!wait)
  362.         rc= Dos16SemSet(Ncb->ncb_semaphore);
  363.  
  364.     if(!Netbeui)
  365.     {
  366.         rc=Netbios(Ncb );
  367.     }
  368.  
  369.     return (wait)?Ncb->bncb.ncb_retcode:rc;
  370. }
  371.  
  372. USHORT
  373. NCBListen(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname,
  374.            PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  375. {
  376.     int rc;
  377.     ;
  378.     memset( Ncb, 0, BNCBSIZE ) ;
  379.     Ncb->bncb.ncb_command  = (wait)?NB_LISTEN_WAIT:NB_LISTEN;
  380.     Ncb->bncb.ncb_lana_num = lana;
  381.     Ncb->bncb.ncb_rto      = recv_timeout*2; /* times 2 since in   */
  382.     Ncb->bncb.ncb_sto      = send_timeout*2; /* steps of 500 msecs */
  383.  
  384.     if ( !Netbeui )
  385.     {
  386.         Ncb->bncb.off44.ncb_post_address=
  387.             (address)((!wait)?ncbpost:NULL);
  388.     }
  389.  
  390.     strncpy( Ncb->bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  391.     strncpy( Ncb->bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  392.     if(!wait)
  393.     {
  394.         rc= Dos16SemSet(Ncb->ncb_semaphore);
  395.     }
  396.  
  397.     if(!Netbeui)
  398.     {
  399.         rc=Netbios(Ncb );
  400.     }
  401.  
  402.     return (wait)?Ncb->bncb.ncb_retcode:rc;
  403. }
  404.  
  405. /**********************************************************************/
  406. /*
  407. ** NCBSend      Sends data to the session partner as defined by the
  408. **              session number in the NCB.LSN field.  The data to send
  409. **              is in the buffer pointed to by the NCB.BUFFER field.
  410. **
  411. **              Accepts the adapter number, the session number,
  412. **              the char array holding the message to be sent, and
  413. **              the length of the message in that array.
  414. **
  415. **              Returns the NCB return code.
  416. */
  417.  
  418. USHORT  NCBSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  419.    PBYTE message, word length,BOOL wait)
  420. {
  421.     int rc;
  422.  
  423.     memset( Ncb, 0, BNCBSIZE ) ;
  424.     Ncb->bncb.ncb_command  = (wait)?NB_SEND_WAIT:NB_SEND;
  425.     Ncb->bncb.ncb_lana_num = lana;
  426.     Ncb->bncb.ncb_lsn      = lsn;
  427.     Ncb->bncb.ncb_buffer_address = message;
  428.     Ncb->bncb.ncb_length   = length;
  429.  
  430.     if ( !Netbeui )
  431.     {
  432.         Ncb->bncb.off44.ncb_post_address=
  433.             (address)((!wait)?ncbpost:NULL);
  434.     }
  435.  
  436.     if(!wait)
  437.         rc= Dos16SemSet(Ncb->ncb_semaphore);
  438.  
  439.     if(!Netbeui)
  440.     {
  441.         rc=Netbios(Ncb );
  442.     }
  443.  
  444.     return (wait)?Ncb->bncb.ncb_retcode:rc;
  445. }
  446.  
  447. USHORT NCBSendDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  448.    PSZ rmtname, PBYTE message, word length,BOOL wait)
  449. {
  450.     int rc;
  451.  
  452.     memset( Ncb, 0, BNCBSIZE ) ;
  453.     Ncb->bncb.ncb_command  =
  454.                      (wait)?NB_SEND_DATAGRAM_WAIT:NB_SEND_DATAGRAM;
  455.     Ncb->bncb.ncb_lana_num = lana;
  456.     Ncb->bncb.ncb_num      = lsn;
  457.     Ncb->bncb.ncb_buffer_address = message;
  458.     Ncb->bncb.ncb_length   = length;
  459.  
  460.     if ( !Netbeui )
  461.     {
  462.         Ncb->bncb.off44.ncb_post_address=
  463.             (address)((!wait)?ncbpost:NULL);
  464.     }
  465.  
  466.     strncpy( Ncb->bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  467.     if(!wait)
  468.       rc= Dos16SemSet(Ncb->ncb_semaphore );
  469.  
  470.     if(!Netbeui)
  471.     {
  472.         rc=Netbios(Ncb );
  473.     }
  474.  
  475.     return (wait)?Ncb->bncb.ncb_retcode:rc;
  476. }
  477.  
  478. USHORT
  479. NCBSendBroadcast(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  480.    PBYTE message, word length,BOOL wait)
  481. {
  482.     int rc;
  483.  
  484.    memset( Ncb, 0, BNCBSIZE ) ;
  485.    Ncb->bncb.ncb_command  =
  486.          (wait)?NB_SEND_BROADCAST_DATAGRAM_WAIT:NB_SEND_BROADCAST_DATAGRAM;
  487.    Ncb->bncb.ncb_lana_num = lana;
  488.    Ncb->bncb.ncb_num      = lsn;
  489.    Ncb->bncb.ncb_buffer_address = message;
  490.    Ncb->bncb.ncb_length   = length;
  491.  
  492.    if ( !Netbeui )
  493.    {
  494.       Ncb->bncb.off44.ncb_post_address=
  495.          (address)((!wait)?ncbpost:NULL);
  496.    }
  497.  
  498.    if(!wait)
  499.      rc= Dos16SemSet(Ncb->ncb_semaphore );
  500.  
  501.    if(!Netbeui)
  502.    {
  503.        rc=Netbios(Ncb );
  504.    }
  505.  
  506.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  507. }
  508.  
  509. USHORT
  510. NCBSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  511.    PBYTE message, word length,BOOL wait)
  512. {
  513.     int rc;
  514.  ;
  515.    memset( Ncb, 0, BNCBSIZE ) ;
  516.    Ncb->bncb.ncb_command  =
  517.                         (wait)?NB_SEND_NO_ACK_WAIT:NB_SEND_NO_ACK;
  518.    Ncb->bncb.ncb_lana_num = lana;
  519.    Ncb->bncb.ncb_lsn      = lsn;
  520.    Ncb->bncb.ncb_buffer_address = message;
  521.    Ncb->bncb.ncb_length   = length;
  522.  
  523.    if ( !Netbeui )
  524.    {
  525.       Ncb->bncb.off44.ncb_post_address=
  526.          (address)((!wait)?ncbpost:NULL);
  527.    }
  528.  
  529.   if(!wait)
  530.     rc= Dos16SemSet(Ncb->ncb_semaphore);
  531.  
  532.   if(!Netbeui)
  533.   {
  534.       rc=Netbios(Ncb );
  535.   }
  536.  
  537.   return (wait)?Ncb->bncb.ncb_retcode:rc;
  538. }
  539. /**********************************************************************/
  540. /*
  541. ** NCBChainSend      Sends data to the session partner as defined by the
  542. **              session number in the NCB.LSN field.  The data to send
  543. **              is in the buffer pointed to by the NCB.BUFFER field.
  544. **
  545. **              Accepts the adapter number, the session number,
  546. **              the char array holding the message to be sent, and
  547. **              the length of the message in that array.
  548. **
  549. **              Returns the NCB return code.
  550. */
  551.  
  552. USHORT
  553. NCBChainSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  554.    PBYTE  message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  555. {
  556.     int rc;
  557.     PBuf2 b2;
  558.  
  559.    memset( Ncb, 0, BNCBSIZE ) ;
  560.    b2=(PBuf2)&Ncb->bncb.ncb_callname;
  561.    Ncb->bncb.ncb_command  =
  562.                              (wait)?NB_CHAIN_SEND_WAIT:NB_CHAIN_SEND;
  563.    Ncb->bncb.ncb_lana_num = lana;
  564.    Ncb->bncb.ncb_lsn      = lsn;
  565.    Ncb->bncb.ncb_buffer_address = message;
  566.    Ncb->bncb.ncb_length   = length;
  567.  
  568.    if ( !Netbeui )
  569.    {
  570.       Ncb->bncb.off44.ncb_post_address=
  571.          (address)((!wait)?ncbpost:NULL);
  572.    }
  573.  
  574.    b2->Length=Length2;
  575.    b2->Buffer=Buffer2;
  576.    if(!wait)
  577.      rc= Dos16SemSet(Ncb->ncb_semaphore);
  578.  
  579.    if(!Netbeui)
  580.    {
  581.        rc=Netbios(Ncb );
  582.    }
  583.  
  584.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  585. }
  586.  
  587. USHORT
  588. NCBChainSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  589.    PBYTE message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  590. {
  591.     int rc;
  592.     PBuf2 b2;
  593.  
  594.     memset( Ncb, 0, BNCBSIZE ) ;
  595.    b2=(PBuf2)&Ncb->bncb.ncb_callname;
  596.    Ncb->bncb.ncb_command  =
  597.                   (wait)?NB_CHAIN_SEND_NO_ACK_WAIT:NB_CHAIN_SEND_NO_ACK;
  598.    Ncb->bncb.ncb_lana_num = lana;
  599.    Ncb->bncb.ncb_lsn      = lsn;
  600.    Ncb->bncb.ncb_buffer_address = message;
  601.    Ncb->bncb.ncb_length   = length;
  602.  
  603.    if ( !Netbeui )
  604.    {
  605.       Ncb->bncb.off44.ncb_post_address=
  606.          (address)((!wait)?ncbpost:NULL);
  607.    }
  608.  
  609.    b2->Length=Length2;
  610.    b2->Buffer=Buffer2;
  611.    if(!wait)
  612.      rc= Dos16SemSet(Ncb->ncb_semaphore);
  613.  
  614.    if(!Netbeui)
  615.    {
  616.        rc=Netbios(Ncb );
  617.    }
  618.  
  619.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  620. }
  621.  
  622. /**********************************************************************/
  623. /*
  624. ** NCBReceive   Receives data from the session partner that sends data
  625. **              to this station.
  626. **
  627. **              Accepts the adapter number, the session number,
  628. **              the char array to hold the message received, and
  629. **              the maximum length the message may occupy in that
  630. **              array.
  631. **
  632. **              Returns the NCB return code and, if successful,
  633. **              the received data in the buffer.
  634. */
  635.  
  636. USHORT
  637. NCBReceive(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  638.    PBYTE buffer, word length, BOOL wait )
  639. {
  640.     int rc;
  641.  
  642.    memset( Ncb, 0, BNCBSIZE ) ;
  643.    Ncb->bncb.ncb_command  = (wait)?NB_RECEIVE_WAIT:NB_RECEIVE;
  644.    Ncb->bncb.ncb_lana_num = lana;
  645.    Ncb->bncb.ncb_lsn      = lsn;
  646.    Ncb->bncb.ncb_buffer_address = buffer;
  647.    Ncb->bncb.ncb_length   = length;
  648.  
  649.    if ( !Netbeui )
  650.    {
  651.       Ncb->bncb.off44.ncb_post_address=
  652.          (address)((!wait)?ncbpost:NULL);
  653.    }
  654.  
  655.    if(!wait)
  656.      rc= Dos16SemSet(Ncb->ncb_semaphore);
  657.  
  658.    if(!Netbeui)
  659.    {
  660.        rc=Netbios(Ncb );
  661.    }
  662.  
  663.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  664. }
  665. /**********************************************************************/
  666. /*
  667. ** NCBReceiveAny Receives data from the session partner that sends data
  668. **              to this station.
  669. **
  670. **              Accepts the adapter number, the session number,
  671. **              the char array to hold the message received, and
  672. **              the maximum length the message may occupy in that
  673. **              array.
  674. **
  675. **              Returns the NCB return code and, if successful,
  676. **              the received data in the buffer.
  677. */
  678.  
  679. USHORT
  680. NCBReceiveAny(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  681.    PBYTE buffer, word length,BOOL wait )
  682. {
  683.     int rc;
  684.  
  685.    memset( Ncb, 0, BNCBSIZE ) ;
  686.    Ncb->bncb.ncb_command  =
  687.                            (wait)?NB_RECEIVE_ANY_WAIT:NB_RECEIVE_ANY;
  688.    Ncb->bncb.ncb_lana_num = lana;
  689.    Ncb->bncb.ncb_num      = lsn;
  690.    Ncb->bncb.ncb_buffer_address = buffer;
  691.    Ncb->bncb.ncb_length   = length;
  692.  
  693.    if ( !Netbeui )
  694.    {
  695.       Ncb->bncb.off44.ncb_post_address=
  696.          (address)((!wait)?ncbpost:NULL);
  697.    }
  698.  
  699.    if(!wait)
  700.      rc= Dos16SemSet(Ncb->ncb_semaphore );
  701.  
  702.    if(!Netbeui)
  703.    {
  704.        rc=Netbios(Ncb );
  705.    }
  706.  
  707.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  708. }
  709.  
  710. USHORT
  711. NCBReceiveDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  712.    PBYTE buffer, word length,BOOL wait )
  713. {
  714.     int rc;
  715.  
  716.    memset( Ncb, 0, BNCBSIZE ) ;
  717.    Ncb->bncb.ncb_command  =
  718.                (wait)?NB_RECEIVE_DATAGRAM_WAIT:NB_RECEIVE_DATAGRAM;
  719.    Ncb->bncb.ncb_lana_num = lana;
  720.    Ncb->bncb.ncb_num      = lsn;
  721.    Ncb->bncb.ncb_buffer_address = buffer;
  722.    Ncb->bncb.ncb_length   = length;
  723.  
  724.    if ( !Netbeui )
  725.    {
  726.       Ncb->bncb.off44.ncb_post_address=
  727.          (address)((!wait)?ncbpost:NULL);
  728.    }
  729.  
  730.    if(!wait)
  731.      rc= Dos16SemSet(Ncb->ncb_semaphore );
  732.  
  733.    if(!Netbeui)
  734.    {
  735.        rc=Netbios(Ncb );
  736.    }
  737.  
  738.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  739. }
  740.  
  741. USHORT
  742. NCBReceiveBroadcast(BOOL Netbeui, PNCB  Ncb,USHORT  lana, USHORT lsn,
  743.    PBYTE buffer, word length,BOOL wait )
  744. {
  745.     int rc;
  746.     ;
  747.    memset( Ncb, 0, BNCBSIZE ) ;
  748.    Ncb->bncb.ncb_command  =
  749.        (wait)?NB_RECEIVE_BROADCAST_DATAGRAM_W:NB_RECEIVE_BROADCAST_DATAGRAM;
  750.    Ncb->bncb.ncb_lana_num = lana;
  751.    Ncb->bncb.ncb_num      = lsn;
  752.    Ncb->bncb.ncb_buffer_address = buffer;
  753.    Ncb->bncb.ncb_length   = length;
  754.  
  755.    if ( !Netbeui )
  756.    {
  757.       Ncb->bncb.off44.ncb_post_address=
  758.          (address)((!wait)?ncbpost:NULL);
  759.    }
  760.  
  761.    if(!wait)
  762.      rc= Dos16SemSet(Ncb->ncb_semaphore );
  763.  
  764.    if(!Netbeui)
  765.    {
  766.        rc=Netbios(Ncb );
  767.    }
  768.  
  769.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  770. }
  771.  
  772. /**********************************************************************/
  773. /*
  774. ** NCBHangup    Closes the session with another name on the network
  775. **              specified by the session number.
  776. **
  777. **              Accepts the adapter number and session number.
  778. **
  779. **              Returns the NCB return code.
  780. */
  781.  
  782. USHORT
  783. NCBHangup(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn )
  784. {
  785.    memset( Ncb, 0, BNCBSIZE ) ;
  786.    Ncb->bncb.ncb_command  = NB_HANG_UP_WAIT;
  787.    Ncb->bncb.ncb_lana_num = lana;
  788.    Ncb->bncb.ncb_lsn      = lsn;
  789.  
  790.    if(!Netbeui)
  791.    {
  792.      Netbios(Ncb );
  793.    }
  794.  
  795.    return (Ncb->bncb.ncb_retcode);
  796. }
  797.  
  798. /**********************************************************************/
  799. /*
  800. ** NCBCancel    Cancels a previously issued NCB if possible.
  801. **
  802. **              Accepts the adapter number and a ptr to the NCB to cancel.
  803. **
  804. **              Returns the NCB return code.
  805. */
  806.  
  807. USHORT
  808. NCBCancel(BOOL Netbeui, PNCB  Ncb, USHORT lana, PNCB NcbToCancel)
  809. {
  810.    memset( Ncb, 0, BNCBSIZE ) ;
  811.    Ncb->bncb.ncb_command  = NB_CANCEL_WAIT;
  812.    Ncb->bncb.ncb_lana_num = lana;
  813.    Ncb->bncb.ncb_buffer_address = (address)NcbToCancel;
  814.  
  815.    if(!Netbeui)
  816.    {
  817.        Netbios(Ncb );
  818.    }
  819.  
  820.    return (Ncb->bncb.ncb_retcode);
  821. }
  822.  
  823. /**********************************************************************/
  824. /*
  825. ** NCBStatus
  826. **
  827. **              Accepts the adapter number and a ptr to the NCB to cancel.
  828. **
  829. **              Returns the NCB return code.
  830. */
  831.  
  832. USHORT
  833. NCBStatus(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE callname,
  834.    PSTATUSINFO pInfo, word length, BOOL wait )
  835. {
  836.     int rc;
  837.  
  838.    memset( Ncb, 0, BNCBSIZE ) ;
  839.    Ncb->bncb.ncb_command  = (wait)?NB_STATUS_WAIT:NB_STATUS;
  840.    Ncb->bncb.ncb_lana_num = lana;
  841.    strncpy( Ncb->bncb.ncb_callname, callname, NETBIOS_NAME_LEN );
  842.    Ncb->bncb.ncb_buffer_address = (PBYTE) pInfo;
  843.    Ncb->bncb.ncb_length   = length;
  844.  
  845.    if ( !Netbeui )
  846.    {
  847.       Ncb->bncb.off44.ncb_post_address=
  848.          (address)((!wait)?ncbpost:NULL);
  849.    }
  850.  
  851.    if(!wait)
  852.      rc= Dos16SemSet(Ncb->ncb_semaphore);
  853.  
  854.    if(!Netbeui)
  855.    {
  856.        rc=Netbios(Ncb );
  857.    }
  858.  
  859.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  860. }
  861.  
  862. USHORT
  863. NCBSessionStatus(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE lclname,
  864.    PSESSIONINFO pInfo, word length, BOOL wait )
  865. {
  866.     int rc;
  867.  
  868.    memset( Ncb, 0, BNCBSIZE ) ;
  869.    Ncb->bncb.ncb_command  =
  870.                      (wait)?NB_SESSION_STATUS_WAIT:NB_SESSION_STATUS;
  871.    Ncb->bncb.ncb_lana_num = lana;
  872.    strncpy( Ncb->bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  873.    Ncb->bncb.ncb_buffer_address = (PBYTE) pInfo;
  874.    Ncb->bncb.ncb_length   = length;
  875.  
  876.    if ( !Netbeui )
  877.    {
  878.       Ncb->bncb.off44.ncb_post_address=
  879.          (address)((!wait)?ncbpost:NULL);
  880.    }
  881.  
  882.    if(!wait)
  883.      rc= Dos16SemSet(Ncb->ncb_semaphore);
  884.  
  885.    if(!Netbeui)
  886.    {
  887.        rc=Netbios(Ncb );
  888.    }
  889.  
  890.    return (wait)?Ncb->bncb.ncb_retcode:rc;
  891. }
  892.  
  893. VOID
  894. NCBCancelOutstanding( VOID )
  895. {
  896.     if (netbiosAvail) {
  897.        int i;
  898.        NCB CancelNCB;
  899.        /* Cancel all outstanding Netbios Send or Work requests */
  900.  
  901.        for ( i = 0 ; i < MAXWS ; i++) {
  902.            if (pSendNCB[i]->bncb.ncb_retcode ==
  903.                NB_COMMAND_IN_PROCESS ) {
  904.                NCBCancel( NetbeuiAPI,
  905.                          &CancelNCB,
  906.                          NetBiosAdapter,
  907.                          pSendNCB[i] ) ;
  908.                Dos16SemWait( pSendNCB[i]->ncb_semaphore,
  909.                             SEM_INDEFINITE_WAIT);
  910.            }
  911.        }
  912.        if ( pWorkNCB->bncb.ncb_retcode == NB_COMMAND_IN_PROCESS ) {
  913.            NCBCancel( NetbeuiAPI, &CancelNCB, NetBiosAdapter, pWorkNCB ) ;
  914.            Dos16SemWait( pWorkNCB->ncb_semaphore,
  915.                         SEM_INDEFINITE_WAIT ) ;
  916.        }
  917.    }
  918. }
  919. #endif /* CK_NETBIOS */
  920.