home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / n / netbioc.zip / DATASRV.C < prev    next >
C/C++ Source or Header  |  1992-03-01  |  3KB  |  126 lines

  1. /***************************************************************************
  2.  *  DATASRV.C                                   *
  3.  *    This file contains following NetBIOS Datagram Service related       *
  4.  *    functions                               *
  5.  *                                       *
  6.  *      SendDatagram     () :- Sends datagram to a specific name       *
  7.  *      ReceiveDatagram() :- Receives datagram name sent to specific       *
  8.  *                   name.
  9.  *                                       *
  10.  *  History:    Alok Sinha  October, 1991    Created               *
  11.  *                                       *
  12.  ***********************************************************************/
  13.  
  14. // Include files
  15. #include <ncb.h>
  16. #include <common.h>
  17. #include <namesrv.h>
  18. #include <memory.h>
  19. #include <string.h>
  20.  
  21.  
  22. /*
  23.  * FUNCTION    :: SendDatagram()
  24.  * PARAMETERS  ::
  25.  *     [in]  pchName      :- 16 byte unique or global name pointer
  26.  *     [in]  ucLana      :- Lan Adaptor number
  27.  *     [in]  ucNameNum  :- Name Number associated with Name.
  28.  *     [in]  pchData      :- pointer to a data buffer to send
  29.  *     [in]  usDataLen  :- data buffer length.
  30.  *
  31.  * RETURN VALUE:
  32.  *        NO_ERROR if no errors were encountered, else error returned from
  33.  *        NetBIOS call in Retcode field.
  34.  */
  35.  
  36. unsigned char    SendDatagram( char *pchName ,
  37.                   unsigned char ucLana,
  38.                   unsigned char ucNameNum,
  39.                   char far * pchData,
  40.                   unsigned short usDataLen
  41.                )
  42. {
  43.     NCB Ncb;
  44.     unsigned char ucRc;
  45.  
  46.     /* First clear out the buffer */
  47.     ClearNcb ( &Ncb);
  48.  
  49.     /*    Set the Command      */
  50.     Ncb.ncb_command = NCBDGSEND;
  51.  
  52.     /* set the LAN Adaptor number */
  53.     Ncb.ncb_lana_num = ucLana;
  54.  
  55.     /* set the Name Number */
  56.     Ncb.ncb_num = ucNameNum;
  57.  
  58.     /* Set  Data buffer pointer and it's length */
  59.     Ncb.ncb_buffer = pchData;
  60.     Ncb.ncb_length = usDataLen;
  61.  
  62.     /* set the remote name    */
  63.     memcpy ( Ncb.ncb_callname, pchName,    NCBNAMSZ);
  64.  
  65.     /* Make the OS dependent NetBIOS call */
  66.     if ((ucRc=NetBiosRequest ( &Ncb))!= NO_ERROR)
  67.     return ucRc ;
  68.  
  69.     return Ncb.ncb_retcode;
  70.  
  71. }
  72.  
  73.  
  74. /*
  75.  * FUNCTION    :: ReceiveDatagram()
  76.  * PARAMETERS  ::
  77.  *     [in]  ucLana      :- Lan Adaptor number
  78.  *     [in]  ucNameNum  :- Name Number associated with Name.
  79.  *     [in]  pchData      :- pointer to a data buffer to send
  80.  *     [in/out]pusDataLen  :- This is set to data buffer length when
  81.  *                called by application. And it is set by
  82.  *                to data buffer size actually received, if call
  83.  *                completes successfully.
  84.  *
  85.  * RETURN VALUE:
  86.  *        NO_ERROR if no errors were encountered, else error returned from
  87.  *        NetBIOS call in Retcode field.
  88.  */
  89.  
  90. unsigned char    ReceiveDatagram(unsigned char ucLana,
  91.                 unsigned char ucNameNum,
  92.                 char far * pchData,
  93.                 unsigned short *pusDataLen
  94.                   )
  95. {
  96.     NCB Ncb;
  97.     unsigned char ucRc;
  98.  
  99.     /* First clear out the buffer */
  100.     ClearNcb ( &Ncb);
  101.  
  102.     /*    Set the Command      */
  103.     Ncb.ncb_command = NCBDGRECV;
  104.  
  105.     /* set the LAN Adaptor number */
  106.     Ncb.ncb_lana_num = ucLana;
  107.  
  108.     /* set the Name Number */
  109.     Ncb.ncb_num = ucNameNum;
  110.  
  111.     /* Set  Data buffer pointer and it's length */
  112.     Ncb.ncb_buffer = pchData;
  113.     Ncb.ncb_length = *pusDataLen;
  114.  
  115.     /* Make the OS dependent NetBIOS call */
  116.     if ((ucRc=NetBiosRequest ( &Ncb))!= NO_ERROR)
  117.     return ucRc ;
  118.  
  119.     /* return actual size of data buffer if call was successful */
  120.     if (Ncb.ncb_retcode == NO_ERROR)
  121.     *pusDataLen = Ncb.ncb_length;
  122.  
  123.     return Ncb.ncb_retcode;
  124.  
  125. }
  126.