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

  1. /***************************************************************************
  2.  *  NAMESRV.C                                   *
  3.  *    This file contains following NetBIOS Name Service related functions*
  4.  *                                       *
  5.  *      AddName  () - Adds a unique name or group name in the Name Table *
  6.  *      DelName  () - Deletes a name from the Name Table           *
  7.  *      FindName () - Find a name on the networks               *
  8.  *                                       *
  9.  *  History:    Alok Sinha  October, 1991    Created               *
  10.  *                                       *
  11.  ***********************************************************************/
  12.  
  13. // Include files
  14. #include <ncb.h>
  15. #include <common.h>
  16. #include <namesrv.h>
  17. #include <memory.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. /*
  22.  * FUNCTION    :: AddName()
  23.  * PARAMETERS  ::
  24.  *     [in]  pchName      :- 16 byte unique or global name pointer
  25.  *     [in]  ucFlags      :- such as Unique Name or Global Name
  26.  *     [in]  ucLana      :- Lan Adaptor number
  27.  *     [out] pucNameNum :- Pointer to Name Number. A valid value can be
  28.  *                 expected in this, if return value is NO_ERROR.
  29.  * RETURN VALUE:
  30.  *        NO_ERROR if no errors were encountered, else error returned from
  31.  *        NetBIOS call in Retcode field.
  32.  */
  33.  
  34.  
  35. unsigned char AddName (char *pchName,
  36.             unsigned char ucFlags,
  37.             unsigned char ucLana,
  38.             unsigned char * pucNameNum
  39.                )
  40. {
  41.     NCB Ncb;
  42.     unsigned char ucRc;
  43.  
  44.     /* First clear out the buffer */
  45.     ClearNcb ( &Ncb);
  46.  
  47.     /*    Set the Command      */
  48.     if ( ucFlags == ADD_UNIQUE_NAME)
  49.     Ncb.ncb_command = NCBADDNAME;
  50.     else if ( ucFlags == ADD_GROUP_NAME)
  51.     Ncb.ncb_command = NCBADDGRNAME;
  52.     else
  53.     return ERROR_INVALID_PARAMETER;
  54.  
  55.     /* set the LAN Adaptor number */
  56.     Ncb.ncb_lana_num = ucLana;
  57.  
  58.     /* set the name          */
  59.     memcpy ( Ncb.ncb_name, pchName,  NCBNAMSZ);
  60.  
  61.     /* Make the OS dependent NetBIOS call */
  62.     if ((ucRc=NetBiosRequest ( &Ncb))!= NO_ERROR)
  63.     return ucRc ;
  64.  
  65.     /* return name number if call was successful */
  66.     if (Ncb.ncb_retcode == NO_ERROR)
  67.     *pucNameNum = Ncb.ncb_num;
  68.  
  69.     return Ncb.ncb_retcode;
  70. }
  71.  
  72.  
  73. /*
  74.  * FUNCTION    :: DelName()
  75.  * PARAMETERS  ::
  76.  *     [in]  pchName      :- 16 byte unique or global name pointer
  77.  *     [in]  ucLana      :- Lan Adaptor number
  78.  *     [in]  ucNameNum :-  Name Number associated with Name.
  79.  *
  80.  * RETURN VALUE:
  81.  *        NO_ERROR if no errors were encountered, else error returned from
  82.  *        NetBIOS call in Retcode field.
  83.  */
  84.  
  85.  
  86. unsigned char DelName (char *pchName,
  87.             unsigned char ucLana,
  88.             unsigned char ucNameNum
  89.                )
  90. {
  91.     NCB Ncb;
  92.     unsigned char ucRc;
  93.  
  94.     /* First clear out the buffer */
  95.     ClearNcb ( &Ncb);
  96.  
  97.     /*    Set the Command      */
  98.     Ncb.ncb_command = NCBDELNAME;
  99.  
  100.     /* set the LAN Adaptor number */
  101.     Ncb.ncb_lana_num = ucLana;
  102.  
  103.     /* set the name          */
  104.     memcpy ( Ncb.ncb_name, pchName,  NCBNAMSZ);
  105.  
  106.     /* Make the OS dependent NetBIOS call   */
  107.     if ((ucRc=NetBiosRequest ( &Ncb))!= NO_ERROR)
  108.     return ucRc ;
  109.  
  110.     return Ncb.ncb_retcode;
  111. }
  112.  
  113. /*
  114.  * FUNCTION    :: FindName()
  115.  * PARAMETERS  ::
  116.  *     [in]  pchName      :- 16 byte unique or global name pointer
  117.  *     [in]  ucLana      :- Lan Adaptor number
  118.  *
  119.  * RETURN VALUE:
  120.  *        TRUE  :- If a workstation with Supplied name exists and reponds.
  121.  *        FALSE :- False otherwise
  122.  */
  123.  
  124.  
  125. BOOL FindName (char *pchName,
  126.         unsigned char ucLana
  127.           )
  128. {
  129.     NCB        Ncb;
  130.     unsigned char ucRc;
  131.     unsigned char  ucBuffer [ FIND_BUFFER_LENGTH ];
  132.     FINDBUF       *pFindBuf;
  133.  
  134.     /* First clear out the buffer */
  135.     ClearNcb ( &Ncb);
  136.  
  137.     /*    Set the Command      */
  138.     Ncb.ncb_command = NCBFINDNAME;
  139.  
  140.     /* set the LAN Adaptor number */
  141.     Ncb.ncb_lana_num = ucLana;
  142.  
  143.     /* set the name          */
  144.     memcpy ( Ncb.ncb_callname, pchName,    NCBNAMSZ);
  145.  
  146.     /* set the buffer and buffer length */
  147.     Ncb.ncb_buffer = (char far *) ucBuffer;
  148.     Ncb.ncb_length =  FIND_BUFFER_LENGTH;
  149.  
  150.     /* Make the OS dependent NetBIOS call     */
  151.     if ((ucRc=NetBiosRequest ( &Ncb))!= NO_ERROR)
  152.     return ucRc ;
  153.  
  154.     /* check the length returned    */
  155.     if (Ncb.ncb_length < sizeof (FINDBUF) )
  156.     {
  157.     printf ("retcode: [%x] length: [%d]\n",Ncb.ncb_retcode, Ncb.ncb_length );
  158.     return FALSE;
  159.     }
  160.  
  161.     /* cast FINDBUF pointer into the buffer */
  162.     pFindBuf = (FINDBUF *) ucBuffer;
  163.  
  164.     /*
  165.      * if any one workstation with supplied name responded,
  166.      * we return TRUE since the name supplied can be registered
  167.      * as a unique name or group name.
  168.      */
  169.  
  170.     if (pFindBuf->usNumResponding != 0)
  171.     {
  172.     printf("Responding: %d\n",pFindBuf->usNumResponding);
  173.     printf("status: %d\n", pFindBuf->ucStatus);
  174.     printf("hdr length: %d\n", pFindBuf->ucLanHeaderLength);
  175.     return TRUE;
  176.     }
  177.     return FALSE;
  178. }
  179.