home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / manage / snmp / mit / bsd / icmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  4.6 KB  |  229 lines

  1.  
  2. /*
  3.  *    $Header: icmp.c,v 3.0 91/05/17 16:14:18 jrd Rel $
  4.  *    Author: J. Davin
  5.  *    Copyright 1988, 1989, Massachusetts Institute of Technology
  6.  *    See permission and disclaimer notice in file "notice.h"
  7.  */
  8.  
  9. #include    <notice.h>
  10.  
  11. #include    <sys/types.h>
  12. #include    <netinet/in.h>
  13. #include    <netinet/in_systm.h>
  14. #include    <netinet/ip.h>
  15. #include    <netinet/ip_icmp.h>
  16. #include    <netinet/icmp_var.h>
  17. #include    <nlist.h>
  18.  
  19. #include    <ctypes.h>
  20. #include    <error.h>
  21. #include    <local.h>
  22. #include    <icmp.h>
  23. #include    <mix.h>
  24. #include    <mis.h>
  25. #include    <asn.h>
  26.  
  27. #include    <kmem.h>
  28.  
  29. static    CUnslType        icmpAddr;
  30. static    char            *icmpXlate = "\3\13\14\4\5\10\0\15\16\21\22";
  31.  
  32. static    AsnIdType    icmpRetrieve (item)
  33.  
  34. CIntfType        item;
  35.  
  36. {
  37.     struct    icmpstat    statBuf;
  38.     CUnslType        counter;
  39.     AsnIdType        result;
  40.     CIntfType        i;
  41.  
  42.     if (kmemRead ((CBytePtrType) & statBuf, (CIntfType) sizeof (statBuf),
  43.         icmpAddr) != (CIntfType) sizeof (statBuf)) {
  44.         result = (AsnIdType) 0;
  45.     }
  46.     else {
  47.         if (item == (CIntfType) 1) {
  48.             counter = (CUnslType) 0;
  49.             counter += (CUnslType) statBuf.icps_badcode;
  50.             counter += (CUnslType) statBuf.icps_tooshort;
  51.             counter += (CUnslType) statBuf.icps_checksum;
  52.             counter += (CUnslType) statBuf.icps_badlen;
  53.             for (i = 0; i < ICMP_MAXTYPE; i++) {
  54.                 counter += (CUnslType)
  55.                     statBuf.icps_inhist [ i ];
  56.             }
  57.         }
  58.         else if (item == (CIntfType) 2) {
  59.             counter = (CUnslType) 0;
  60.             counter += (CUnslType) statBuf.icps_badcode;
  61.             counter += (CUnslType) statBuf.icps_tooshort;
  62.             counter += (CUnslType) statBuf.icps_checksum;
  63.             counter += (CUnslType) statBuf.icps_badlen;
  64.         }
  65.         else if (item < (CIntfType) 14) {
  66.             counter = (CUnslType) statBuf.icps_inhist
  67.                 [ (int) icmpXlate [ (int) item - 3 ] ];
  68.         }
  69.         else if (item == (CIntfType) 14) {
  70.             counter = (CUnslType) 0;
  71.             counter += (CUnslType) statBuf.icps_error;
  72.             counter += (CUnslType) statBuf.icps_oldicmp;
  73.             for (i = 0; i < ICMP_MAXTYPE; i++) {
  74.                 counter += (CUnslType)
  75.                     statBuf.icps_inhist [ i ];
  76.             }
  77.         }
  78.         else if (item == (CIntfType) 15) {
  79.             counter = (CUnslType) 0;
  80.             counter += (CUnslType) statBuf.icps_error;
  81.             counter += (CUnslType) statBuf.icps_oldicmp;
  82.         }
  83.         else {
  84.             counter = (CUnslType) statBuf.icps_outhist
  85.                 [ (int) icmpXlate [ (int) item - 16 ] ];
  86.         }
  87.  
  88.         result = asnUnsl (asnClassApplication, (AsnTagType) 1,
  89.             counter);
  90.     }
  91.  
  92.     return (result);
  93. }
  94.  
  95. static    MixStatusType    icmpRelease (cookie)
  96.  
  97. MixCookieType        cookie;
  98.  
  99. {
  100.     cookie = cookie;
  101.     return (smpErrorGeneric);
  102. }
  103.  
  104. static    MixStatusType    icmpCreate (cookie, name, namelen, asn)
  105.  
  106. MixCookieType        cookie;
  107. MixNamePtrType        name;
  108. MixLengthType        namelen;
  109. AsnIdType        asn;
  110.  
  111. {
  112.     cookie = cookie;
  113.     name = name;
  114.     namelen = namelen;
  115.     asn = asn;
  116.     return (smpErrorGeneric);
  117. }
  118.  
  119. static    MixStatusType    icmpDestroy (cookie, name, namelen)
  120.  
  121. MixCookieType        cookie;
  122. MixNamePtrType        name;
  123. MixLengthType        namelen;
  124.  
  125. {
  126.     cookie = cookie;
  127.     name = name;
  128.     namelen = namelen;
  129.     return (smpErrorGeneric);
  130. }
  131.  
  132. static    AsnIdType    icmpGet (cookie, name, namelen)
  133.  
  134. MixCookieType        cookie;
  135. MixNamePtrType        name;
  136. MixLengthType        namelen;
  137.  
  138. {
  139.     CIntfType        item;
  140.  
  141.     cookie = cookie;
  142.     if ((namelen != (MixLengthType) 2) ||
  143.         ((item = (CIntfType) *name) < (CIntfType) 1) ||
  144.         (item > (CIntfType) 26) || (*(name + 1) != (MixNameType) 0)) {
  145.         return ((AsnIdType) 0);
  146.     }
  147.     else {
  148.         return (icmpRetrieve (item));
  149.     }
  150. }
  151.  
  152. static    MixStatusType    icmpSet (cookie, name, namelen, asn)
  153.  
  154. MixCookieType        cookie;
  155. MixNamePtrType        name;
  156. MixLengthType        namelen;
  157. AsnIdType        asn;
  158.  
  159. {
  160.     cookie = cookie;
  161.     name = name;
  162.     namelen = namelen;
  163.     asn = asn;
  164.     return (smpErrorReadOnly);
  165. }
  166.  
  167. static    AsnIdType    icmpNext (cookie, name, namelenp)
  168.  
  169. MixCookieType        cookie;
  170. MixNamePtrType        name;
  171. MixLengthPtrType    namelenp;
  172.  
  173. {
  174.     CIntfType        item;
  175.  
  176.     cookie = cookie;
  177.     if (*namelenp == (MixLengthType) 0) {
  178.         *namelenp = (MixLengthType) 2;
  179.         *name++ = (MixNameType) 1;
  180.         *name = (MixNameType) 0;
  181.         return (icmpRetrieve ((CIntfType) 1));
  182.     }
  183.     else if (*namelenp == (MixLengthType) 1) {
  184.         if ((item = (CIntfType) *name) <= (CIntfType) 26) {
  185.             *namelenp = (MixLengthType) 2;
  186.             *(++name) = (MixNameType) 0;
  187.             return (icmpRetrieve (item));
  188.         }
  189.         else {
  190.             return ((AsnIdType) 0);
  191.         }
  192.     }
  193.     else if ((item = (CIntfType) *name) < (CIntfType) 26) {
  194.         *namelenp = (MixLengthType) 2;
  195.         *name++ = (MixNameType) (++item);
  196.         *name = (MixNameType) 0;
  197.         return (icmpRetrieve (item));
  198.     }
  199.     else {
  200.         return ((AsnIdType) 0);
  201.     }
  202. }
  203.  
  204. static    MixOpsType    icmpOps = {
  205.  
  206.             icmpRelease,
  207.             icmpCreate,
  208.             icmpDestroy,
  209.             icmpNext,
  210.             icmpGet,
  211.             icmpSet
  212.  
  213.             };
  214.  
  215. CVoidType        icmpInit ()
  216.  
  217. {
  218.     struct        nlist        nl [ 2 ];
  219.  
  220.     nl [ 0 ].n_name = "_icmpstat";
  221.     nl [ 1 ].n_name = (char *) 0;
  222.     if (nlist ("/vmunix", nl) == 0) {
  223.         icmpAddr = (CUnslType) nl [ 0 ].n_value;
  224.         (void) misExport ((MixNamePtrType) "\53\6\1\2\1\5",
  225.             (MixLengthType) 6, & icmpOps, (MixCookieType) 0);
  226.     }
  227. }
  228.  
  229.