home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETLSTNM.C < prev    next >
Text File  |  1992-03-11  |  2KB  |  90 lines

  1. /* netlstnm.c - list NETBIOS names
  2.  * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
  3.  * Division of Cancer Prevention & Control, NCI
  4.  */
  5.  
  6. /* Revision history:
  7.  * 1.01  ytm  01/31/91  eliminate post routine
  8.  * 1.00  ytm  01/31/91  first release
  9.  */
  10.  
  11. /* Program notes:
  12.  * Current versions are specific for TurboC.
  13.  */
  14.  
  15. #include <local.h>                      /* standard definitions */
  16. #include "netbios.h"
  17.  
  18. /* status structure */
  19. #define STATUS_UNKNOWN 0xff
  20. #define STATUS_STRUCT struct status
  21. typedef STATUS_STRUCT
  22.   {
  23.   word   wCode;
  24.   string sText;
  25.   };
  26. STATUS_STRUCT aStatus[] =
  27.   {
  28.   {0,  "OK"},
  29.   {STATUS_UNKNOWN, "?"}
  30.   };
  31.  
  32. /* globals */
  33. NB_STATUS Nb;
  34. NCB       Ncb;
  35.  
  36. /* function prototypes */
  37. short main(short argc, string argv[]);
  38. word NetAdapterStatus(string sName);
  39.  
  40. /* check the adapter status */
  41. word NetAdapterStatus(string sName)
  42. {
  43. string s, t;
  44. memset(&Ncb, 0, sizeof(NCB));
  45. Ncb.NCB_COMMAND = STATUS_WAIT;
  46. strncpy(Ncb.NCB_CALLNAME, sName, NETBIOS_NAME_LEN);
  47. for (s = Ncb.NCB_CALLNAME, t = s + NETBIOS_NAME_LEN - 1; s < t; s++)
  48.   *s = ((*s) ? toupper(*s) : ' ');
  49. Ncb.NCB_BUFFER = (void far *) &Nb;
  50. Ncb.NCB_LENGTH = sizeof(Nb);
  51. Ncb.NCB_CMD_CPLT = STATUS_UNKNOWN;
  52. _ES = FP_SEG(&Ncb);
  53. _BX = FP_OFF(&Ncb);
  54. _AX = 0x0100;
  55. geninterrupt(0x5c);
  56. return(Ncb.NCB_CMD_CPLT);
  57. } /* NetAdapterStatus */ 
  58.  
  59. /* main */
  60. short main(short argc, string argv[])
  61. {
  62. char   caAdapter[NETBIOS_NAME_LEN];
  63. short  i;
  64. word   wStatus;
  65. printf("Netlstnm v1.01\nNETBIOS names for ");
  66. memset(caAdapter, 0, NETBIOS_NAME_LEN);
  67. if (argc > 1)
  68.   {
  69.   strncpy(caAdapter, argv[1], NETBIOS_NAME_LEN);
  70.   printf("%s:\n", caAdapter);
  71.   }
  72. else
  73.   {
  74.   strcpy(caAdapter, "*");
  75.   printf("this computer:\n");
  76.   }
  77. if ((wStatus = NetAdapterStatus(caAdapter)) == 0)
  78.   {
  79.   for (i = 0; i < Nb.wNames; i++)
  80.     printf("%s %d\n", Nb.aNameEntry[i].caName,
  81.                     Nb.aNameEntry[i].byNcbNum);
  82.   }
  83. for (i = 0; *(aStatus[i].sText) != '?'; i++)
  84.   if (aStatus[i].wCode == wStatus) break;
  85. printf("Netlstnm status: %s (%d)\n", aStatus[i].sText, Ncb.NCB_CMD_CPLT);
  86. return(i);
  87. } /* main */
  88.  
  89.  
  90.