home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / NETB32.ZIP / NETBVIEW.C < prev    next >
Text File  |  1993-04-12  |  25KB  |  728 lines

  1. #define INCL_DOSSEMAPHORES
  2. #define INCL_DOSMODULEMGR
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <malloc.h>
  7. #include <string.h>
  8. #ifndef E32TO16
  9. #include <dos.h>
  10. #endif
  11. #include "netbview.h"
  12. #define No 0
  13. #define Yes 1
  14.  
  15. #ifdef E32TO16
  16.  
  17. APIRET16 APIENTRY16 Dos16SemSet(PULONG);
  18. APIRET16 APIENTRY16 Dos16SemClear(PULONG);
  19. #define DosSemSet Dos16SemSet
  20. #define DosGetModHandle DosQueryModuleHandle
  21. #define DosGetProcAddr(x,y,z) DosQueryProcAddr(x,0,y,z)
  22. #ifdef _loadds
  23. #undef _loadds
  24. #define _loadds
  25. #endif
  26. static APIRET16 (* APIENTRY16 netbios)(PNCB)=NULL;
  27. static APIRET16 (* APIENTRY16 netbios_Submit)(USHORT, USHORT, PNCB)=NULL;
  28. static APIRET16 (* APIENTRY16 netbios_Close)(USHORT, USHORT)=NULL;
  29. static APIRET16 (* APIENTRY16 netbios_Open)(PSZ, PSZ, USHORT, PUSHORT);
  30. static APIRET16 (* APIENTRY16 netbios_Enum)(PSZ, USHORT, PBYTE,USHORT, PUSHORT,PUSHORT)=NULL;
  31. #else
  32. #ifndef FP_SEG
  33. #define FP_SEG(fp) (*((unsigned  *)&(fp)+1))
  34. #define FP_OFF(fp) (*((unsigned  *)&(fp)))
  35. #endif
  36. #define APIRET16 USHORT
  37. #define APIENTRY16 far pascal
  38. static APIRET16 (APIENTRY16 *netbios)(PNCB)=NULL;
  39. static APIRET16 (APIENTRY16 *netbios_Submit)(USHORT, USHORT, PNCB)=NULL;
  40. static APIRET16 (APIENTRY16 *netbios_Close)(USHORT, USHORT)=NULL;
  41. static APIRET16 (APIENTRY16 *netbios_Open)(PSZ, PSZ, USHORT, PUSHORT);
  42. static APIRET16 (APIENTRY16 *netbios_Enum)(PSZ, USHORT, PBYTE,USHORT, PUSHORT,PUSHORT)=NULL;
  43. #endif
  44.  
  45.  
  46. static USHORT Netbeui_Handle[4]={0,0,0,0};
  47. static PNETINFO1 pNetinfo=NULL;
  48. static USHORT Netentries=0;
  49.  
  50. USHORT CDECL loadapi(PSZ module, PSZ proc, PFN FAR *addr)
  51. {
  52. int rc,rc1;
  53. HMODULE mh;
  54.        rc1=0;                         /* load adapter processor */
  55.        rc=DosGetModHandle(module,&mh);
  56.        if(rc==0)
  57.          {                            /* loaded, check for this process */
  58.          rc1=DosGetProcAddr(mh,proc,addr);
  59.          }
  60.        if(rc || rc1)     /* either not loaded, or not loaded for this process */
  61.          {                            /* so load it */
  62.          rc=DosLoadModule(NULL,0,module,&mh);
  63.          rc1=1;                       /* force getprocaddr */
  64.          }
  65.        if(rc==0)
  66.          {                            /* loaded ok? */
  67.          if(rc1)                      /* no address to call, so get it */
  68.            rc=DosGetProcAddr(mh,proc,addr); /* get entry */
  69.          }
  70.        return rc;
  71. }
  72.  
  73. USHORT CDECL netbios_avail(BOOL Netbeui)
  74. {
  75. int rc=0;
  76.         if(!Netbeui)
  77.           {
  78.           if(!netbios)
  79.             rc=loadapi("ACSNETB","NETBIOS",(PFN *)&netbios);
  80.           } /* end if */
  81.         else
  82.           {
  83.           if(!netbios_Submit)
  84.             {
  85.             rc|=loadapi("NETAPI","NETBIOSSUBMIT",(PFN *) &netbios_Submit);
  86.             rc|=loadapi("NETAPI","NETBIOSCLOSE", (PFN *) &netbios_Close);
  87.             rc|=loadapi("NETAPI","NETBIOSOPEN",  (PFN *) &netbios_Open);
  88.             rc|=loadapi("NETAPI","NETBIOSENUM",  (PFN *) &netbios_Enum);
  89.             } /* end if */
  90.           } /* end else */
  91.         return rc;
  92. }
  93. GetNCBConfig(BOOL Netbeui,USHORT Adapter,PUSHORT S,PUSHORT C, PUSHORT N)
  94. {
  95. NCB WorkNcb;
  96.       NCBConfig(Netbeui,&WorkNcb,Adapter,S,C,N);
  97. }
  98.  
  99. #ifndef E32TO16
  100. static void _loadds ncbpost(ncb_seg,a,b,c,ncb_off)
  101. USHORT ncb_seg,a,b,c,ncb_off;
  102. {
  103. PNCB ncbp;
  104. USHORT rc;
  105.         _asm {
  106.         mov ncbp+2,bx
  107.         mov ncbp,es
  108.         }
  109. //        FP_SEG(ncbp)=ncb_seg;
  110. //        FP_OFF(ncbp)=ncb_off;
  111.         rc=DosSemClear((HSEM)&ncbp->basic_ncb.ncb_semiphore);
  112. }
  113. #else
  114. #pragma stack16(256)
  115. VOID CDECL16 ncbpost(USHORT Junk, PNCB16 NcbPointer)
  116. {
  117.         Dos16SemClear(&NcbPointer->basic_ncb.ncb_semiphore);
  118. }
  119. #endif
  120.  
  121. static USHORT CDECL NetbeuiConfig(USHORT lana, PUSHORT sessions, PUSHORT commands,PUSHORT names)
  122. {
  123. USHORT rc=NB_INADEQUATE_RESOURCES,blen,MaxEntries,i;
  124. PNETINFO1 temp=NULL;
  125.  
  126.         if(netbios_Enum)
  127.           {
  128.           if(!pNetinfo)
  129.             {
  130.             (*netbios_Enum)(NULL,1,(PBYTE)pNetinfo,0,&Netentries,&MaxEntries);
  131.             if(pNetinfo=(PNETINFO1)malloc(blen=sizeof(NETINFO1)*MaxEntries))
  132.               {
  133.               if(rc=(*netbios_Enum)(NULL,1,(PBYTE)pNetinfo,blen,&Netentries,&MaxEntries))
  134.                 {
  135.                 free(pNetinfo);
  136.                 pNetinfo=NULL;
  137.                 }
  138.               } /* end if */
  139.             }
  140.           if(pNetinfo)
  141.             {
  142.             if(lana<=Netentries)
  143.               {
  144.               *sessions=pNetinfo[lana].nb1_max_sess;
  145.               *commands=pNetinfo[lana].nb1_max_ncbs;
  146.               *names=   pNetinfo[lana].nb1_max_names;
  147.               rc=NB_COMMAND_SUCCESSFUL;
  148.               } /* end if */
  149.             else
  150.               {
  151.               rc=NB_INVALID_ADAPTER;
  152.               } /* end else */
  153.             } /* end if */
  154.           } /* end if */
  155.         return rc;
  156. }
  157.  
  158.  
  159. USHORT CDECL  NCBConfig(BOOL Netbeui, PNCB Ncb, USHORT lana, PUSHORT sessions, PUSHORT commands, PUSHORT names )
  160. {
  161. SHORT rc;
  162.  
  163.         if(!Netbeui)
  164.           {
  165.           rc=NCBReset(Netbeui, Ncb, lana, 255, 255,255 );
  166.           *sessions=Ncb->basic_ncb.bncb.ncb_name[0];
  167.           *commands=Ncb->basic_ncb.bncb.ncb_name[1];
  168.           *names=   Ncb->basic_ncb.bncb.ncb_name[2];
  169.           NCBClose(Netbeui,Ncb,lana);
  170.           } /* end if */
  171.         else
  172.           {
  173.           memset( Ncb, 0, NCBSIZE );
  174.           if(!(rc=NetbeuiConfig(lana,sessions,commands,names)))
  175.             {
  176.             Ncb->basic_ncb.bncb.ncb_name[8]=*sessions;
  177.             Ncb->basic_ncb.bncb.ncb_name[9]=*commands;
  178.             Ncb->basic_ncb.bncb.ncb_name[10]=*names;
  179.             }
  180.           } /* end else */
  181.  
  182.         return rc;
  183. }
  184. USHORT CDECL  NCBClose( BOOL Netbeui, PNCB Ncb, USHORT lana)
  185. {
  186. USHORT rc;
  187.         if(!Netbeui)
  188.           {
  189.           memset( Ncb, 0, NCBSIZE );
  190.           Ncb->reset.ncb_command  = NB_RESET_WAIT;
  191.           Ncb->reset.ncb_lsn=255;
  192.           Ncb->reset.ncb_lana_num = lana;
  193.           rc=(*netbios)(Ncb);
  194.           } /* end if */
  195.         else
  196.           {
  197.           if(Netbeui_Handle[lana])
  198.             {
  199.             rc=(*netbios_Close)(Netbeui_Handle[lana],0);
  200.             } /* end if */
  201.           else
  202.             {
  203.             rc=NB_ENVIRONMENT_NOT_DEFINED;
  204.             } /* end else */
  205.           } /* end else */
  206.         return rc;
  207. }
  208. USHORT CDECL  NCBReset( BOOL Netbeui, PNCB Ncb, USHORT lana,USHORT  sessions,USHORT  commands,USHORT names )
  209. {
  210. int i,rc=NB_INADEQUATE_RESOURCES;
  211.         if(!Netbeui)
  212.           {
  213.           memset( Ncb, 0, NCBSIZE );
  214.           Ncb->reset.ncb_command  = NB_RESET_WAIT;
  215.           Ncb->reset.ncb_lana_num = lana;
  216.           Ncb->reset.req_sessions = sessions;
  217.           Ncb->reset.req_commands = commands;
  218.           Ncb->reset.req_names = names;
  219.  
  220.           (*netbios)(Ncb );
  221.  
  222.           rc=Ncb->reset.ncb_retcode;
  223.           } /* end if */
  224.         else
  225.           {
  226.           if(!pNetinfo)
  227.             {
  228.             rc=NetbeuiConfig(lana,&sessions,&commands,&names);
  229.             } /* end if */
  230.           if(pNetinfo)
  231.             {
  232.             if(lana<=Netentries)
  233.               {
  234.               if(pNetinfo[lana].nb1_max_sess>=sessions &&
  235.                  pNetinfo[lana].nb1_max_ncbs>=commands &&
  236.                  pNetinfo[lana].nb1_max_names>=names)
  237.                  rc=(*netbios_Open)(pNetinfo[lana].nb1_net_name,NULL,1,&Netbeui_Handle[lana]);
  238.               } /* end if */
  239.             else
  240.               {
  241.               rc=NB_INVALID_ADAPTER;
  242.               } /* end else */
  243.             } /* end if */
  244.           } /* end else */
  245.         return rc;
  246. }
  247. USHORT CDECL NCBAddName( BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  248. {
  249.  
  250.         memset( Ncb, 0, NCBSIZE );
  251.         Ncb->basic_ncb.bncb.ncb_command  = NB_ADD_NAME_WAIT;
  252.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  253.         strncpy( Ncb->basic_ncb.bncb.ncb_name, name, 16 );
  254.         Ncb->basic_ncb.bncb.ncb_name[15]=0xff;
  255.         if(Netbeui)
  256.           {
  257.           (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  258.           } /* end if */
  259.         else
  260.           {
  261.           (*netbios)(Ncb );
  262.           } /* end else */
  263.  
  264.         return (Ncb->basic_ncb.bncb.ncb_retcode);
  265. }
  266. USHORT CDECL NCBDeleteName(BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  267. {
  268.  
  269.         memset( Ncb, 0, NCBSIZE );
  270.         Ncb->basic_ncb.bncb.ncb_command  = NB_DELETE_NAME_WAIT;
  271.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  272.         strncpy( Ncb->basic_ncb.bncb.ncb_name, name, 16 );
  273.         Ncb->basic_ncb.bncb.ncb_name[15]=0xff;
  274.  
  275.         if(Netbeui)
  276.           {
  277.           (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  278.           } /* end if */
  279.         else
  280.           {
  281.           (*netbios)(Ncb );
  282.           }
  283.  
  284.         return (Ncb->basic_ncb.bncb.ncb_retcode);
  285. }
  286. USHORT CDECL NCBAddGroupName(BOOL Netbeui, PNCB Ncb,USHORT lana, PBYTE name )
  287. {
  288.  
  289.         memset( Ncb, 0, NCBSIZE );
  290.         Ncb->basic_ncb.bncb.ncb_command  = NB_ADD_GROUP_NAME_WAIT;
  291.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  292.         strncpy( Ncb->basic_ncb.bncb.ncb_name, name, 16 );
  293.         Ncb->basic_ncb.bncb.ncb_name[15]=0xff;
  294.  
  295.         if(Netbeui)
  296.           {
  297.           (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  298.           } /* end if */
  299.         else
  300.           {
  301.           (*netbios)(Ncb );
  302.           }
  303.  
  304.         return (Ncb->basic_ncb.bncb.ncb_retcode);
  305. }
  306. USHORT CDECL  NCBCall(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname, PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  307. {
  308. int rc;
  309.         memset( Ncb, 0, NCBSIZE );
  310.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_CALL_WAIT:NB_CALL;
  311.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  312.         Ncb->basic_ncb.bncb.ncb_rto      = recv_timeout<<1;  /* times 2 since in   */
  313.         Ncb->basic_ncb.bncb.ncb_sto      = send_timeout<<1;  /* steps of 500 msecs */
  314.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  315.         strncpy( Ncb->basic_ncb.bncb.ncb_name, lclname, 16 );
  316.         Ncb->basic_ncb.bncb.ncb_name[15]=0xff;
  317.         strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, 16 );
  318.         Ncb->basic_ncb.bncb.ncb_callname[15]=0xff;
  319.         if(!wait)
  320.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  321.  
  322.         if(Netbeui)
  323.           {
  324.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  325.           } /* end if */
  326.         else
  327.           {
  328.           rc=(*netbios)(Ncb );
  329.           }
  330.  
  331.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  332. }
  333. USHORT CDECL NCBListen(BOOL Netbeui, PNCB  Ncb, USHORT lana, PBYTE lclname, PBYTE rmtname,USHORT recv_timeout,USHORT send_timeout,BOOL wait)
  334. {
  335. int rc;
  336.         memset( Ncb, 0, NCBSIZE );
  337.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_LISTEN_WAIT:NB_LISTEN;
  338.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  339.         Ncb->basic_ncb.bncb.ncb_rto      = recv_timeout<<1;   /* times 2 since in   */
  340.         Ncb->basic_ncb.bncb.ncb_sto      = send_timeout<<1;   /* steps of 500 msecs */
  341.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  342.         strncpy( Ncb->basic_ncb.bncb.ncb_name, lclname, 16 );
  343.         Ncb->basic_ncb.bncb.ncb_name[15]=0xff;
  344.         strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, 16 );
  345.         Ncb->basic_ncb.bncb.ncb_callname[15]=0xff;
  346.         if(!wait)
  347.           {
  348.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  349.           }
  350.  
  351.         if(Netbeui)
  352.           {
  353.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  354.           } /* end if */
  355.         else
  356.           {
  357.           rc=(*netbios)(Ncb );
  358.           }
  359.  
  360.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  361. }
  362.  
  363. /**********************************************************************/
  364. /*
  365. ** NCBSend      Sends data to the session partner as defined by the
  366. **              session number in the NCB.LSN field.  The data to send
  367. **              is in the buffer pointed to by the NCB.BUFFER field.
  368. **
  369. **              Accepts the adapter number, the session number,
  370. **              the char array holding the message to be sent, and
  371. **              the length of the message in that array.
  372. **
  373. **              Returns the NCB return code.
  374. */
  375.  
  376. USHORT CDECL  NCBSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn, PBYTE message, word length,BOOL wait)
  377. {
  378. int rc;
  379.         memset( Ncb, 0, NCBSIZE );
  380.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_SEND_WAIT:NB_SEND;
  381.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  382.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  383.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  384.         Ncb->basic_ncb.bncb.ncb_length   = length;
  385.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  386.         if(!wait)
  387.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  388.  
  389.         if(Netbeui)
  390.           {
  391.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  392.           } /* end if */
  393.         else
  394.           {
  395.           rc=(*netbios)(Ncb );
  396.           }
  397.  
  398.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  399. }
  400.  
  401. USHORT CDECL  NCBSendDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,PSZ rmtname, PBYTE message, word length,BOOL wait)
  402. {
  403. int rc;
  404.         memset( Ncb, 0, NCBSIZE );
  405.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_SEND_DATAGRAM_WAIT:NB_SEND_DATAGRAM;
  406.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  407.         Ncb->basic_ncb.bncb.ncb_num      = lsn;
  408.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  409.         Ncb->basic_ncb.bncb.ncb_length   = length;
  410.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  411.         strncpy( Ncb->basic_ncb.bncb.ncb_callname, rmtname, 16 );
  412.         if(!wait)
  413.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  414.  
  415.         if(Netbeui)
  416.           {
  417.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  418.           } /* end if */
  419.         else
  420.           {
  421.           rc=(*netbios)(Ncb );
  422.           }
  423.  
  424.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  425. }
  426. USHORT CDECL  NCBSendBroadcast(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn, PBYTE message, word length,BOOL wait)
  427. {
  428. int rc;
  429.         memset( Ncb, 0, NCBSIZE );
  430.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_SEND_BROADCAST_DATAGRAM_WAIT:NB_SEND_BROADCAST_DATAGRAM;
  431.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  432.         Ncb->basic_ncb.bncb.ncb_num      = lsn;
  433.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  434.         Ncb->basic_ncb.bncb.ncb_length   = length;
  435.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  436.         if(!wait)
  437.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  438.  
  439.         if(Netbeui)
  440.           {
  441.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  442.           } /* end if */
  443.         else
  444.           {
  445.           rc=(*netbios)(Ncb );
  446.           }
  447.  
  448.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  449. }
  450. USHORT CDECL  NCBSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn, PBYTE message, word length,BOOL wait)
  451. {
  452. int rc;
  453.         memset( Ncb, 0, NCBSIZE );
  454.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_SEND_NO_ACK_WAIT:NB_SEND_NO_ACK;
  455.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  456.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  457.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  458.         Ncb->basic_ncb.bncb.ncb_length   = length;
  459.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  460.         if(!wait)
  461.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  462.  
  463.         if(Netbeui)
  464.           {
  465.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  466.           } /* end if */
  467.         else
  468.           {
  469.           rc=(*netbios)(Ncb );
  470.           }
  471.  
  472.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  473. }
  474. /**********************************************************************/
  475. /*
  476. ** NCBChainSend      Sends data to the session partner as defined by the
  477. **              session number in the NCB.LSN field.  The data to send
  478. **              is in the buffer pointed to by the NCB.BUFFER field.
  479. **
  480. **              Accepts the adapter number, the session number,
  481. **              the char array holding the message to be sent, and
  482. **              the length of the message in that array.
  483. **
  484. **              Returns the NCB return code.
  485. */
  486.  
  487. USHORT CDECL  NCBChainSend(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,PBYTE  message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  488. {
  489. int rc;
  490. PBuf2 b2;
  491.         memset( Ncb, 0, NCBSIZE );
  492.         b2=(PBuf2)&Ncb->basic_ncb.bncb.ncb_callname;
  493.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_CHAIN_SEND_WAIT:NB_CHAIN_SEND;
  494.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  495.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  496.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  497.         Ncb->basic_ncb.bncb.ncb_length   = length;
  498.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  499.         b2->Length=Length2;
  500.         b2->Buffer=Buffer2;
  501.         if(!wait)
  502.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  503.  
  504.         if(Netbeui)
  505.           {
  506.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  507.           } /* end if */
  508.         else
  509.           {
  510.           rc=(*netbios)(Ncb );
  511.           }
  512.  
  513.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  514. }
  515. USHORT CDECL  NCBChainSendNoAck(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn, PBYTE message, word length, PBYTE Buffer2, word Length2,BOOL wait)
  516. {
  517. int rc;
  518. PBuf2 b2;
  519.         memset( Ncb, 0, NCBSIZE );
  520.         b2=(PBuf2)&Ncb->basic_ncb.bncb.ncb_callname;
  521.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_CHAIN_SEND_NO_ACK_WAIT:NB_CHAIN_SEND_NO_ACK;
  522.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  523.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  524.         Ncb->basic_ncb.bncb.ncb_buffer_address = message;
  525.         Ncb->basic_ncb.bncb.ncb_length   = length;
  526.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  527.         b2->Length=Length2;
  528.         b2->Buffer=Buffer2;
  529.         if(!wait)
  530.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  531.  
  532.         if(Netbeui)
  533.           {
  534.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  535.           } /* end if */
  536.         else
  537.           {
  538.           rc=(*netbios)(Ncb );
  539.           }
  540.  
  541.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  542. }
  543.  
  544. /**********************************************************************/
  545. /*
  546. ** NCBReceive   Receives data from the session partner that sends data
  547. **              to this station.
  548. **
  549. **              Accepts the adapter number, the session number,
  550. **              the char array to hold the message received, and
  551. **              the maximum length the message may occupy in that
  552. **              array.
  553. **
  554. **              Returns the NCB return code and, if successful,
  555. **              the received data in the buffer.
  556. */
  557.  
  558. USHORT CDECL NCBReceive(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,PBYTE buffer, word length, BOOL wait )
  559. {
  560. int rc;
  561.         memset( Ncb, 0, NCBSIZE );
  562.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_RECEIVE_WAIT:NB_RECEIVE;
  563.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  564.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  565.         Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  566.         Ncb->basic_ncb.bncb.ncb_length   = length;
  567.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  568.         if(!wait)
  569.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  570.  
  571.         if(Netbeui)
  572.           {
  573.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  574.           } /* end if */
  575.         else
  576.           {
  577.           rc=(*netbios)(Ncb );
  578.           }
  579.  
  580.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  581. }
  582. /**********************************************************************/
  583. /*
  584. ** NCBReceiveAny Receives data from the session partner that sends data
  585. **              to this station.
  586. **
  587. **              Accepts the adapter number, the session number,
  588. **              the char array to hold the message received, and
  589. **              the maximum length the message may occupy in that
  590. **              array.
  591. **
  592. **              Returns the NCB return code and, if successful,
  593. **              the received data in the buffer.
  594. */
  595.  
  596. USHORT CDECL NCBReceiveAny(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn, PBYTE buffer, word length,BOOL wait )
  597. {
  598. int rc;
  599.         memset( Ncb, 0, NCBSIZE );
  600.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_RECEIVE_ANY_WAIT:NB_RECEIVE_ANY;
  601.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  602.         Ncb->basic_ncb.bncb.ncb_num      = lsn;
  603.         Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  604.         Ncb->basic_ncb.bncb.ncb_length   = length;
  605.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  606.         if(!wait)
  607.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  608.  
  609.         if(Netbeui)
  610.           {
  611.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  612.           } /* end if */
  613.         else
  614.           {
  615.           rc=(*netbios)(Ncb );
  616.           }
  617.  
  618.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  619. }
  620.  
  621. USHORT CDECL NCBReceiveDatagram(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn,PBYTE buffer, word length,BOOL wait )
  622. {
  623. int rc;
  624.         memset( Ncb, 0, NCBSIZE );
  625.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_RECEIVE_DATAGRAM_WAIT:NB_RECEIVE_DATAGRAM;
  626.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  627.         Ncb->basic_ncb.bncb.ncb_num      = lsn;
  628.         Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  629.         Ncb->basic_ncb.bncb.ncb_length   = length;
  630.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  631.         if(!wait)
  632.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  633.  
  634.         if(Netbeui)
  635.           {
  636.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  637.           } /* end if */
  638.         else
  639.           {
  640.           rc=(*netbios)(Ncb );
  641.           }
  642.  
  643.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  644. }
  645.  
  646. USHORT CDECL NCBReceiveBroadcast(BOOL Netbeui, PNCB  Ncb,USHORT  lana, USHORT lsn, PBYTE buffer, word length,BOOL wait )
  647. {
  648. int rc;
  649.         memset( Ncb, 0, NCBSIZE );
  650.         Ncb->basic_ncb.bncb.ncb_command  = (wait)?NB_RECEIVE_BROADCAST_DATAGRAM_W:NB_RECEIVE_BROADCAST_DATAGRAM;
  651.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  652.         Ncb->basic_ncb.bncb.ncb_num      = lsn;
  653.         Ncb->basic_ncb.bncb.ncb_buffer_address = buffer;
  654.         Ncb->basic_ncb.bncb.ncb_length   = length;
  655.         Ncb->basic_ncb.bncb.off44.ncb_post_address=(address)((!wait)?ncbpost:NULL);
  656.         if(!wait)
  657.           DosSemSet((HSEM)&Ncb->basic_ncb.ncb_semiphore);
  658.  
  659.         if(Netbeui)
  660.           {
  661.           rc=(*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  662.           } /* end if */
  663.         else
  664.           {
  665.           rc=(*netbios)(Ncb );
  666.           }
  667.  
  668.         return (wait)?Ncb->basic_ncb.bncb.ncb_retcode:rc;
  669. }
  670.  
  671. /**********************************************************************/
  672. /*
  673. ** NCBHangup    Closes the session with another name on the network
  674. **              specified by the session number.
  675. **
  676. **              Accepts the adapter number and session number.
  677. **
  678. **              Returns the NCB return code.
  679. */
  680.  
  681. USHORT CDECL  NCBHangup(BOOL Netbeui, PNCB  Ncb, USHORT lana, USHORT lsn )
  682. {
  683.         memset( Ncb, 0, NCBSIZE );
  684.         Ncb->basic_ncb.bncb.ncb_command  = NB_HANG_UP_WAIT;
  685.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  686.         Ncb->basic_ncb.bncb.ncb_lsn      = lsn;
  687.  
  688.         if(Netbeui)
  689.           {
  690.           (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  691.           } /* end if */
  692.         else
  693.           {
  694.           (*netbios)(Ncb );
  695.           }
  696.  
  697.         return (Ncb->basic_ncb.bncb.ncb_retcode);
  698. }
  699.  
  700. /**********************************************************************/
  701. /*
  702. ** NCBCancel    Closes the session with another name on the network
  703. **              specified by the session number.
  704. **
  705. **              Accepts the adapter number and session number.
  706. **
  707. **              Returns the NCB return code.
  708. */
  709.  
  710. USHORT CDECL  NCBCancel(BOOL Netbeui, PNCB  Ncb, USHORT lana, PNCB NcbToCancel)
  711. {
  712.         memset( Ncb, 0, NCBSIZE );
  713.         Ncb->basic_ncb.bncb.ncb_command  = NB_CANCEL_WAIT;
  714.         Ncb->basic_ncb.bncb.ncb_lana_num = lana;
  715.         Ncb->basic_ncb.bncb.ncb_buffer_address = (address)NcbToCancel;
  716.  
  717.         if(Netbeui)
  718.           {
  719.           (*netbios_Submit)(Netbeui_Handle[lana],0,Ncb);
  720.           } /* end if */
  721.         else
  722.           {
  723.           (*netbios)(Ncb );
  724.           }
  725.  
  726.         return (Ncb->basic_ncb.bncb.ncb_retcode);
  727. }
  728.