home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / netio111.zip / netbios.c < prev    next >
C/C++ Source or Header  |  1999-10-24  |  18KB  |  688 lines

  1. /* netbios.c
  2.  * NetBIOS access library
  3.  *
  4.  * Author:  Kai Uwe Rommel <rommel@ars.de>
  5.  * Created: Tue Apr 02 1996
  6.  */
  7.  
  8. static char *rcsid =
  9. "$Id: netbios.c,v 1.3 1997/08/09 16:38:55 rommel Exp rommel $";
  10. static char *rcsrev = "$Revision: 1.3 $";
  11.  
  12. /*
  13.  * $Log: netbios.c,v $
  14.  * Revision 1.3  1997/08/09 16:38:55  rommel
  15.  * code simplification for different OS support
  16.  *
  17.  * Revision 1.2  1997/08/09 16:01:48  rommel
  18.  * added Win32 support
  19.  *
  20.  * Revision 1.1  1997/08/09 15:07:58  rommel
  21.  * Initial revision
  22.  *
  23.  */
  24.  
  25. #if !defined(LINUX) && !defined(DJGPP)
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <malloc.h>
  30. #include <string.h>
  31.  
  32. #include "netbios.h"
  33.  
  34. #ifdef WIN32
  35.  
  36. #define NetBIOS(PNCB) Netbios((struct _NCB *) PNCB)
  37.  
  38. #else /* !WIN32 */
  39.  
  40. #ifdef DOS /* only real-mode DOS with LAN-Manager */
  41.  
  42. #include <dos.h>
  43. #define strncpy _fstrncpy
  44.  
  45. #else /* !DOS */
  46.  
  47. #define OS2
  48. #define INCL_DOSSEMAPHORES
  49. #define INCL_DOSMODULEMGR
  50. #include <os2.h>
  51.  
  52. #ifdef __32BIT__
  53. APIRET16 APIENTRY16 Dos16SemSet(PULONG);
  54. APIRET16 APIENTRY16 Dos16SemClear(PULONG);
  55. APIRET16 APIENTRY16 Dos16SemWait(PULONG, ULONG);
  56. #define DosSemSet    Dos16SemSet
  57. #define DosSemClear  Dos16SemClear
  58. #define DosSemWait   Dos16SemWait
  59. #define DosGetModHandle DosQueryModuleHandle
  60. #define DosGetProcAddr(x,y,z) DosQueryProcAddr(x,0,y,z)
  61. #define FUNCPTR * _Far16 _Pascal
  62. #else /* !__32BIT__ */
  63. #define FUNCPTR _far _pascal *
  64. #define strncpy _fstrncpy
  65. #endif /* __32BIT__ */
  66.  
  67. #endif /* DOS */
  68. #endif /* WIN32 */
  69.  
  70. typedef struct
  71. {
  72.   USHORT Length;
  73.   PBYTE Buffer;
  74. }
  75. *PBuf2;
  76.  
  77. typedef struct netbios_info_1
  78. {
  79. # define DEVLEN 8
  80. # define NETBIOS_NAME_LEN 16
  81.   char nb1_net_name[NETBIOS_NAME_LEN + 1];
  82.   char nb1_driver_name[DEVLEN + 1];    /* OS/2 device driver name        */
  83.   unsigned char nb1_lana_num;        /* LAN adapter number of this net */
  84.   char nb1_pad_1;
  85.   unsigned short nb1_driver_type;
  86.   unsigned short nb1_net_status;
  87.   unsigned long nb1_net_bandwidth;    /* Network bandwidth, bits/second */
  88.   unsigned short nb1_max_sess;        /* Max number of sessions         */
  89.   unsigned short nb1_max_ncbs;        /* Max number of outstanding NCBs */
  90.   unsigned short nb1_max_names;        /* Max number of names            */
  91. }
  92. NETINFO1, *PNETINFO1;
  93.  
  94. BOOL NetBIOS_API = NETBIOS;
  95.  
  96. #ifdef WIN32
  97.  
  98. USHORT NetBIOS_Avail()
  99. {
  100.   return 0;
  101. }
  102.  
  103. static void CALLBACK NCBPost(PNCB Ncb)
  104. {
  105.   if (Ncb -> basic_ncb.ncb_semaphore)
  106.     SetEvent(Ncb -> basic_ncb.ncb_semaphore);
  107. }
  108.  
  109. USHORT NCBWait(PNCB Ncb, ULONG timeout)
  110. {
  111.   if (timeout == -1)
  112.     timeout = INFINITE;
  113.  
  114.   if (Ncb -> basic_ncb.ncb_semaphore)
  115.     return WaitForSingleObject(Ncb -> basic_ncb.ncb_semaphore, timeout);
  116.   else
  117.     return -1;
  118. }
  119.  
  120. static void NCBWaitInit(PNCB Ncb, BOOL wait)
  121. {
  122.   if (!wait)
  123.   {
  124.     if (Ncb -> basic_ncb.ncb_semaphore == 0)
  125.       Ncb -> basic_ncb.ncb_semaphore = CreateEvent(NULL, TRUE, FALSE, NULL);
  126.     if (Ncb -> basic_ncb.ncb_semaphore)
  127.       ResetEvent(Ncb -> basic_ncb.ncb_semaphore);
  128.   }
  129. }
  130.  
  131. #else /* !WIN32 */
  132.  
  133. #ifdef DOS
  134.  
  135. USHORT NetBIOS_Avail()
  136. {
  137.   return 0;
  138. }
  139.  
  140. static USHORT NetBIOS(PNCB16 Ncb)
  141. {
  142.   _asm
  143.   {
  144.     mov bx,Ncb
  145.     mov es,Ncb + 2
  146.     int 0x5C /* call NetBIOS */
  147.   }
  148. }
  149.  
  150. static void _interrupt NCBPost(void)
  151. {
  152.   PNCB16 Ncb;
  153.  
  154.   _asm
  155.   {
  156.     mov Ncb,bx
  157.     mov Ncb + 2,es
  158.   }
  159.  
  160.   Ncb -> basic_ncb.ncb_semaphore = 0;
  161. }
  162.  
  163. USHORT NCBWait(PNCB Ncb, ULONG timeout)
  164. {
  165.   while (Ncb -> basic_ncb.ncb_semaphore)
  166.   {
  167.     _asm
  168.     {
  169.       mov ax,0x1680
  170.       int 0x2F /* give up time slice under DPMI */
  171.     }
  172.   }
  173.  
  174.   return 0;
  175. }
  176.  
  177. static void NCBWaitInit(PNCB Ncb, BOOL wait)
  178. {
  179.   if (!wait)
  180.     Ncb -> basic_ncb.ncb_semaphore = 1;
  181. }
  182.  
  183. #else /* !DOS */
  184.  
  185. static USHORT (FUNCPTR NetBIOS)(PNCB16) = NULL;
  186.  
  187. static USHORT (FUNCPTR NetBIOS_Submit)(USHORT, USHORT, PNCB16) = NULL;
  188. static USHORT (FUNCPTR NetBIOS_Close)(USHORT, USHORT) = NULL;
  189. static USHORT (FUNCPTR NetBIOS_Open)(PSZ, PSZ, USHORT, PUSHORT);
  190. static USHORT (FUNCPTR NetBIOS_Enum)(PSZ, USHORT, PBYTE, USHORT, PUSHORT, PUSHORT) = NULL;
  191.  
  192. static USHORT NetBEUI_Handle[4] = {0, 0, 0, 0};
  193. static PNETINFO1 pNetinfo = NULL;
  194. static USHORT Netentries = 0;
  195.  
  196. static USHORT Load_API(PSZ module, PSZ proc, PFN FAR *addr)
  197. {
  198.   int rc, rc1 = 0;
  199.   HMODULE mh;
  200.  
  201.   if ((rc = DosGetModHandle(module, &mh)) == 0)
  202.     rc1 = DosGetProcAddr(mh, proc, addr);
  203.  
  204.   if (rc || rc1)
  205.   {
  206.     rc = DosLoadModule(NULL, 0, module, &mh);
  207.     rc1 = 1;
  208.   }
  209.  
  210.   if (rc == 0 && rc1)
  211.     rc = DosGetProcAddr(mh, proc, addr);
  212.  
  213.   return rc;
  214. }
  215.  
  216. USHORT NetBIOS_Avail()
  217. {
  218.   int rc = 0;
  219.  
  220.   if (NetBIOS_API == NETBEUI)
  221.   {
  222.     if (!NetBIOS_Submit)
  223.     {
  224.       rc |= Load_API("NETAPI", "NETBIOSSUBMIT", (PFN *) &NetBIOS_Submit);
  225.       rc |= Load_API("NETAPI", "NETBIOSCLOSE", (PFN *) &NetBIOS_Close);
  226.       rc |= Load_API("NETAPI", "NETBIOSOPEN", (PFN *) &NetBIOS_Open);
  227.       rc |= Load_API("NETAPI", "NETBIOSENUM", (PFN *) &NetBIOS_Enum);
  228.     }
  229.   }
  230.   else
  231.   {
  232.     if (!NetBIOS)
  233.       rc = Load_API("ACSNETB", "NETBIOS", (PFN *) &NetBIOS);
  234.   }
  235.  
  236.   return rc;
  237. }
  238.  
  239. #ifdef __32BIT__
  240. #pragma stack16(256)
  241. static void _Far16 _Cdecl
  242. #else /* !__32BIT__ */
  243. static void _far _loadds
  244. #endif /* __32BIT__ */
  245. NCBPost(USHORT Junk, PNCB16 Ncb)
  246. {
  247.   DosSemClear(&Ncb -> basic_ncb.ncb_semaphore);
  248. }
  249.  
  250. USHORT NCBWait(PNCB Ncb, ULONG timeout)
  251. {
  252.   if (timeout == -1)
  253.     timeout = SEM_INDEFINITE_WAIT;
  254.   return DosSemWait(&Ncb -> basic_ncb.ncb_semaphore, timeout);
  255. }
  256.  
  257. static void NCBWaitInit(PNCB Ncb, BOOL wait)
  258. {
  259.   if (!wait)
  260.     DosSemSet((HSEM) &Ncb -> basic_ncb.ncb_semaphore);
  261. }
  262.  
  263. static USHORT NetBEUI_Config(USHORT lana,
  264.                  PUSHORT sessions, PUSHORT commands, PUSHORT names)
  265. {
  266.   USHORT rc = NB_INADEQUATE_RESOURCES, blen, MaxEntries, i;
  267.   PNETINFO1 temp = NULL;
  268.  
  269.   if (NetBIOS_Enum)
  270.   {
  271.     if (!pNetinfo)
  272.     {
  273.       NetBIOS_Enum(NULL, 1, (PBYTE) pNetinfo, 0, &Netentries, &MaxEntries);
  274.  
  275.       if ((pNetinfo = (PNETINFO1)
  276.        malloc(blen = sizeof(NETINFO1) * MaxEntries)) != NULL)
  277.     if ((rc = NetBIOS_Enum(NULL, 1, (PBYTE) pNetinfo, blen,
  278.                    &Netentries, &MaxEntries)) != 0)
  279.     {
  280.       free(pNetinfo);
  281.       pNetinfo = NULL;
  282.     }
  283.     }
  284.  
  285.     if (pNetinfo)
  286.       if (lana <= Netentries)
  287.       {
  288.     *sessions = pNetinfo[lana].nb1_max_sess;
  289.     *commands = pNetinfo[lana].nb1_max_ncbs;
  290.     *names = pNetinfo[lana].nb1_max_names;
  291.     rc = NB_COMMAND_SUCCESSFUL;
  292.       }
  293.       else
  294.     rc = NB_INVALID_ADAPTER;
  295.   }
  296.  
  297.   return rc;
  298. }
  299.  
  300. #endif /* DOS */
  301.  
  302. #endif /* WIN32 */
  303.  
  304. USHORT NCBConfig(PNCB Ncb, USHORT lana,
  305.          PUSHORT sessions, PUSHORT commands, PUSHORT names)
  306. {
  307.   SHORT rc;
  308.  
  309. #ifdef OS2
  310.   if (NetBIOS_API == NETBEUI)
  311.   {
  312.     memset(Ncb, 0, NCBSIZE);
  313.  
  314.     if (!(rc = NetBEUI_Config(lana, sessions, commands, names)))
  315.     {
  316.       Ncb -> basic_ncb.bncb.ncb_name[8] = *sessions;
  317.       Ncb -> basic_ncb.bncb.ncb_name[9] = *commands;
  318.       Ncb -> basic_ncb.bncb.ncb_name[10] = *names;
  319.     }
  320.   }
  321.   else
  322. #endif /* OS2 */
  323.   {
  324.     rc = NCBReset(Ncb, lana, 255, 255, 255);
  325.     *sessions = Ncb -> basic_ncb.bncb.ncb_name[0];
  326.     *commands = Ncb -> basic_ncb.bncb.ncb_name[1];
  327.     *names = Ncb -> basic_ncb.bncb.ncb_name[2];
  328.     NCBClose(Ncb, lana);
  329.   }
  330.  
  331.   return rc;
  332. }
  333.  
  334. USHORT NCBClose(PNCB Ncb, USHORT lana)
  335. {
  336.   USHORT rc;
  337.  
  338. #ifdef OS2
  339.   if (NetBIOS_API == NETBEUI)
  340.   {
  341.     if (NetBEUI_Handle[lana])
  342.       rc = NetBIOS_Close(NetBEUI_Handle[lana], 0);
  343.     else
  344.       rc = NB_ENVIRONMENT_NOT_DEFINED;
  345.   }
  346.   else
  347. #endif /* OS2 */
  348.   {
  349.     memset (Ncb, 0, NCBSIZE);
  350.     Ncb -> reset.ncb_command = NB_RESET_WAIT;
  351.     Ncb -> reset.ncb_lsn = 255;
  352.     Ncb -> reset.ncb_lana_num = lana;
  353.     rc = NetBIOS(Ncb);
  354.   }
  355.  
  356.   return rc;
  357. }
  358.  
  359. USHORT NCBReset(PNCB Ncb, USHORT lana,
  360.         USHORT sessions, USHORT commands, USHORT names)
  361. {
  362.   int i, rc = NB_INADEQUATE_RESOURCES;
  363.  
  364. #ifdef OS2
  365.   if (NetBIOS_API == NETBEUI)
  366.   {
  367.     if (!pNetinfo)
  368.       rc = NetBEUI_Config(lana, &sessions, &commands, &names);
  369.  
  370.     if (pNetinfo)
  371.     {
  372.       if (lana <= Netentries)
  373.       {
  374.     if (pNetinfo[lana].nb1_max_sess >= sessions &&
  375.         pNetinfo[lana].nb1_max_ncbs >= commands &&
  376.         pNetinfo[lana].nb1_max_names >= names)
  377.       rc = NetBIOS_Open(pNetinfo[lana].nb1_net_name,
  378.                    NULL, 1, &NetBEUI_Handle[lana]);
  379.       }
  380.       else
  381.     rc = NB_INVALID_ADAPTER;
  382.     }
  383.   }
  384.   else
  385. #endif /* OS2 */
  386.   {
  387.     memset(Ncb, 0, NCBSIZE);
  388.  
  389.     Ncb -> reset.ncb_command = NB_RESET_WAIT;
  390.     Ncb -> reset.ncb_lana_num = lana;
  391.     Ncb -> reset.req_sessions = sessions;
  392.     Ncb -> reset.req_commands = commands;
  393.     Ncb -> reset.req_names = names;
  394.  
  395.     NetBIOS(Ncb);
  396.  
  397.     rc = Ncb -> reset.ncb_retcode;
  398.   }
  399.  
  400.   return rc;
  401. }
  402.  
  403. int NCBSubmit(USHORT lana, PNCB Ncb)
  404. {
  405. #if defined(DOS) || defined(WIN32)
  406.   return NetBIOS(Ncb);
  407. #else /* !DOS */
  408.   return (NetBIOS_API == NETBEUI)
  409.          ? NetBIOS_Submit(NetBEUI_Handle[lana], 0, Ncb)
  410.          : NetBIOS(Ncb);
  411. #endif /* DOS */
  412. }
  413.  
  414. /* from now on, only system independent code */
  415.  
  416. int NCBSubmitWait(USHORT lana, PNCB Ncb, BOOL wait)
  417. {
  418.   int rc;
  419.  
  420.   Ncb -> basic_ncb.bncb.off44.ncb_post_address = (address) (wait ? NULL : NCBPost);
  421.  
  422.   NCBWaitInit(Ncb, wait);
  423.   rc = NCBSubmit(lana, Ncb);
  424.  
  425.   return wait ? Ncb -> basic_ncb.bncb.ncb_retcode : rc;
  426. }
  427.  
  428. USHORT NCBAddName(PNCB Ncb, USHORT lana, PBYTE name)
  429. {
  430.   memset(Ncb, 0, NCBSIZE);
  431.  
  432.   Ncb -> basic_ncb.bncb.ncb_command = NB_ADD_NAME_WAIT;
  433.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  434.   strncpy (Ncb -> basic_ncb.bncb.ncb_name, name, 16);
  435.   Ncb -> basic_ncb.bncb.ncb_name[15] = 0xff;
  436.  
  437.   NCBSubmit(lana, Ncb);
  438.  
  439.   return (Ncb -> basic_ncb.bncb.ncb_retcode);
  440. }
  441.  
  442. USHORT NCBDeleteName(PNCB Ncb, USHORT lana, PBYTE name)
  443. {
  444.   memset(Ncb, 0, NCBSIZE);
  445.  
  446.   Ncb -> basic_ncb.bncb.ncb_command = NB_DELETE_NAME_WAIT;
  447.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  448.   strncpy (Ncb -> basic_ncb.bncb.ncb_name, name, 16);
  449.   Ncb -> basic_ncb.bncb.ncb_name[15] = 0xff;
  450.  
  451.   NCBSubmit(lana, Ncb);
  452.  
  453.   return (Ncb -> basic_ncb.bncb.ncb_retcode);
  454. }
  455.  
  456. USHORT NCBAddGroupName(PNCB Ncb, USHORT lana, PBYTE name)
  457. {
  458.   memset(Ncb, 0, NCBSIZE);
  459.  
  460.   Ncb -> basic_ncb.bncb.ncb_command = NB_ADD_GROUP_NAME_WAIT;
  461.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  462.   strncpy (Ncb -> basic_ncb.bncb.ncb_name, name, 16);
  463.   Ncb -> basic_ncb.bncb.ncb_name[15] = 0xff;
  464.  
  465.   NCBSubmit(lana, Ncb);
  466.  
  467.   return (Ncb -> basic_ncb.bncb.ncb_retcode);
  468. }
  469.  
  470. USHORT NCBCall(PNCB Ncb, USHORT lana, PBYTE lclname, PBYTE rmtname,
  471.            USHORT recv_timeout, USHORT send_timeout, BOOL wait)
  472. {
  473.   memset(Ncb, 0, NCBSIZE);
  474.  
  475.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_CALL_WAIT : NB_CALL;
  476.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  477.   Ncb -> basic_ncb.bncb.ncb_rto = recv_timeout << 1;    /* times 2 since in   */
  478.   Ncb -> basic_ncb.bncb.ncb_sto = send_timeout << 1;    /* steps of 500 msecs */
  479.   strncpy (Ncb -> basic_ncb.bncb.ncb_name, lclname, 16);
  480.   Ncb -> basic_ncb.bncb.ncb_name[15] = 0xff;
  481.   strncpy (Ncb -> basic_ncb.bncb.ncb_callname, rmtname, 16);
  482.   Ncb -> basic_ncb.bncb.ncb_callname[15] = 0xff;
  483.  
  484.   return NCBSubmitWait(lana, Ncb, wait);
  485. }
  486.  
  487. USHORT NCBListen(PNCB Ncb, USHORT lana, PBYTE lclname, PBYTE rmtname,
  488.          USHORT recv_timeout, USHORT send_timeout, BOOL wait)
  489. {
  490.   memset(Ncb, 0, NCBSIZE);
  491.  
  492.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_LISTEN_WAIT : NB_LISTEN;
  493.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  494.   Ncb -> basic_ncb.bncb.ncb_rto = recv_timeout << 1;    /* times 2 since in   */
  495.   Ncb -> basic_ncb.bncb.ncb_sto = send_timeout << 1;    /* steps of 500 msecs */
  496.   strncpy (Ncb -> basic_ncb.bncb.ncb_name, lclname, 16);
  497.   Ncb -> basic_ncb.bncb.ncb_name[15] = 0xff;
  498.   strncpy (Ncb -> basic_ncb.bncb.ncb_callname, rmtname, 16);
  499.   Ncb -> basic_ncb.bncb.ncb_callname[15] = 0xff;
  500.  
  501.   return NCBSubmitWait(lana, Ncb, wait);
  502. }
  503.  
  504. USHORT NCBSend(PNCB Ncb, USHORT lana, USHORT lsn,
  505.            PBYTE message, word length, BOOL wait)
  506. {
  507.   memset(Ncb, 0, NCBSIZE);
  508.  
  509.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_SEND_WAIT : NB_SEND;
  510.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  511.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  512.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  513.   Ncb -> basic_ncb.bncb.ncb_length = length;
  514.  
  515.   return NCBSubmitWait(lana, Ncb, wait);
  516. }
  517.  
  518. USHORT NCBSendDatagram(PNCB Ncb, USHORT lana, USHORT lsn,
  519.                PSZ rmtname, PBYTE message, word length, BOOL wait)
  520. {
  521.   memset(Ncb, 0, NCBSIZE);
  522.  
  523.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_SEND_DATAGRAM_WAIT : NB_SEND_DATAGRAM;
  524.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  525.   Ncb -> basic_ncb.bncb.ncb_num = lsn;
  526.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  527.   Ncb -> basic_ncb.bncb.ncb_length = length;
  528.   strncpy (Ncb -> basic_ncb.bncb.ncb_callname, rmtname, 16);
  529.  
  530.   return NCBSubmitWait(lana, Ncb, wait);
  531. }
  532.  
  533. USHORT NCBSendBroadcast(PNCB Ncb, USHORT lana, USHORT lsn,
  534.             PBYTE message, word length, BOOL wait)
  535. {
  536.   memset(Ncb, 0, NCBSIZE);
  537.  
  538.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_SEND_BROADCAST_DATAGRAM_WAIT : NB_SEND_BROADCAST_DATAGRAM;
  539.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  540.   Ncb -> basic_ncb.bncb.ncb_num = lsn;
  541.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  542.   Ncb -> basic_ncb.bncb.ncb_length = length;
  543.  
  544.   return NCBSubmitWait(lana, Ncb, wait);
  545. }
  546.  
  547. USHORT NCBSendNoAck(PNCB Ncb, USHORT lana, USHORT lsn,
  548.             PBYTE message, word length, BOOL wait)
  549. {
  550.   memset(Ncb, 0, NCBSIZE);
  551.  
  552.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_SEND_NO_ACK_WAIT : NB_SEND_NO_ACK;
  553.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  554.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  555.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  556.   Ncb -> basic_ncb.bncb.ncb_length = length;
  557.  
  558.   return NCBSubmitWait(lana, Ncb, wait);
  559. }
  560.  
  561. USHORT NCBChainSend(PNCB Ncb, USHORT lana, USHORT lsn,
  562.             PBYTE message, word length,
  563.             PBYTE Buffer2, word Length2, BOOL wait)
  564. {
  565.   PBuf2 b2;
  566.  
  567.   memset(Ncb, 0, NCBSIZE);
  568.  
  569.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_CHAIN_SEND_WAIT : NB_CHAIN_SEND;
  570.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  571.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  572.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  573.   Ncb -> basic_ncb.bncb.ncb_length = length;
  574.  
  575.   b2 = (PBuf2) &Ncb -> basic_ncb.bncb.ncb_callname;
  576.   b2 -> Length = Length2;
  577.   b2 -> Buffer = Buffer2;
  578.  
  579.   return NCBSubmitWait(lana, Ncb, wait);
  580. }
  581.  
  582. USHORT NCBChainSendNoAck(PNCB Ncb, USHORT lana, USHORT lsn,
  583.              PBYTE message, word length,
  584.              PBYTE Buffer2, word Length2, BOOL wait)
  585. {
  586.   PBuf2 b2;
  587.  
  588.   memset(Ncb, 0, NCBSIZE);
  589.  
  590.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_CHAIN_SEND_NO_ACK_WAIT : NB_CHAIN_SEND_NO_ACK;
  591.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  592.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  593.   Ncb -> basic_ncb.bncb.ncb_buffer_address = message;
  594.   Ncb -> basic_ncb.bncb.ncb_length = length;
  595.  
  596.   b2 = (PBuf2) &Ncb -> basic_ncb.bncb.ncb_callname;
  597.   b2 -> Length = Length2;
  598.   b2 -> Buffer = Buffer2;
  599.  
  600.   return NCBSubmitWait(lana, Ncb, wait);
  601. }
  602.  
  603. USHORT NCBReceive(PNCB Ncb, USHORT lana, USHORT lsn,
  604.           PBYTE buffer, word length, BOOL wait)
  605. {
  606.   memset(Ncb, 0, NCBSIZE);
  607.  
  608.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_RECEIVE_WAIT : NB_RECEIVE;
  609.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  610.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  611.   Ncb -> basic_ncb.bncb.ncb_buffer_address = buffer;
  612.   Ncb -> basic_ncb.bncb.ncb_length = length;
  613.  
  614.   return NCBSubmitWait(lana, Ncb, wait);
  615. }
  616.  
  617. USHORT NCBReceiveAny(PNCB Ncb, USHORT lana, USHORT lsn,
  618.              PBYTE buffer, word length, BOOL wait)
  619. {
  620.   memset(Ncb, 0, NCBSIZE);
  621.  
  622.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_RECEIVE_ANY_WAIT : NB_RECEIVE_ANY;
  623.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  624.   Ncb -> basic_ncb.bncb.ncb_num = lsn;
  625.   Ncb -> basic_ncb.bncb.ncb_buffer_address = buffer;
  626.   Ncb -> basic_ncb.bncb.ncb_length = length;
  627.  
  628.   return NCBSubmitWait(lana, Ncb, wait);
  629. }
  630.  
  631. USHORT NCBReceiveDatagram(PNCB Ncb, USHORT lana, USHORT lsn,
  632.               PBYTE buffer, word length, BOOL wait)
  633. {
  634.   memset(Ncb, 0, NCBSIZE);
  635.  
  636.   Ncb -> basic_ncb.bncb.ncb_command = wait ? NB_RECEIVE_DATAGRAM_WAIT : NB_RECEIVE_DATAGRAM;
  637.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  638.   Ncb -> basic_ncb.bncb.ncb_num = lsn;
  639.   Ncb -> basic_ncb.bncb.ncb_buffer_address = buffer;
  640.   Ncb -> basic_ncb.bncb.ncb_length = length;
  641.  
  642.   return NCBSubmitWait(lana, Ncb, wait);
  643. }
  644.  
  645. USHORT NCBReceiveBroadcast(PNCB Ncb, USHORT lana, USHORT lsn,
  646.                PBYTE buffer, word length, BOOL wait)
  647. {
  648.   memset(Ncb, 0, NCBSIZE);
  649.  
  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.  
  656.   return NCBSubmitWait(lana, Ncb, wait);
  657. }
  658.  
  659. USHORT NCBHangup(PNCB Ncb, USHORT lana, USHORT lsn)
  660. {
  661.   memset(Ncb, 0, NCBSIZE);
  662.  
  663.   Ncb -> basic_ncb.bncb.ncb_command = NB_HANG_UP_WAIT;
  664.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  665.   Ncb -> basic_ncb.bncb.ncb_lsn = lsn;
  666.  
  667.   NCBSubmit(lana, Ncb);
  668.  
  669.   return (Ncb -> basic_ncb.bncb.ncb_retcode);
  670. }
  671.  
  672. USHORT NCBCancel(PNCB Ncb, USHORT lana, PNCB NcbToCancel)
  673. {
  674.   memset(Ncb, 0, NCBSIZE);
  675.  
  676.   Ncb -> basic_ncb.bncb.ncb_command = NB_CANCEL_WAIT;
  677.   Ncb -> basic_ncb.bncb.ncb_lana_num = lana;
  678.   Ncb -> basic_ncb.bncb.ncb_buffer_address = (address) NcbToCancel;
  679.  
  680.   NCBSubmit(lana, Ncb);
  681.  
  682.   return (Ncb -> basic_ncb.bncb.ncb_retcode);
  683. }
  684.  
  685. #endif /* !LINUX && !DJGPP */
  686.  
  687. /* end of netbios.c */
  688.