home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckonbi.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  34KB  |  1,231 lines

  1. char *ckonbiv = "OS/2 NetBios support, 8.0.010, 18 Sep 96";
  2.  
  3. /*  C K O N B I  --  OS/2-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.    Author: Jeffrey E Altman <jaltman@secure-endpoints.com>
  14.              Secure Endpoints Inc., New York City     
  15.  
  16.    Supports:
  17.       Traditional NetBios interface:
  18.          IBM Lan Adapter and Protocol Support
  19.          IBM OS/2 Extended Services
  20.          IBM Communication Manager/2
  21.  
  22.       Newer Netbeui Interface:
  23.          Microsoft LAN Manager Requester
  24.          IBM LAN Server Requester
  25.          Novell Netware Requester
  26. */
  27.  
  28. #ifndef __32BIT__
  29. #ifdef CK_NETBIOS
  30. #undef CK_NETBIOS
  31. #endif /* CK_NETBIOS */
  32. #endif /* __32BIT__ */
  33.  
  34. #ifdef CK_NETBIOS
  35. #ifdef NT
  36. #include <windows.h>
  37. #define APIRET16 UCHAR
  38. #define APIENTRY16
  39. #else /* NT */
  40. #define INCL_NOPM
  41. #define INCL_DOSPROCESS
  42. #define INCL_DOSMODULEMGR
  43. #define INCL_ERRORS
  44. #define INCL_DOSSEMAPHORES
  45. #include <os2.h>
  46. #undef COMMENT
  47. #endif /* NT */
  48.  
  49. #include "ckcdeb.h"
  50. #include "ckcker.h"
  51. #ifndef NT
  52. #include "ckonbi.h"
  53. #endif /* NT */
  54.  
  55. #define No 0
  56. #define Yes 1
  57.  
  58. #ifdef _loadds
  59. #undef _loadds
  60. #define _loadds
  61. #endif
  62.  
  63. static APIRET16 (* APIENTRY16 netbios)(PNCB)=NULL;
  64. static APIRET16 (* APIENTRY16 netbios_Submit)(USHORT, USHORT, PNCB)=NULL;
  65. static APIRET16 (* APIENTRY16 netbios_Close)(USHORT, USHORT)=NULL;
  66. static APIRET16 (* APIENTRY16 netbios_Open)(PSZ, PSZ, USHORT, PUSHORT)=NULL;
  67. static APIRET16 (* APIENTRY16 netbios_Enum)(PSZ, USHORT, PBYTE,USHORT,
  68.    PUSHORT,PUSHORT)=NULL;
  69.  
  70. static USHORT Netbeui_Handle[NB_ADAPTERS]={0,0,0,0};
  71. static PNETINFO1 pNetinfo=NULL;
  72. static USHORT Netentries=0;
  73.  
  74. extern int pid ;
  75. extern int ttyfd ;
  76. extern USHORT netbiosAvail ;
  77. extern BOOL NetbeuiAPI = 0 ;
  78.  
  79. UCHAR  NetBiosRemote[NETBIOS_NAME_LEN+1] = "                \0" ;
  80. UCHAR  NetBiosName[NETBIOS_NAME_LEN+1] = "                \0" ;
  81. UCHAR  NetBiosAdapter = 0 ;
  82. BYTE   NetBiosLSN = 0 ;
  83. HEV    hevNetBiosLSN = 0 ;
  84. PNCB   pWorkNCB = 0 ;
  85. PNCB   pListenNCB = 0 ;
  86. PNCB   pRecvNCB = 0 ;
  87. PNCB   pSendNCB[MAXWS] ;
  88. TID    ListenThreadID = -1 ;
  89. #ifndef NT
  90. #pragma seg16 (NetBiosRecvBuf)
  91. #endif /* NT */
  92. BYTE   NetBiosRecvBuf[MAXRP]="" ;
  93. #ifndef NT
  94. #pragma seg16 (NetBiosSendBuf)
  95. #endif /* NT */
  96. BYTE * NetBiosSendBuf[MAXWS] ;
  97. USHORT MaxCmds=0,MaxSess=0,MaxNames=0,MaxWs=0 ;
  98.  
  99. static USHORT
  100. NetbeuiConfig(USHORT lana, PUSHORT sessions, PUSHORT commands,
  101.                PUSHORT names)
  102. {
  103.     USHORT rc=NB_INADEQUATE_RESOURCES,blen,MaxEntries,i;
  104.     PNETINFO1 temp=NULL;
  105.  
  106.     if(netbios_Enum)
  107.     {
  108.         if(!pNetinfo)
  109.         {
  110.             if(pNetinfo=(PNETINFO1)malloc(blen=sizeof(NETINFO1)*NB_ADAPTERS))
  111.             {
  112.                 if(rc=(*netbios_Enum)(NULL,1,(PBYTE)pNetinfo,blen,&Netentries,
  113.                                        &MaxEntries))
  114.                 {
  115.                     free(pNetinfo);
  116.                     pNetinfo=NULL;
  117.                 }
  118.             } /* end if */
  119.         }
  120.         if(pNetinfo)
  121.         {
  122.             if(lana<=Netentries)
  123.             {
  124.                 *sessions=pNetinfo[lana].nb1_max_sess;
  125.                 *commands=pNetinfo[lana].nb1_max_ncbs;
  126.                 *names=   pNetinfo[lana].nb1_max_names;
  127.                 rc=NB_COMMAND_SUCCESSFUL;
  128.             } /* end if */
  129.             else
  130.             {
  131.                 rc=NB_INVALID_ADAPTER;
  132.             } /* end else */
  133.         } /* end if */
  134.     } /* end if */
  135.     return rc;
  136. }
  137.  
  138. USHORT
  139. NCBReset( BOOL Netbeui, PNCB Ncb, USHORT lana,USHORT  sessions,
  140.                   USHORT  commands,USHORT names )
  141. {
  142.     int i,rc=NB_INADEQUATE_RESOURCES,nrc=0;
  143.     if(!Netbeui)
  144.     {
  145.         memset( Ncb, 0, BNCBSIZE ) ;
  146.         Ncb->reset.ncb_command  = NB_RESET_WAIT;
  147.         Ncb->reset.ncb_lana_num = lana;
  148.         Ncb->reset.req_sessions = sessions;
  149.         Ncb->reset.req_commands = commands;
  150.         Ncb->reset.req_names = names;
  151.  
  152.         nrc = (*netbios)(Ncb );
  153.  
  154.         rc=Ncb->reset.ncb_retcode;
  155.     } /* end if */
  156.     else
  157.     {
  158.         if(!pNetinfo)
  159.         {
  160.             rc=NetbeuiConfig(lana,&sessions,&commands,&names);
  161.         } /* end if */
  162.         if(pNetinfo)
  163.         {
  164.             if(lana<=Netentries)
  165.             {
  166.                 if(pNetinfo[lana].nb1_max_sess>=sessions &&
  167.                     pNetinfo[lana].nb1_max_ncbs>=commands &&
  168.                     pNetinfo[lana].nb1_max_names>=names)
  169.                   rc=(*netbios_Open)(pNetinfo[lana].nb1_net_name,NULL,1,
  170.                                       &Netbeui_Handle[lana]);
  171.             } /* end if */
  172.             else
  173.             {
  174.                 rc=NB_INVALID_ADAPTER;
  175.             } /* end else */
  176.         } /* end if */
  177.     } /* end else */
  178.     return rc;
  179. }
  180.  
  181. USHORT
  182. NCBConfig(BOOL Netbeui, PNCB Ncb, USHORT lana, PUSHORT sessions,
  183.            PUSHORT commands, PUSHORT names )
  184. {
  185.     SHORT rc;
  186.  
  187.     *sessions=0;
  188.     *commands=0;
  189.     *names=   0;
  190.  
  191.     if(!Netbeui)
  192.     {
  193.         debug(F100,"ckonbi:NCBConfig: About to NCBReset","",0);
  194.         rc=NCBReset(Netbeui, Ncb, lana, 255, 255,255 );
  195.         debug(F111,"ckonbi: NCBConfig","NCBReset",rc);
  196.         if ( rc == NB_COMMAND_SUCCESSFUL ||
  197.              rc == NB_INADEQUATE_RESOURCES ) {
  198.             *sessions=Ncb->reset.act_sessions;
  199.             *commands=Ncb->reset.act_commands;
  200.             *names=   Ncb->reset.act_names;
  201.         }
  202.         if ( rc == NB_COMMAND_SUCCESSFUL ) {
  203.             debug(F100,"ckonbi:NCBConfig: About to NCBClose","",0);
  204.             NCBClose(Netbeui,Ncb,lana);
  205.         }
  206.     } /* end if */
  207.     else
  208.     {
  209.         memset( Ncb, 0, BNCBSIZE ) ;
  210.         if(!(rc=NetbeuiConfig(lana,sessions,commands,names)))
  211.         {
  212.             Ncb->basic_ncb.bncb.ncb_name[8]=*sessions;
  213.             Ncb->basic_ncb.bncb.ncb_name[9]=*commands;
  214.             Ncb->basic_ncb.bncb.ncb_name[10]=*names;
  215.         }
  216.     } /* end else */
  217.  
  218.     return rc;
  219. }
  220.  
  221. USHORT
  222. GetNCBConfig(BOOL Netbeui,USHORT Adapter,PUSHORT S,PUSHORT C, PUSHORT N)
  223. {
  224.     NCB TempNCB;
  225.     return NCBConfig(Netbeui,&TempNCB,Adapter,S,C,N);
  226. }
  227.  
  228. void
  229. os2_netbiosinit( void ) {
  230.     int rc = 1, i ;
  231.  
  232.     if (deblog)
  233.     {
  234.         printf( "  NetBIOS support..." ) ;
  235.         debug(F101,"NetBIOS support...","",NetBiosAdapter);
  236.     }
  237.  
  238.     if ( NetBiosAdapter < 0 ) {
  239.         /* NetBios support has been disabled */
  240.         if (deblog)
  241.         {
  242.             printf( "has been disabled\n" ) ;
  243.             debug(F100,"has been disabled","",0);
  244.         }
  245.         return ;
  246.     }
  247.  
  248.     /* Initialize Send NCBs to zero */
  249.     for ( i=0; i<MAXWS ; i++ )
  250.     {
  251.         pSendNCB[i] = 0 ;
  252.         NetBiosSendBuf[i] = malloc( MAXSP ) ;
  253.     }
  254.  
  255.     rc = netbios_avail( NetbeuiAPI=0 ) ;  /* ACSNETB.DLL - NTS/2 */
  256.  
  257.     if ( rc )
  258.         rc = netbios_avail( NetbeuiAPI=1 ) ;  /* NETAPI.DLL - Lan Manager,
  259.                                                          Lan Server 2.x,
  260.                                                          Novell Requester */
  261.  
  262.     if ( !rc ) {
  263.         char semname[19] ;
  264.  
  265.         if ( NetbeuiAPI ) {
  266.             if (deblog)
  267.             {
  268.                 printf( "NETAPI.DLL loaded OK\n") ;
  269.                 debug(F100,"NETAPI.DLL loaded OK","",0);
  270.             }
  271.         }
  272.         else {
  273.             if (deblog)
  274.             {
  275.                 printf( "ACSNETB.DLL loaded OK\n") ;
  276.                 debug(F100,"ACSNETB.DLL loaded OK","",0);
  277.             }
  278.         }
  279.  
  280.         DosCreateEventSem( NULL, &hevNetBiosLSN, 0, 0 );
  281.  
  282.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"W");
  283.         if ( pWorkNCB = (PNCB) malloc( NCBSIZE ) )
  284.             rc = Dos16CreateSem( DC_SEM_SHARED,
  285.                                  (PHSEM16) &(pWorkNCB->basic_ncb.ncb_semaphore),
  286.                                  semname ) ;
  287.  
  288.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"L");
  289.         if ( pListenNCB = (PNCB) malloc( NCBSIZE ) )
  290.             rc = Dos16CreateSem( DC_SEM_SHARED,
  291.                                  (PHSEM16) &(pListenNCB->basic_ncb.ncb_semaphore),
  292.                                  semname ) ;
  293.  
  294.         sprintf(semname,"\\SEM\\%#6.6X.CK%s",pid,"R");
  295.         if ( pRecvNCB = (PNCB) malloc( NCBSIZE ) )
  296.             rc = Dos16CreateSem( DC_SEM_SHARED,
  297.                                  (PHSEM16) &(pRecvNCB->basic_ncb.ncb_semaphore),
  298.                                  semname ) ;
  299.  
  300.         for ( i=0 ; i < MAXWS ; i++ ) {
  301.             sprintf(semname,"\\SEM\\%#6.6X.%s%2d",pid,"S",i);
  302.             if ( pSendNCB[i] = (PNCB) malloc( NCBSIZE ) )
  303.                 rc = Dos16CreateSem( DC_SEM_SHARED,
  304.                                      (PHSEM16) &(pSendNCB[i]->basic_ncb.ncb_semaphore),
  305.                                      semname ) ;
  306.         }
  307.  
  308.         debug(F111,"os2_netbiosinit - About to GetNCBConfig","",0);
  309.         GetNCBConfig( NetbeuiAPI, NetBiosAdapter, &MaxSess,
  310.                       &MaxCmds, &MaxNames ) ;
  311.         debug( F101,"MaxSess","",MaxSess ) ;
  312.         debug( F101, "MaxCmds", "", MaxCmds ) ;
  313.         debug( F101, "MaxNames", "", MaxNames ) ;
  314.  
  315.         if ( NB_LSN < MaxSess )
  316.             MaxSess = NB_LSN ;
  317.         if ( NB_NCB < MaxCmds )
  318.             MaxCmds = NB_NCB ;
  319.         MaxWs = MaxCmds - 3 ;
  320.         if ( MAXWS  < MaxWs )
  321.             MaxWs = MAXWS ;
  322.         if ( NB_NAMES < MaxNames )
  323.             MaxNames = NB_NAMES ;
  324.  
  325.         rc = NCBReset( NetbeuiAPI, pWorkNCB, NetBiosAdapter,
  326.                        MaxSess, MaxCmds, MaxNames ) ;
  327.  
  328.  
  329.         if ( rc ) {
  330.             if (deblog)
  331.             {
  332.                 printf( "NetBIOS Adapter Reset failed\n" ) ;
  333.                 debug(F100,"NetBIOS Adapter Reset failed","",0);
  334.             }
  335.         }
  336.         else {
  337.             netbiosAvail = 1 ;
  338.             if (deblog)
  339.             {
  340.                 printf( "NetBIOS Adapter Reset successful\n" ) ;
  341.                 debug(F100,"NetBIOS Adapter Reset successful","",0);
  342.             }
  343.         }
  344.     }
  345.     else if (deblog)
  346.     {
  347.         printf( "Not installed\n" ) ;
  348.         debug(F100,"Not installed","",0);
  349.     }
  350. }
  351.  
  352. void
  353. os2_netbioscleanup( void ) {
  354.     if ( netbiosAvail )
  355.     {
  356.         int i ;
  357.  
  358.         if (strcmp( NetBiosName, "                " ) )
  359.             NCBDeleteName( NetbeuiAPI, pWorkNCB, NetBiosAdapter, NetBiosName ) ;
  360.  
  361.         NCBClose( NetbeuiAPI, pWorkNCB, NetBiosAdapter ) ;
  362.  
  363.         if ( pWorkNCB )
  364.         {
  365.             Dos16CloseSem( pWorkNCB->basic_ncb.ncb_semaphore ) ;
  366.             free( pWorkNCB ) ;
  367.             pWorkNCB = 0 ;
  368.          }
  369.  
  370.         if ( pListenNCB )
  371.         {
  372.             Dos16CloseSem( pListenNCB->basic_ncb.ncb_semaphore ) ;
  373.             free( pListenNCB ) ;
  374.             pListenNCB = 0 ;
  375.         }
  376.  
  377.         if ( pRecvNCB )
  378.         {
  379.             Dos16CloseSem( pRecvNCB->basic_ncb.ncb_semaphore ) ;
  380.             free( pRecvNCB ) ;
  381.             pRecvNCB = 0 ;
  382.         }
  383.  
  384.         for ( i=0 ; i<MAXWS ; i++ ) {
  385.             if ( pSendNCB[i] )
  386.             {
  387.                 Dos16CloseSem( pSendNCB[i]->basic_ncb.ncb_semaphore ) ;
  388.                 free( pSendNCB[i] ) ;
  389.                 pSendNCB[i] = 0 ;
  390.  
  391.                 if ( NetBiosSendBuf[i] )
  392.                 {
  393.                     free( NetBiosSendBuf[i] ) ;
  394.                     NetBiosSendBuf[i] = 0 ;
  395.                 }
  396.             }
  397.         }
  398.  
  399.         DosCloseEventSem( hevNetBiosLSN );
  400.     }
  401. }
  402.  
  403. USHORT
  404. loadapi(PSZ module, PSZ proc, PFN FAR *addr)
  405. {
  406.     int rc,rc1;
  407.     HMODULE mh;
  408.     rc1=0;                         /* load adapter processor */
  409.  
  410.     debug(F100,"ckonbi:loadapi DosQueryModuleHandle","",0);
  411.     rc=DosQueryModuleHandle(module,&mh);
  412.     debug(F111,"ckonbi:loadapi DosQueryModuleHandle","rc",rc);
  413.     if(rc==0)
  414.     {
  415.         debug(F100,"ckonbi:loadapi DosQueryProcAddr","",0);
  416.         /* loaded, check for this process */
  417.         rc1=DosQueryProcAddr(mh,0,proc,addr);
  418.         debug(F111,"ckonbi:loadapi DosQueryProcAddr","rc",rc1);
  419.     }
  420.     if(rc || rc1)   /* either not loaded, or not loaded for this process */
  421.     {
  422.         /* so load it */
  423.         debug(F100,"ckonbi:loadapi DosLoadModule","",0);
  424.         rc=DosLoadModule(NULL,0,module,&mh);
  425.         debug(F111,"ckonbi:loadapi DosLoadModule","rc",rc);
  426.         rc1=1;                       /* force getprocaddr */
  427.     }
  428.     if(rc==0)
  429.     {                            /* loaded ok? */
  430.         if(rc1) {
  431.             /* no address to call, so get it */
  432.             debug(F100,"ckonbi:loadapi DosQueryProcAddr","",0);
  433.             rc=DosQueryProcAddr(mh,0,proc,addr); /* get entry */
  434.             debug(F111,"ckonbi:loadapi DosQueryProcAddr","rc",rc);
  435.         }
  436.     }
  437.     debug(F111,"ckonbi:loadapi","rc",rc);
  438.     return rc;
  439. }
  440.  
  441. USHORT
  442. netbios_avail(BOOL Netbeui)
  443. {
  444.     int rc=0;
  445.     if(!Netbeui)
  446.     {
  447.         if(!netbios)
  448.             rc=loadapi("ACSNETB","NETBIOS",(PFN *)&netbios);
  449.     } /* end if */
  450.     else
  451.     {
  452.         if(!netbios_Submit)
  453.         {
  454.             rc|=loadapi("NETAPI","NETBIOSSUBMIT",(PFN *) &netbios_Submit);
  455.             rc|=loadapi("NETAPI","NETBIOSCLOSE", (PFN *) &netbios_Close );
  456.             rc|=loadapi("NETAPI","NETBIOSOPEN",  (PFN *) &netbios_Open  );
  457.             rc|=loadapi("NETAPI","NETBIOSENUM",  (PFN *) &netbios_Enum  );
  458.         } /* end if */
  459.     } /* end else */
  460.     debug(F111,"ckonbi:netbios_avail","rc",rc);
  461.     return rc;
  462. }
  463.  
  464. #pragma stack16(256)
  465. VOID CDECL16
  466. ncbpost(USHORT Junk, PNCB16 NcbPointer)
  467. {
  468.     APIRET rc = 0 ;
  469.     NCB ncb = *NcbPointer ;
  470.     rc = Dos16SemClear(NcbPointer->basic_ncb.ncb_semaphore);
  471. }
  472.  
  473.  
  474. USHORT
  475. NCBClose( BOOL Netbeui, PNCB Ncb, USHORT lana)
  476. {
  477.     USHORT rc;
  478.     if(!Netbeui)
  479.     {
  480.         memset( Ncb, 0, BNCBSIZE ) ;
  481.         Ncb->reset.ncb_command  = NB_RESET_WAIT;
  482.         Ncb->reset.ncb_lsn=255;
  483.         Ncb->reset.ncb_lana_num = lana;
  484.         rc=(*netbios)(Ncb);
  485.     } /* end if */
  486.     else
  487.     {
  488.         if(Netbeui_Handle[lana])
  489.         {
  490.             rc=(*netbios_Close)(Netbeui_Handle[lana],0);
  491.         } /* end if */
  492.         else
  493.         {
  494.             rc=NB_ENVIRONMENT_NOT_DEFINED;
  495.         } /* end else */
  496.     } /* end else */
  497.     debug(F111,"ckonbi:NCBClose","rc",rc);
  498.     return rc;
  499. }
  500. USHORT
  501. NCBAddName( BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  502. {
  503.     memset( Ncb, 0, BNCBSIZE ) ;
  504.     Ncb->basic_ncb.bncb.ncb_command  = NB_ADD_NAME_WAIT;
  505.     Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  506.     strncpy( Ncb->basic_ncb.bncb.ncb_name, name, NETBIOS_NAME_LEN );
  507.     if(Netbeui)
  508.     {
  509.         (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  510.     } /* end if */
  511.     else
  512.     {
  513.         (*netbios)(Ncb );
  514.     } /* end else */
  515.  
  516.     return (Ncb->basic_ncb.bncb.ncb_retcode);
  517. }
  518.  
  519. USHORT
  520. NCBDeleteName(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE name )
  521. {
  522.     memset( Ncb, 0, BNCBSIZE ) ;
  523.     Ncb->basic_ncb.bncb.ncb_command  = NB_DELETE_NAME_WAIT;
  524.     Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  525.     strncpy( Ncb->basic_ncb.bncb.ncb_name, name, NETBIOS_NAME_LEN );
  526.  
  527.     if(Netbeui)
  528.     {
  529.         (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  530.     } /* end if */
  531.     else
  532.     {
  533.         (*netbios)(Ncb );
  534.     }
  535.  
  536.     return (Ncb->basic_ncb.bncb.ncb_retcode);
  537. }
  538. USHORT
  539. NCBAddGroupName(BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  540. {
  541.     memset( Ncb, 0, BNCBSIZE ) ;
  542.     Ncb->basic_ncb.bncb.ncb_command  = NB_ADD_GROUP_NAME_WAIT;
  543.     Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  544.     strncpy( Ncb->basic_ncb.bncb.ncb_name, name, NETBIOS_NAME_LEN );
  545.  
  546.     if(Netbeui)
  547.     {
  548.         (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  549.     } /* end if */
  550.     else
  551.     {
  552.         (*netbios)(Ncb );
  553.     }
  554.  
  555.     return (Ncb->basic_ncb.bncb.ncb_retcode);
  556. }
  557.  
  558. USHORT
  559. NCBCall(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname,
  560.          PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  561. {
  562.     int rc;
  563.     ;
  564.  
  565.     memset( Ncb, 0, BNCBSIZE ) ;
  566.     Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_CALL_WAIT:NB_CALL;
  567.     Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  568.     Ncb->basic_ncb.bncb.ncb_rto      = recv_timeout*2;  /* times 2 since in   */
  569.     Ncb->basic_ncb.bncb.ncb_sto      = send_timeout*2;  /* steps of 500 msecs */
  570.  
  571.     if ( Netbeui )
  572.     {
  573.         Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  574.             ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  575.     } else {
  576.         Ncb->basic_ncb.bncb.off44.ncb_post_address=
  577.             (address)((!wait)?ncbpost:NULL);
  578.     }
  579.  
  580.     strncpy( Ncb->basic_ncb.bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  581.     strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  582.     if(!wait)
  583.         rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  584.  
  585.     if(Netbeui)
  586.     {
  587.         rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  588.     } /* end if */
  589.     else
  590.     {
  591.         rc=(*netbios)(Ncb );
  592.     }
  593.  
  594.     return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  595. }
  596.  
  597. USHORT
  598. NCBListen(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname,
  599.            PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  600. {
  601.     int rc;
  602.     ;
  603.     memset( Ncb, 0, BNCBSIZE ) ;
  604.     Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_LISTEN_WAIT:NB_LISTEN;
  605.     Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  606.     Ncb->basic_ncb.bncb.ncb_rto      = recv_timeout*2; /* times 2 since in   */
  607.     Ncb->basic_ncb.bncb.ncb_sto      = send_timeout*2; /* steps of 500 msecs */
  608.  
  609.     if ( Netbeui )
  610.     {
  611.         Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  612.             ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  613.     } else {
  614.         Ncb->basic_ncb.bncb.off44.ncb_post_address=
  615.             (address)((!wait)?ncbpost:NULL);
  616.     }
  617.  
  618.     strncpy( Ncb->basic_ncb.bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  619.     strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  620.     if(!wait)
  621.     {
  622.         rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  623.     }
  624.  
  625.     if(Netbeui)
  626.     {
  627.         rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  628.     } /* end if */
  629.     else
  630.     {
  631.         rc=(*netbios)(Ncb );
  632.     }
  633.  
  634.     return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  635. }
  636.  
  637. /**********************************************************************/
  638. /*
  639. ** NCBSend      Sends data to the session partner as defined by the
  640. **              session number in the NCB.LSN field.  The data to send
  641. **              is in the buffer pointed to by the NCB.BUFFER field.
  642. **
  643. **              Accepts the adapter number, the session number,
  644. **              the char array holding the message to be sent, and
  645. **              the length of the message in that array.
  646. **
  647. **              Returns the NCB return code.
  648. */
  649.  
  650. USHORT  NCBSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  651.    PBYTE message, word length,BOOL wait)
  652. {
  653. int rc;
  654.  ;
  655.    memset( Ncb, 0, BNCBSIZE ) ;
  656.    Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_SEND_WAIT:NB_SEND;
  657.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  658.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  659.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  660.    Ncb->basic_ncb.bncb.ncb_length   = length;
  661.  
  662.    if ( Netbeui )
  663.    {
  664.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  665.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  666.    } else {
  667.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  668.          (address)((!wait)?ncbpost:NULL);
  669.    }
  670.  
  671.    if(!wait)
  672.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  673.  
  674.    if(Netbeui)
  675.      {
  676.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  677.      } /* end if */
  678.    else
  679.      {
  680.      rc=(*netbios)(Ncb );
  681.      }
  682.  
  683.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  684. }
  685.  
  686. USHORT NCBSendDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  687.    PSZ rmtname, PBYTE message, word length,BOOL wait)
  688. {
  689. int rc;
  690.  ;
  691.    memset( Ncb, 0, BNCBSIZE ) ;
  692.    Ncb->basic_ncb.bncb.ncb_command  =
  693.                      (wait)?NB_SEND_DATAGRAM_WAIT:NB_SEND_DATAGRAM;
  694.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  695.    Ncb->basic_ncb.bncb.ncb_num      = lsn;
  696.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  697.    Ncb->basic_ncb.bncb.ncb_length   = length;
  698.  
  699.    if ( Netbeui )
  700.    {
  701.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  702.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  703.    } else {
  704.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  705.          (address)((!wait)?ncbpost:NULL);
  706.    }
  707.  
  708.     strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, NETBIOS_NAME_LEN );
  709.     if(!wait)
  710.       rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore );
  711.  
  712.     if(Netbeui)
  713.       {
  714.       rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  715.       } /* end if */
  716.     else
  717.       {
  718.       rc=(*netbios)(Ncb );
  719.       }
  720.  
  721.     return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  722. }
  723. USHORT  NCBSendBroadcast(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  724.    PBYTE message, word length,BOOL wait)
  725. {
  726. int rc;
  727.  ;
  728.    memset( Ncb, 0, BNCBSIZE ) ;
  729.    Ncb->basic_ncb.bncb.ncb_command  =
  730.          (wait)?NB_SEND_BROADCAST_DATAGRAM_WAIT:NB_SEND_BROADCAST_DATAGRAM;
  731.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  732.    Ncb->basic_ncb.bncb.ncb_num      = lsn;
  733.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  734.    Ncb->basic_ncb.bncb.ncb_length   = length;
  735.  
  736.    if ( Netbeui )
  737.    {
  738.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  739.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  740.    } else {
  741.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  742.          (address)((!wait)?ncbpost:NULL);
  743.    }
  744.  
  745.    if(!wait)
  746.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore );
  747.  
  748.    if(Netbeui)
  749.      {
  750.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  751.      } /* end if */
  752.    else
  753.      {
  754.      rc=(*netbios)(Ncb );
  755.      }
  756.  
  757.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  758. }
  759.  
  760. USHORT  NCBSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  761.    PBYTE message, word length,BOOL wait)
  762. {
  763. int rc;
  764.  ;
  765.    memset( Ncb, 0, BNCBSIZE ) ;
  766.    Ncb->basic_ncb.bncb.ncb_command  =
  767.                         (wait)?NB_SEND_NO_ACK_WAIT:NB_SEND_NO_ACK;
  768.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  769.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  770.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  771.    Ncb->basic_ncb.bncb.ncb_length   = length;
  772.  
  773.    if ( Netbeui )
  774.    {
  775.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  776.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  777.    } else {
  778.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  779.          (address)((!wait)?ncbpost:NULL);
  780.    }
  781.  
  782.   if(!wait)
  783.     rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  784.  
  785.   if(Netbeui)
  786.     {
  787.     rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  788.     } /* end if */
  789.   else
  790.     {
  791.     rc=(*netbios)(Ncb );
  792.     }
  793.  
  794.   return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  795. }
  796. /**********************************************************************/
  797. /*
  798. ** NCBChainSend      Sends data to the session partner as defined by the
  799. **              session number in the NCB.LSN field.  The data to send
  800. **              is in the buffer pointed to by the NCB.BUFFER field.
  801. **
  802. **              Accepts the adapter number, the session number,
  803. **              the char array holding the message to be sent, and
  804. **              the length of the message in that array.
  805. **
  806. **              Returns the NCB return code.
  807. */
  808.  
  809. USHORT  NCBChainSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  810.    PBYTE  message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  811. {
  812. int rc;
  813. PBuf2 b2;
  814.  ;
  815.    memset( Ncb, 0, BNCBSIZE ) ;
  816.    b2=(PBuf2)&Ncb->basic_ncb.bncb.ncb_callname;
  817.    Ncb->basic_ncb.bncb.ncb_command  =
  818.                              (wait)?NB_CHAIN_SEND_WAIT:NB_CHAIN_SEND;
  819.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  820.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  821.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  822.    Ncb->basic_ncb.bncb.ncb_length   = length;
  823.  
  824.    if ( Netbeui )
  825.    {
  826.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  827.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  828.    } else {
  829.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  830.          (address)((!wait)?ncbpost:NULL);
  831.    }
  832.  
  833.    b2->Length=Length2;
  834.    b2->Buffer=Buffer2;
  835.    if(!wait)
  836.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  837.  
  838.    if(Netbeui)
  839.      {
  840.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  841.      } /* end if */
  842.    else
  843.      {
  844.      rc=(*netbios)(Ncb );
  845.      }
  846.  
  847.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  848. }
  849. USHORT  NCBChainSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  850.    PBYTE message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  851. {
  852. int rc;
  853. PBuf2 b2;
  854.  ;
  855.    memset( Ncb, 0, BNCBSIZE ) ;
  856.    b2=(PBuf2)&Ncb->basic_ncb.bncb.ncb_callname;
  857.    Ncb->basic_ncb.bncb.ncb_command  =
  858.                   (wait)?NB_CHAIN_SEND_NO_ACK_WAIT:NB_CHAIN_SEND_NO_ACK;
  859.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  860.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  861.    Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  862.    Ncb->basic_ncb.bncb.ncb_length   = length;
  863.  
  864.    if ( Netbeui )
  865.    {
  866.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  867.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  868.    } else {
  869.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  870.          (address)((!wait)?ncbpost:NULL);
  871.    }
  872.  
  873.    b2->Length=Length2;
  874.    b2->Buffer=Buffer2;
  875.    if(!wait)
  876.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  877.  
  878.    if(Netbeui)
  879.      {
  880.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  881.      } /* end if */
  882.    else
  883.      {
  884.      rc=(*netbios)(Ncb );
  885.      }
  886.  
  887.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  888. }
  889.  
  890. /**********************************************************************/
  891. /*
  892. ** NCBReceive   Receives data from the session partner that sends data
  893. **              to this station.
  894. **
  895. **              Accepts the adapter number, the session number,
  896. **              the char array to hold the message received, and
  897. **              the maximum length the message may occupy in that
  898. **              array.
  899. **
  900. **              Returns the NCB return code and, if successful,
  901. **              the received data in the buffer.
  902. */
  903.  
  904. USHORT NCBReceive(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  905.    PBYTE buffer, word length, BOOL wait )
  906. {
  907. int rc;
  908.  ;
  909.    memset( Ncb, 0, BNCBSIZE ) ;
  910.    Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_RECEIVE_WAIT:NB_RECEIVE;
  911.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  912.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  913.    Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  914.    Ncb->basic_ncb.bncb.ncb_length   = length;
  915.  
  916.    if ( Netbeui )
  917.    {
  918.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  919.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  920.    } else {
  921.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  922.          (address)((!wait)?ncbpost:NULL);
  923.    }
  924.  
  925.    if(!wait)
  926.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  927.  
  928.    if(Netbeui)
  929.      {
  930.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  931.      } /* end if */
  932.    else
  933.      {
  934.      rc=(*netbios)(Ncb );
  935.      }
  936.  
  937.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  938. }
  939. /**********************************************************************/
  940. /*
  941. ** NCBReceiveAny Receives data from the session partner that sends data
  942. **              to this station.
  943. **
  944. **              Accepts the adapter number, the session number,
  945. **              the char array to hold the message received, and
  946. **              the maximum length the message may occupy in that
  947. **              array.
  948. **
  949. **              Returns the NCB return code and, if successful,
  950. **              the received data in the buffer.
  951. */
  952.  
  953. USHORT NCBReceiveAny(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  954.    PBYTE buffer, word length,BOOL wait )
  955. {
  956. int rc;
  957.  ;
  958.    memset( Ncb, 0, BNCBSIZE ) ;
  959.    Ncb->basic_ncb.bncb.ncb_command  =
  960.                            (wait)?NB_RECEIVE_ANY_WAIT:NB_RECEIVE_ANY;
  961.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  962.    Ncb->basic_ncb.bncb.ncb_num      = lsn;
  963.    Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  964.    Ncb->basic_ncb.bncb.ncb_length   = length;
  965.  
  966.    if ( Netbeui )
  967.    {
  968.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  969.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  970.    } else {
  971.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  972.          (address)((!wait)?ncbpost:NULL);
  973.    }
  974.  
  975.    if(!wait)
  976.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore );
  977.  
  978.    if(Netbeui)
  979.      {
  980.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  981.      } /* end if */
  982.    else
  983.      {
  984.      rc=(*netbios)(Ncb );
  985.      }
  986.  
  987.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  988. }
  989.  
  990. USHORT NCBReceiveDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,
  991.    PBYTE buffer, word length,BOOL wait )
  992. {
  993. int rc;
  994.  ;
  995.    memset( Ncb, 0, BNCBSIZE ) ;
  996.    Ncb->basic_ncb.bncb.ncb_command  =
  997.                (wait)?NB_RECEIVE_DATAGRAM_WAIT:NB_RECEIVE_DATAGRAM;
  998.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  999.    Ncb->basic_ncb.bncb.ncb_num      = lsn;
  1000.    Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  1001.    Ncb->basic_ncb.bncb.ncb_length   = length;
  1002.  
  1003.    if ( Netbeui )
  1004.    {
  1005.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  1006.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  1007.    } else {
  1008.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  1009.          (address)((!wait)?ncbpost:NULL);
  1010.    }
  1011.  
  1012.    if(!wait)
  1013.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore );
  1014.  
  1015.    if(Netbeui)
  1016.      {
  1017.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1018.      } /* end if */
  1019.    else
  1020.      {
  1021.      rc=(*netbios)(Ncb );
  1022.      }
  1023.  
  1024.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  1025. }
  1026.  
  1027. USHORT NCBReceiveBroadcast(BOOL Netbeui, PNCB  Ncb,USHORT  lana, USHORT lsn,
  1028.    PBYTE buffer, word length,BOOL wait )
  1029. {
  1030. int rc;
  1031.  ;
  1032.    memset( Ncb, 0, BNCBSIZE ) ;
  1033.    Ncb->basic_ncb.bncb.ncb_command  =
  1034.        (wait)?NB_RECEIVE_BROADCAST_DATAGRAM_W:NB_RECEIVE_BROADCAST_DATAGRAM;
  1035.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  1036.    Ncb->basic_ncb.bncb.ncb_num      = lsn;
  1037.    Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  1038.    Ncb->basic_ncb.bncb.ncb_length   = length;
  1039.  
  1040.    if ( Netbeui )
  1041.    {
  1042.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  1043.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  1044.    } else {
  1045.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  1046.          (address)((!wait)?ncbpost:NULL);
  1047.    }
  1048.  
  1049.    if(!wait)
  1050.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore );
  1051.  
  1052.    if(Netbeui)
  1053.      {
  1054.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1055.      } /* end if */
  1056.    else
  1057.      {
  1058.      rc=(*netbios)(Ncb );
  1059.      }
  1060.  
  1061.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  1062. }
  1063.  
  1064. /**********************************************************************/
  1065. /*
  1066. ** NCBHangup    Closes the session with another name on the network
  1067. **              specified by the session number.
  1068. **
  1069. **              Accepts the adapter number and session number.
  1070. **
  1071. **              Returns the NCB return code.
  1072. */
  1073.  
  1074. USHORT  NCBHangup(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn )
  1075. {
  1076.    memset( Ncb, 0, BNCBSIZE ) ;
  1077.    Ncb->basic_ncb.bncb.ncb_command  = NB_HANG_UP_WAIT;
  1078.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  1079.    Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  1080.  
  1081.    if(Netbeui)
  1082.      {
  1083.      (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1084.      } /* end if */
  1085.    else
  1086.      {
  1087.      (*netbios)(Ncb );
  1088.      }
  1089.  
  1090.    return (Ncb->basic_ncb.bncb.ncb_retcode);
  1091. }
  1092.  
  1093. /**********************************************************************/
  1094. /*
  1095. ** NCBCancel    Cancels a previously issued NCB if possible.
  1096. **
  1097. **              Accepts the adapter number and a ptr to the NCB to cancel.
  1098. **
  1099. **              Returns the NCB return code.
  1100. */
  1101.  
  1102. USHORT  NCBCancel(BOOL Netbeui, PNCB  Ncb, USHORT lana, PNCB NcbToCancel)
  1103. {
  1104.    memset( Ncb, 0, BNCBSIZE ) ;
  1105.    Ncb->basic_ncb.bncb.ncb_command  = NB_CANCEL_WAIT;
  1106.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  1107.    Ncb->basic_ncb.bncb.ncb_buffer_address = (address)NcbToCancel;
  1108.  
  1109.    if(Netbeui)
  1110.      {
  1111.      (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1112.      } /* end if */
  1113.    else
  1114.      {
  1115.      (*netbios)(Ncb );
  1116.      }
  1117.  
  1118.    return (Ncb->basic_ncb.bncb.ncb_retcode);
  1119. }
  1120.  
  1121. /**********************************************************************/
  1122. /*
  1123. ** NCBStatus
  1124. **
  1125. **              Accepts the adapter number and a ptr to the NCB to cancel.
  1126. **
  1127. **              Returns the NCB return code.
  1128. */
  1129.  
  1130. USHORT NCBStatus(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE callname,
  1131.    PSTATUSINFO pInfo, word length, BOOL wait )
  1132. {
  1133. int rc;
  1134.  ;
  1135.    memset( Ncb, 0, BNCBSIZE ) ;
  1136.    Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_STATUS_WAIT:NB_STATUS;
  1137.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  1138.    strncpy( Ncb->basic_ncb.bncb.ncb_callname, callname, NETBIOS_NAME_LEN );
  1139.    Ncb->basic_ncb.bncb.ncb_buffer_address = (PBYTE) pInfo;
  1140.    Ncb->basic_ncb.bncb.ncb_length   = length;
  1141.  
  1142.    if ( Netbeui )
  1143.    {
  1144.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  1145.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  1146.    } else {
  1147.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  1148.          (address)((!wait)?ncbpost:NULL);
  1149.    }
  1150.  
  1151.    if(!wait)
  1152.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  1153.  
  1154.    if(Netbeui)
  1155.      {
  1156.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1157.      } /* end if */
  1158.    else
  1159.      {
  1160.      rc=(*netbios)(Ncb );
  1161.      }
  1162.  
  1163.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  1164. }
  1165.  
  1166. USHORT NCBSessionStatus(BOOL Netbeui, PNCB Ncb, USHORT lana, PBYTE lclname,
  1167.    PSESSIONINFO pInfo, word length, BOOL wait )
  1168. {
  1169. int rc;
  1170.  ;
  1171.    memset( Ncb, 0, BNCBSIZE ) ;
  1172.    Ncb->basic_ncb.bncb.ncb_command  =
  1173.                      (wait)?NB_SESSION_STATUS_WAIT:NB_SESSION_STATUS;
  1174.    Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  1175.    strncpy( Ncb->basic_ncb.bncb.ncb_name, lclname, NETBIOS_NAME_LEN );
  1176.    Ncb->basic_ncb.bncb.ncb_buffer_address = (PBYTE) pInfo;
  1177.    Ncb->basic_ncb.bncb.ncb_length   = length;
  1178.  
  1179.    if ( Netbeui )
  1180.    {
  1181.       Ncb->basic_ncb.bncb.off44.ncb_post_handle=
  1182.          ((!wait)?Ncb->basic_ncb.ncb_semaphore:0L);
  1183.    } else {
  1184.       Ncb->basic_ncb.bncb.off44.ncb_post_address=
  1185.          (address)((!wait)?ncbpost:NULL);
  1186.    }
  1187.  
  1188.    if(!wait)
  1189.      rc= Dos16SemSet(Ncb->basic_ncb.ncb_semaphore);
  1190.  
  1191.    if(Netbeui)
  1192.      {
  1193.      rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  1194.      } /* end if */
  1195.    else
  1196.      {
  1197.      rc=(*netbios)(Ncb );
  1198.      }
  1199.  
  1200.    return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  1201. }
  1202.  
  1203. VOID
  1204. NCBCancelOutstanding( VOID )
  1205. {
  1206.     if (netbiosAvail) {
  1207.        int i;
  1208.        NCB CancelNCB;
  1209.        /* Cancel all outstanding Netbios Send or Work requests */
  1210.  
  1211.        for ( i = 0 ; i < MAXWS ; i++) {
  1212.            if (pSendNCB[i]->basic_ncb.bncb.ncb_retcode ==
  1213.                NB_COMMAND_IN_PROCESS ) {
  1214.                NCBCancel( NetbeuiAPI,
  1215.                          &CancelNCB,
  1216.                          NetBiosAdapter,
  1217.                          pSendNCB[i] ) ;
  1218.                Dos16SemWait( pSendNCB[i]->basic_ncb.ncb_semaphore,
  1219.                             SEM_INDEFINITE_WAIT);
  1220.            }
  1221.        }
  1222.        if ( pWorkNCB->basic_ncb.bncb.ncb_retcode == NB_COMMAND_IN_PROCESS ) {
  1223.            NCBCancel( NetbeuiAPI, &CancelNCB, NetBiosAdapter, pWorkNCB ) ;
  1224.            Dos16SemWait( pWorkNCB->basic_ncb.ncb_semaphore,
  1225.                         SEM_INDEFINITE_WAIT ) ;
  1226.        }
  1227.    }
  1228. }
  1229.  
  1230. #endif /* CK_NETBIOS */
  1231.