home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / lists / redrlst / net.c next >
Encoding:
C/C++ Source or Header  |  1988-08-29  |  1.8 KB  |  74 lines

  1.  
  2. #include <stdio.h>
  3. #include <dos.h>
  4.  
  5. /*
  6.  *    List all network devices for networked PCs using NETBIOS
  7.  *    (tested on 3Com nets only, though info was taken from the DOS
  8.  *    tech reference)
  9.  *
  10.  *    Feel free to pillage and plunder this code fragment as you see
  11.  *    fit.
  12.  *
  13.  *    D. Cornejo; TPCC; PO Box 501, Herndon, VA 22070
  14.  */
  15.  
  16. /* make sure the necessary pointers are long pointers */
  17. #define FAR far
  18.  
  19. /* prototype for the NETBIOS access function */
  20. int GetRedirList (int index, char * FAR localname, char * FAR netname, int * FAR type);
  21.  
  22. void main (void)
  23. {
  24.      char locbuf[128], netbuf[128];
  25.      int type;
  26.      int cy;
  27.      int index;
  28.      char *devtyp;
  29.  
  30.      cy = 0;
  31.      index = 0;
  32.      while ((index < 256) && (cy == 0)) {
  33.       cy = GetRedirList (index, locbuf, netbuf, &type);
  34.       if (cy == 0) {
  35.            switch (type) {
  36.            case 3:
  37.             devtyp = "Print";
  38.             break;
  39.            case 4:
  40.             devtyp = "Drive";
  41.             break;
  42.            default:
  43.             devtyp = "Unknown";
  44.            }
  45.  
  46.            printf ("[%d] %s: local name='%s' net name='%s'\n",
  47.                index, devtyp, locbuf, netbuf);
  48.       }
  49.       index++;
  50.      }
  51. }
  52.  
  53. int GetRedirList (int index, char * FAR localname, char * FAR netname, int * FAR type)
  54. {
  55.      /* read the local name, network name, and device type for entry <index> */
  56.  
  57.      union REGS junk;
  58.      struct SREGS sjunk;
  59.  
  60.      junk.x.ax = 0x5f02;    /* function call 5f (subfunction 2) */
  61.      junk.x.bx = index;        /* index of entry in redir table */
  62.  
  63.      sjunk.ds = FP_SEG (localname);    /* pointer to local name buf */
  64.      junk.x.si = FP_OFF (localname);
  65.  
  66.      sjunk.es = FP_SEG (netname);    /* pointer to net name buf */
  67.      junk.x.di = FP_OFF (netname);
  68.  
  69.      intdosx (&junk, &junk, &sjunk);    /* make the call */
  70.  
  71.      *type = junk.x.bx;
  72.      return (junk.x.cflag);    /* return the carry flag */
  73. }
  74.