home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IEEERS.ZIP / IEEERES.C next >
Text File  |  1992-11-20  |  8KB  |  194 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Module name :     IEEERES                                                 */
  4. /*                                                                            */
  5. /*  Function :        Provides SAPs and link stations info for a LAN adapter  */
  6. /*                                                                            */
  7. /*  Usage :           IEEERES [Adapter={0/1}]                                 */
  8. /*                                                                            */
  9. /*                    default: Adapter=0                                      */
  10. /*                                                                            */
  11. /*                    IEEERES                                                 */
  12. /*                                                                            */
  13. /*  Return codes :    0    if successful                                      */
  14. /*                    1    if a parameter was bad and/or Help was given       */
  15. /*                    x    if an IEEE CCB fails the ccb.retcode is returned   */
  16. /*                                                                            */
  17. /*  Author :          Franck Minssieux                                        */
  18. /*                                                                            */
  19. /******************************************************************************/
  20.  
  21. #define E32TO16
  22.  
  23. #include <stdio.h>
  24. #include <os2.h>
  25. #include <ctype.h>
  26. #include <string.h>
  27.  
  28.  
  29. /* Include programming language support declarations    */
  30.  
  31. #include "lan_7_c.h"   /* general typedefs */
  32. #include "lan_1_c.h"   /* DLC defines      */
  33. #include "lan_3_c.h"   /* CCB structures   */
  34. #include "lan_6_c.h"   /* ACSLAN external definitions */
  35.  
  36.  
  37. /*   program declarations   */
  38.  
  39. #define COMMAND_IN_PROCESS 0xFF
  40.  
  41. struct ccb_pt
  42.    {
  43.    struct command_control_block_dlr ccb;
  44.    struct dir_status_parms status;
  45.    };
  46.  
  47. address Bad_CCB_Ptr;
  48. byte ret_code;
  49. byte Lana;                      /* 0 or 1                             */
  50. byte PermAddr[6];               /* Burnt-in address of adapter        */
  51. byte NodeAddr[6];               /* Network address of adapter         */
  52. byte MaxSap;                    /* Maximum allowable SAPs             */
  53. byte OpenSap;                   /* Number of SAPs opened              */
  54. byte MaxSta;                    /* Maximum allowable link stations    */
  55. byte OpenSta;                   /* Number of link stations opened     */
  56. byte AvailSta;                  /* Number of link stations available  */
  57. struct ccb_pt workccb;
  58.  
  59.  
  60. /**************************************************************/
  61. /*                                                            */
  62. /*  dir_status  implements the IEEE DIR.STATUS function       */
  63. /*                                                            */
  64. /**************************************************************/
  65.  
  66. dir_status (ccb_parm,adapternum)
  67. struct ccb_pt *ccb_parm;
  68. byte adapternum;
  69. {
  70.         struct command_control_block_dlr *status_ccb;
  71.         struct dir_status_parms *pt;
  72.  
  73.         status_ccb=&ccb_parm->ccb;
  74.         pt=&ccb_parm->status;
  75.         memset (status_ccb,0,sizeof(struct command_control_block_dlr));
  76.  
  77.         status_ccb->ccb_command     = LLC_DIR_STATUS;
  78.         status_ccb->ccb_adapter     = adapternum;
  79.         status_ccb->ccb_retcode     = COMMAND_IN_PROCESS;
  80.         status_ccb->parm_1.ccb_parm_offset = (address) pt;
  81.  
  82.         memset(pt,0,sizeof(struct dir_status_parms));
  83.  
  84.         ACSLAN((char *)status_ccb,(char *)&Bad_CCB_Ptr);
  85.         while (status_ccb->ccb_retcode==COMMAND_IN_PROCESS);
  86.         return;
  87. }
  88.  
  89.  
  90. /**************************************************************/
  91. /*                                                            */
  92. /*  Help        Displays directions for running this program  */
  93. /*                                                            */
  94. /**************************************************************/
  95.  
  96. Help()
  97. {
  98.         puts( " " );
  99.         puts( " The syntax is:           ");
  100.         puts( "                          ");
  101.         puts( " IEEERES [Adapter={0|1}]  ");
  102.         puts( "                          ");
  103.         puts( " default: Adapter=0       ");
  104.         puts( " ");
  105.         return;
  106. }
  107.  
  108.  
  109. /**************************************************************/
  110. /*                                                            */
  111. /*                  Main Program                              */
  112. /*                                                            */
  113. /**************************************************************/
  114.  
  115. main(argc,argv)
  116. int argc;
  117. char *argv[];
  118. {
  119.         char *cp;
  120.         byte i;
  121.  
  122.         if (argc==1)
  123.                 Lana=0;
  124.         else    {
  125.                 if (argc!=2)  {
  126.                         help();
  127.                         exit(1);
  128.                 }
  129.  
  130.                 cp = argv[1];
  131.  
  132.                 switch(toupper(*cp))    {
  133.  
  134.                         case 'A':       cp = strchr(cp,'=');
  135.                                         if (!*cp) {
  136.                                             printf("\nBad adapter number\n");
  137.                                             exit(1);
  138.                                         }
  139.                                         if (*++cp=='0')
  140.                                             Lana=0;
  141.                                         else if (*cp=='1')
  142.                                             Lana=1;
  143.                                         else {
  144.                                             printf("\nBad adapter number\n");
  145.                                             exit(1);
  146.                                         }
  147.                                         break;
  148.  
  149.                         case '?':       help();
  150.                                         exit(1);
  151.  
  152.                          default:       printf("\nUnknown parameter on command line: %s\n",cp);
  153.                                         help();
  154.                                         exit(1);
  155.                 }
  156.         }
  157.  
  158.         printf("\nReading the adapter information...\n");
  159.  
  160.         /****************************************************************/
  161.         /*    Get the SAPs and link stations info for the adapter       */
  162.         /****************************************************************/
  163.  
  164.         dir_status(&workccb,Lana);
  165.  
  166.         ret_code=workccb.ccb.ccb_retcode;
  167.         if (ret_code!=LLC_COMMAND_ACCEPTED && ret_code!=LLC_COMMAND_CMPL_NOT_OPENED) {
  168.                 printf("\nError %2X\n",ret_code);
  169.                 exit (ret_code);
  170.         }
  171.         memcpy(PermAddr,workccb.status.burned_in_addr,6);
  172.         memcpy(NodeAddr,workccb.status.node_address,6);
  173.         MaxSap=workccb.status.max_sap;
  174.         OpenSap=workccb.status.open_sap;
  175.         MaxSta=workccb.status.max_station;
  176.         OpenSta=workccb.status.open_station;
  177.         AvailSta=workccb.status.avail_station;
  178.  
  179.         printf("\nThe burned-in address of LAN adapter %u is ",Lana);
  180.         for(i=0;i<6;++i)
  181.                 printf("%02X",PermAddr[i]);
  182.         printf("\nThe current network address of LAN adapter %u is ",Lana);
  183.         for(i=0;i<6;++i)
  184.                 printf("%02X",NodeAddr[i]);
  185.         printf("\n");
  186.         printf("\nThe Maximum number of allowable SAPs is %d",MaxSap);
  187.         printf("\nThe Number of opened SAPs is %d",OpenSap);
  188.         printf("\nThe Maximum number of allowable link stations is %d",MaxSta);
  189.         printf("\nThe Number of opened link stations is %d",OpenSta);
  190.         printf("\nThe Number of available link stations is %d",AvailSta);
  191.         printf("\n");
  192.         exit(0);
  193. }
  194.