home *** CD-ROM | disk | FTP | other *** search
/ Doom Fever / Doom_Fever-1995_Maple_Media.iso / dmutil / drivers.zip / IPXSTAT.C < prev    next >
C/C++ Source or Header  |  1990-07-23  |  4KB  |  145 lines

  1. /*
  2.  * IPXSTAT - display statistics from the IPXPKT driver
  3.  * Compile with: tcc -ml -eipxstat ipxstat.c
  4.  * Usage: ipxstat <vector_num>
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10.  
  11. #ifndef VERSION
  12. #define VERSION    2
  13. #endif
  14.  
  15. struct rte {
  16. #if VERSION > 1
  17.     unsigned char rt_ether[6];
  18. #endif
  19.     unsigned char rt_net[4];
  20.     unsigned char rt_node[6];
  21.     unsigned char rt_gate[6];
  22.     unsigned char rt_x_type;
  23.     unsigned int rt_use;
  24. };
  25.  
  26. struct ipxstat {
  27.     unsigned long queue_full;
  28.     unsigned long route_drop;
  29.     unsigned long scache_miss;
  30.     unsigned long rcache_miss;
  31.     unsigned long route_loops;
  32.     unsigned long route_lookups;
  33. };
  34.  
  35. static int version = VERSION;
  36.  
  37. atoh(s)
  38. char *s;
  39. /* from KA9Q, netuser.c */
  40. {
  41.     int ret = 0;
  42.     char c;
  43.     while((c = *s++) != '\0'){
  44.         c &= 0x7f;
  45.         if(c == 'x')
  46.             continue;    /* Ignore 'x', e.g., '0x' prefixes */
  47.         if(c >= '0' && c <= '9')
  48.             ret = ret*16 + (c - '0');
  49.         else if(c >= 'a' && c <= 'f')
  50.             ret = ret*16 + (10 + c - 'a');
  51.         else if(c >= 'A' && c <= 'F')
  52.             ret = ret*16 + (10 + c - 'A');
  53.         else
  54.             break;
  55.     }
  56.     return ret;
  57. }
  58.  
  59. main(argc, argv)
  60. int argc;
  61. char *argv[];
  62. {
  63.     int i, int_no, rt_count;
  64.     char far *(far *interrupts)[];
  65.     struct rte far *rte, far *rte_end;
  66.     struct ipxstat far *ipxstat;
  67.  
  68.     interrupts = (char far *(far *)[]) 0;
  69.  
  70.     if (argc < 2) {
  71.         printf("Give int no\n");
  72.         exit(1);
  73.     }
  74.     if (strncmp("0x", argv[1], 2) == 0)
  75.         int_no = atoh(argv[1]+2);
  76.     else
  77.         int_no = atoi(argv[1]);
  78.     if (strcmp((*interrupts)[int_no] + 3, "PKT DRVR")) {
  79.         printf("No signature at %#x\n", int_no);
  80.         exit(1);
  81.     }
  82.  
  83.     for (i=0; i<10000; i++)
  84.         if (strcmp((*interrupts)[int_no] + i, "RTE_TABL") == 0) break;
  85.  
  86.     printf("RTE found at %4x:%4x\n", FP_SEG((*interrupts)[int_no]+i),
  87.                      FP_OFF((*interrupts)[int_no]+i));
  88.  
  89.     i += sizeof("RTE_TABL");
  90.     rt_count = * ((*interrupts)[int_no] + i);
  91.     printf("Max route entries: %d\n", rt_count);
  92.     rte = (struct rte far *) ((*interrupts)[int_no] + i + 1);
  93.     rte_end = (struct rte far *) MK_FP(FP_SEG(rte), *(int far *)(rte + rt_count));
  94.  
  95.     printf("RTE end at %4x:%4x\n", FP_SEG(rte_end), FP_OFF(rte_end));
  96.  
  97. #if VERSION < 2
  98.     printf("Net          Node               Gate               Type Age\n");
  99. #else
  100.     printf("Ether              Net          Node               Gate               Type Age\n");
  101. #endif
  102.  
  103.     for (; rte < rte_end; rte++)
  104.  
  105. #if VERSION < 2
  106.         printf("%02x:%02x:%02x:%02x  %02x:%02x:%02x:%02x:%02x:%02x  %02x:%02x:%02x:%02x:%02x:%02x  %2x  %u\n",
  107.         rte->rt_net[0], rte->rt_net[1], rte->rt_net[2], rte->rt_net[3],
  108.         rte->rt_node[0], rte->rt_node[1], rte->rt_node[2],
  109.         rte->rt_node[3], rte->rt_node[4], rte->rt_node[5],
  110.         rte->rt_gate[0], rte->rt_gate[1], rte->rt_gate[2],
  111.         rte->rt_gate[3], rte->rt_gate[4], rte->rt_gate[5],
  112.         rte->rt_x_type, rte->rt_use);
  113. #else
  114.         printf("%02x:%02x:%02x:%02x:%02x:%02x  %02x:%02x:%02x:%02x  %02x:%02x:%02x:%02x:%02x:%02x  %02x:%02x:%02x:%02x:%02x:%02x  %2x  %u\n",
  115.         rte->rt_ether[0], rte->rt_ether[1], rte->rt_ether[2],
  116.         rte->rt_ether[3], rte->rt_ether[4], rte->rt_ether[5],
  117.         rte->rt_net[0], rte->rt_net[1], rte->rt_net[2], rte->rt_net[3],
  118.         rte->rt_node[0], rte->rt_node[1], rte->rt_node[2],
  119.         rte->rt_node[3], rte->rt_node[4], rte->rt_node[5],
  120.         rte->rt_gate[0], rte->rt_gate[1], rte->rt_gate[2],
  121.         rte->rt_gate[3], rte->rt_gate[4], rte->rt_gate[5],
  122.         rte->rt_x_type, rte->rt_use);
  123. #endif
  124.  
  125. /* next the stats */
  126.     for (i=0; i<10000; i++)
  127.         if (strcmp((*interrupts)[int_no] + i, "IPXSTAT") == 0) break;
  128.     if (i>=10000) printf("STATS not found\n"), exit(1);
  129.  
  130.     printf("STATS found at %04x:%04x\n", FP_SEG((*interrupts)[int_no]+i),
  131.                      FP_OFF((*interrupts)[int_no]+i));
  132.  
  133.     i += sizeof("IPXSTAT");
  134.     ipxstat = (struct ipxstat *) ((*interrupts)[int_no] + i);
  135.     printf("IPX stats.\n");
  136.     printf("queue full: %lu\n", ipxstat->queue_full);
  137.     printf("route drops: %lu\n", ipxstat->route_drop);
  138.     printf("send cache misses: %lu\n", ipxstat->scache_miss);
  139.     printf("receive cache misses: %lu\n", ipxstat->rcache_miss);
  140.     printf("total route lookups: %lu, loops: %lu, (%f loops/lookup)\n",
  141.         ipxstat->route_lookups, ipxstat->route_loops,
  142.         (float) (ipxstat->route_loops) / (float) (ipxstat->route_lookups?ipxstat->route_lookups:1));
  143.  
  144. }
  145.