icmp.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:21k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  *  ICMP MIB group implementation - icmp.c
  3.  *
  4.  */
  5. #include <net-snmp/net-snmp-config.h>
  6. #include "mibII_common.h"
  7. #if HAVE_NETINET_IP_ICMP_H
  8. #include <netinet/ip_icmp.h>
  9. #endif
  10. #if HAVE_NETINET_ICMP_VAR_H
  11. #include <netinet/icmp_var.h>
  12. #endif
  13. #include <net-snmp/net-snmp-includes.h>
  14. #include <net-snmp/agent/net-snmp-agent-includes.h>
  15. #include <net-snmp/agent/auto_nlist.h>
  16. #include <net-snmp/agent/cache_handler.h>
  17. #include <net-snmp/agent/scalar_group.h>
  18. #include "util_funcs.h"
  19. #include "icmp.h"
  20. #include "sysORTable.h"
  21. #ifndef MIB_STATS_CACHE_TIMEOUT
  22. #define MIB_STATS_CACHE_TIMEOUT 5
  23. #endif
  24. #ifndef ICMP_STATS_CACHE_TIMEOUT
  25. #define ICMP_STATS_CACHE_TIMEOUT MIB_STATS_CACHE_TIMEOUT
  26. #endif
  27.         /*********************
  28.  *
  29.  *  Kernel & interface information,
  30.  *   and internal forward declarations
  31.  *
  32.  *********************/
  33.         /*********************
  34.  *
  35.  *  Initialisation & common implementation functions
  36.  *
  37.  *********************/
  38. /*
  39.  * Define the OID pointer to the top of the mib tree that we're
  40.  * registering underneath 
  41.  */
  42. oid             icmp_oid[] = { SNMP_OID_MIB2, 5 };
  43. #ifdef USING_MIBII_IP_MODULE
  44. extern oid      ip_module_oid[];
  45. extern int      ip_module_oid_len;
  46. extern int      ip_module_count;
  47. #endif
  48. void
  49. init_icmp(void)
  50. {
  51.     netsnmp_handler_registration *reginfo;
  52.     /*
  53.      * register ourselves with the agent as a group of scalars...
  54.      */
  55.     DEBUGMSGTL(("mibII/icmp", "Initialising ICMP groupn"));
  56.     reginfo = netsnmp_create_handler_registration("icmp", icmp_handler,
  57.     icmp_oid, OID_LENGTH(icmp_oid), HANDLER_CAN_RONLY);
  58.     netsnmp_register_scalar_group(reginfo, ICMPINMSGS, ICMPOUTADDRMASKREPS);
  59.     /*
  60.      * .... with a local cache
  61.      *    (except for HP-UX 11, which extracts objects individually)
  62.      */
  63. #ifndef hpux11
  64.     netsnmp_inject_handler( reginfo,
  65.     netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,
  66.     icmp_load, icmp_free,
  67. icmp_oid, OID_LENGTH(icmp_oid)));
  68. #endif
  69. #ifdef USING_MIBII_IP_MODULE
  70.     if (++ip_module_count == 2)
  71.         REGISTER_SYSOR_TABLE(ip_module_oid, ip_module_oid_len,
  72.                              "The MIB module for managing IP and ICMP implementations");
  73. #endif
  74. #ifdef ICMPSTAT_SYMBOL
  75.     auto_nlist(ICMPSTAT_SYMBOL, 0, 0);
  76. #endif
  77. #ifdef solaris2
  78.     init_kernel_sunos5();
  79. #endif
  80. }
  81.         /*********************
  82.  *
  83.  *  System specific data formats
  84.  *
  85.  *********************/
  86. #ifdef hpux11
  87. #define ICMP_STAT_STRUCTURE int
  88. #endif
  89. #ifdef linux
  90. #define ICMP_STAT_STRUCTURE struct icmp_mib
  91. #define USES_SNMP_DESIGNED_ICMPSTAT
  92. #undef ICMPSTAT_SYMBOL
  93. #endif
  94. #ifdef solaris2
  95. #define ICMP_STAT_STRUCTURE mib2_icmp_t
  96. #define USES_SNMP_DESIGNED_ICMPSTAT
  97. #endif
  98. #if defined (WIN32) || defined (cygwin)
  99. #include <iphlpapi.h>
  100. #define ICMP_STAT_STRUCTURE MIB_ICMP
  101. #endif
  102. /* ?? #if (defined(CAN_USE_SYSCTL) && defined(ICMPCTL_STATS)) ?? */
  103. #ifdef HAVE_SYS_ICMPIPSTATS_H
  104. /* or #ifdef HAVE_SYS_TCPIPSTATS_H  ??? */
  105. #define ICMP_STAT_STRUCTURE struct kna
  106. #define USES_TRADITIONAL_ICMPSTAT
  107. #endif
  108. #if !defined(ICMP_STAT_STRUCTURE)
  109. #define ICMP_STAT_STRUCTURE struct icmpstat
  110. #define USES_TRADITIONAL_ICMPSTAT
  111. #endif
  112. ICMP_STAT_STRUCTURE icmpstat;
  113.         /*********************
  114.  *
  115.  *  System independent handler
  116.  *       (mostly!)
  117.  *
  118.  *********************/
  119. int
  120. icmp_handler(netsnmp_mib_handler          *handler,
  121.              netsnmp_handler_registration *reginfo,
  122.              netsnmp_agent_request_info   *reqinfo,
  123.              netsnmp_request_info         *requests)
  124. {
  125.     netsnmp_request_info  *request;
  126.     netsnmp_variable_list *requestvb;
  127.     long     ret_value;
  128.     oid      subid;
  129. #ifdef USES_TRADITIONAL_ICMPSTAT
  130.     int      i;
  131. #endif
  132.     /*
  133.      * The cached data should already have been loaded by the
  134.      *    cache handler, higher up the handler chain.
  135.      * But just to be safe, check this and load it manually if necessary
  136.      */
  137. #ifndef hpux11
  138.     if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {
  139.         netsnmp_assert("cache" == "valid"); /* always false */
  140.         icmp_load( NULL, NULL ); /* XXX - check for failure */
  141.     }
  142. #endif
  143.     /*
  144.      * 
  145.      *
  146.      */
  147.     DEBUGMSGTL(("mibII/icmp", "Handler - mode %sn",
  148.                     se_find_label_in_slist("agent_mode", reqinfo->mode)));
  149.     switch (reqinfo->mode) {
  150.     case MODE_GET:
  151.         for (request=requests; request; request=request->next) {
  152.             requestvb = request->requestvb;
  153.             subid = requestvb->name[OID_LENGTH(icmp_oid)];  /* XXX */
  154.             DEBUGMSGTL(( "mibII/icmp", "oid: "));
  155.             DEBUGMSGOID(("mibII/icmp", requestvb->name,
  156.                                        requestvb->name_length));
  157.             DEBUGMSG((   "mibII/icmp", "n"));
  158.             switch (subid) {
  159. #ifdef USES_SNMP_DESIGNED_ICMPSTAT
  160.     case ICMPINMSGS:
  161.         ret_value = icmpstat.icmpInMsgs;
  162.         break;
  163.     case ICMPINERRORS:
  164.         ret_value = icmpstat.icmpInErrors;
  165.         break;
  166.     case ICMPINDESTUNREACHS:
  167.         ret_value = icmpstat.icmpInDestUnreachs;
  168.         break;
  169.     case ICMPINTIMEEXCDS:
  170.         ret_value = icmpstat.icmpInTimeExcds;
  171.         break;
  172.     case ICMPINPARMPROBS:
  173.         ret_value = icmpstat.icmpInParmProbs;
  174.         break;
  175.     case ICMPINSRCQUENCHS:
  176.         ret_value = icmpstat.icmpInSrcQuenchs;
  177.         break;
  178.     case ICMPINREDIRECTS:
  179.         ret_value = icmpstat.icmpInRedirects;
  180.         break;
  181.     case ICMPINECHOS:
  182.         ret_value = icmpstat.icmpInEchos;
  183.         break;
  184.     case ICMPINECHOREPS:
  185.         ret_value = icmpstat.icmpInEchoReps;
  186.         break;
  187.     case ICMPINTIMESTAMPS:
  188.         ret_value = icmpstat.icmpInTimestamps;
  189.         break;
  190.     case ICMPINTIMESTAMPREPS:
  191.         ret_value = icmpstat.icmpInTimestampReps;
  192.         break;
  193.     case ICMPINADDRMASKS:
  194.         ret_value = icmpstat.icmpInAddrMasks;
  195.         break;
  196.     case ICMPINADDRMASKREPS:
  197.         ret_value = icmpstat.icmpInAddrMaskReps;
  198.         break;
  199.     case ICMPOUTMSGS:
  200.         ret_value = icmpstat.icmpOutMsgs;
  201.         break;
  202.     case ICMPOUTERRORS:
  203.         ret_value = icmpstat.icmpOutErrors;
  204.         break;
  205.     case ICMPOUTDESTUNREACHS:
  206.         ret_value = icmpstat.icmpOutDestUnreachs;
  207.         break;
  208.     case ICMPOUTTIMEEXCDS:
  209.         ret_value = icmpstat.icmpOutTimeExcds;
  210.         break;
  211.     case ICMPOUTPARMPROBS:
  212.         ret_value = icmpstat.icmpOutParmProbs;
  213.         break;
  214.     case ICMPOUTSRCQUENCHS:
  215.         ret_value = icmpstat.icmpOutSrcQuenchs;
  216.         break;
  217.     case ICMPOUTREDIRECTS:
  218.         ret_value = icmpstat.icmpOutRedirects;
  219.         break;
  220.     case ICMPOUTECHOS:
  221.         ret_value = icmpstat.icmpOutEchos;
  222.         break;
  223.     case ICMPOUTECHOREPS:
  224.         ret_value = icmpstat.icmpOutEchoReps;
  225.         break;
  226.     case ICMPOUTTIMESTAMPS:
  227.         ret_value = icmpstat.icmpOutTimestamps;
  228.         break;
  229.     case ICMPOUTTIMESTAMPREPS:
  230.         ret_value = icmpstat.icmpOutTimestampReps;
  231.         break;
  232.     case ICMPOUTADDRMASKS:
  233.         ret_value = icmpstat.icmpOutAddrMasks;
  234.         break;
  235.     case ICMPOUTADDRMASKREPS:
  236.         ret_value = icmpstat.icmpOutAddrMaskReps;
  237.         break;
  238. #else                          /* USES_SNMP_DESIGNED_ICMPSTAT */
  239. #ifdef USES_TRADITIONAL_ICMPSTAT
  240.     case ICMPINMSGS:
  241.         ret_value = icmpstat.icps_badcode +
  242.             icmpstat.icps_tooshort +
  243.             icmpstat.icps_checksum + icmpstat.icps_badlen;
  244.         for (i = 0; i <= ICMP_MAXTYPE; i++)
  245.             ret_value += icmpstat.icps_inhist[i];
  246.         break;
  247.     case ICMPINERRORS:
  248.         ret_value = icmpstat.icps_badcode +
  249.             icmpstat.icps_tooshort +
  250.             icmpstat.icps_checksum + icmpstat.icps_badlen;
  251.         break;
  252.     case ICMPINDESTUNREACHS:
  253.         ret_value = icmpstat.icps_inhist[ICMP_UNREACH];
  254.         break;
  255.     case ICMPINTIMEEXCDS:
  256.         ret_value = icmpstat.icps_inhist[ICMP_TIMXCEED];
  257.         break;
  258.     case ICMPINPARMPROBS:
  259.         ret_value = icmpstat.icps_inhist[ICMP_PARAMPROB];
  260.         break;
  261.     case ICMPINSRCQUENCHS:
  262.         ret_value = icmpstat.icps_inhist[ICMP_SOURCEQUENCH];
  263.         break;
  264.     case ICMPINREDIRECTS:
  265.         ret_value = icmpstat.icps_inhist[ICMP_REDIRECT];
  266.         break;
  267.     case ICMPINECHOS:
  268.         ret_value = icmpstat.icps_inhist[ICMP_ECHO];
  269.         break;
  270.     case ICMPINECHOREPS:
  271.         ret_value = icmpstat.icps_inhist[ICMP_ECHOREPLY];
  272.         break;
  273.     case ICMPINTIMESTAMPS:
  274.         ret_value = icmpstat.icps_inhist[ICMP_TSTAMP];
  275.         break;
  276.     case ICMPINTIMESTAMPREPS:
  277.         ret_value = icmpstat.icps_inhist[ICMP_TSTAMPREPLY];
  278.         break;
  279.     case ICMPINADDRMASKS:
  280.         ret_value = icmpstat.icps_inhist[ICMP_MASKREQ];
  281.         break;
  282.     case ICMPINADDRMASKREPS:
  283.         ret_value = icmpstat.icps_inhist[ICMP_MASKREPLY];
  284.         break;
  285.     case ICMPOUTMSGS:
  286.         ret_value = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;
  287.         for (i = 0; i <= ICMP_MAXTYPE; i++)
  288.             ret_value += icmpstat.icps_outhist[i];
  289.         break;
  290.     case ICMPOUTERRORS:
  291.         ret_value = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;
  292.         break;
  293.     case ICMPOUTDESTUNREACHS:
  294.         ret_value = icmpstat.icps_outhist[ICMP_UNREACH];
  295.         break;
  296.     case ICMPOUTTIMEEXCDS:
  297.         ret_value = icmpstat.icps_outhist[ICMP_TIMXCEED];
  298.         break;
  299.     case ICMPOUTPARMPROBS:
  300.         ret_value = icmpstat.icps_outhist[ICMP_PARAMPROB];
  301.         break;
  302.     case ICMPOUTSRCQUENCHS:
  303.         ret_value = icmpstat.icps_outhist[ICMP_SOURCEQUENCH];
  304.         break;
  305.     case ICMPOUTREDIRECTS:
  306.         ret_value = icmpstat.icps_outhist[ICMP_REDIRECT];
  307.         break;
  308.     case ICMPOUTECHOS:
  309.         ret_value = icmpstat.icps_outhist[ICMP_ECHO];
  310.         break;
  311.     case ICMPOUTECHOREPS:
  312.         ret_value = icmpstat.icps_outhist[ICMP_ECHOREPLY];
  313.         break;
  314.     case ICMPOUTTIMESTAMPS:
  315.         ret_value = icmpstat.icps_outhist[ICMP_TSTAMP];
  316.         break;
  317.     case ICMPOUTTIMESTAMPREPS:
  318.         ret_value = icmpstat.icps_outhist[ICMP_TSTAMPREPLY];
  319.         break;
  320.     case ICMPOUTADDRMASKS:
  321.         ret_value = icmpstat.icps_outhist[ICMP_MASKREQ];
  322.         break;
  323.     case ICMPOUTADDRMASKREPS:
  324.         ret_value = icmpstat.icps_outhist[ICMP_MASKREPLY];
  325.         break;
  326. #else                          /* USES_TRADITIONAL_ICMPSTAT */
  327. #ifdef hpux11
  328.     case ICMPINMSGS:
  329.     case ICMPINERRORS:
  330.     case ICMPINDESTUNREACHS:
  331.     case ICMPINTIMEEXCDS:
  332.     case ICMPINPARMPROBS:
  333.     case ICMPINSRCQUENCHS:
  334.     case ICMPINREDIRECTS:
  335.     case ICMPINECHOS:
  336.     case ICMPINECHOREPS:
  337.     case ICMPINTIMESTAMPS:
  338.     case ICMPINTIMESTAMPREPS:
  339.     case ICMPINADDRMASKS:
  340.     case ICMPINADDRMASKREPS:
  341.     case ICMPOUTMSGS:
  342.     case ICMPOUTERRORS:
  343.     case ICMPOUTDESTUNREACHS:
  344.     case ICMPOUTTIMEEXCDS:
  345.     case ICMPOUTPARMPROBS:
  346.     case ICMPOUTSRCQUENCHS:
  347.     case ICMPOUTREDIRECTS:
  348.     case ICMPOUTECHOS:
  349.     case ICMPOUTECHOREPS:
  350.     case ICMPOUTTIMESTAMPS:
  351.     case ICMPOUTTIMESTAMPREPS:
  352.     case ICMPOUTADDRMASKS:
  353.     case ICMPOUTADDRMASKREPS:
  354. /*
  355.  * This is a bit of a hack, to shoehorn the HP-UX 11
  356.  * single-object retrieval approach into the caching
  357.  * architecture.
  358.  */
  359. if (icmp_load(NULL, (void*)subid) == -1 ) {
  360.             netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
  361.             continue;
  362. }
  363.         ret_value = icmpstat;
  364.         break;
  365. #else                          /* hpux11 */
  366. #if defined (WIN32) || defined (cygwin)
  367.     case ICMPINMSGS:
  368.         ret_value = icmpstat.stats.icmpInStats.dwMsgs;
  369.         break;
  370.     case ICMPINERRORS:
  371.         ret_value = icmpstat.stats.icmpInStats.dwErrors;
  372.         break;
  373.     case ICMPINDESTUNREACHS:
  374.         ret_value = icmpstat.stats.icmpInStats.dwDestUnreachs;
  375.         break;
  376.     case ICMPINTIMEEXCDS:
  377.         ret_value = icmpstat.stats.icmpInStats.dwTimeExcds;
  378.         break;
  379.     case ICMPINPARMPROBS:
  380.         ret_value = icmpstat.stats.icmpInStats.dwParmProbs;
  381.         break;
  382.     case ICMPINSRCQUENCHS:
  383.         ret_value = icmpstat.stats.icmpInStats.dwSrcQuenchs;
  384.         break;
  385.     case ICMPINREDIRECTS:
  386.         ret_value = icmpstat.stats.icmpInStats.dwRedirects;
  387.         break;
  388.     case ICMPINECHOS:
  389.         ret_value = icmpstat.stats.icmpInStats.dwEchos;
  390.         break;
  391.     case ICMPINECHOREPS:
  392.         ret_value = icmpstat.stats.icmpInStats.dwEchoReps;
  393.         break;
  394.     case ICMPINTIMESTAMPS:
  395.         ret_value = icmpstat.stats.icmpInStats.dwTimestamps;
  396.         break;
  397.     case ICMPINTIMESTAMPREPS:
  398.         ret_value = icmpstat.stats.icmpInStats.dwTimestampReps;
  399.         break;
  400.     case ICMPINADDRMASKS:
  401.         ret_value = icmpstat.stats.icmpInStats.dwAddrMasks;
  402.         break;
  403.     case ICMPINADDRMASKREPS:
  404.         ret_value = icmpstat.stats.icmpInStats.dwAddrMaskReps;
  405.         break;
  406.     case ICMPOUTMSGS:
  407.         ret_value = icmpstat.stats.icmpOutStats.dwMsgs;
  408.         break;
  409.     case ICMPOUTERRORS:
  410.         ret_value = icmpstat.stats.icmpOutStats.dwErrors;
  411.         break;
  412.     case ICMPOUTDESTUNREACHS:
  413.         ret_value = icmpstat.stats.icmpOutStats.dwDestUnreachs;
  414.         break;
  415.     case ICMPOUTTIMEEXCDS:
  416.         ret_value = icmpstat.stats.icmpOutStats.dwTimeExcds;
  417.         break;
  418.     case ICMPOUTPARMPROBS:
  419.         ret_value = icmpstat.stats.icmpOutStats.dwParmProbs;
  420.         break;
  421.     case ICMPOUTSRCQUENCHS:
  422.         ret_value = icmpstat.stats.icmpOutStats.dwSrcQuenchs;
  423.         break;
  424.     case ICMPOUTREDIRECTS:
  425.         ret_value = icmpstat.stats.icmpOutStats.dwRedirects;
  426.         break;
  427.     case ICMPOUTECHOS:
  428.         ret_value = icmpstat.stats.icmpOutStats.dwEchos;
  429.         break;
  430.     case ICMPOUTECHOREPS:
  431.         ret_value = icmpstat.stats.icmpOutStats.dwEchoReps;
  432.         break;
  433.     case ICMPOUTTIMESTAMPS:
  434.         ret_value = icmpstat.stats.icmpOutStats.dwTimestamps;
  435.         break;
  436.     case ICMPOUTTIMESTAMPREPS:
  437.         ret_value = icmpstat.stats.icmpOutStats.dwTimestampReps;
  438.         break;
  439.     case ICMPOUTADDRMASKS:
  440.         ret_value = icmpstat.stats.icmpOutStats.dwAddrMasks;
  441.         break;
  442.     case ICMPOUTADDRMASKREPS:
  443.         ret_value = icmpstat.stats.icmpOutStats.dwAddrMaskReps;
  444.         break;
  445. #endif                          /* WIN32 cygwin */
  446. #endif                          /* hpux11 */
  447. #endif                          /* USES_TRADITIONAL_ICMPSTAT */
  448. #endif                          /* USES_SNMP_DESIGNED_ICMPSTAT */
  449.     }
  450.     snmp_set_var_typed_value(request->requestvb, ASN_COUNTER,
  451.              (u_char *)&ret_value, sizeof(ret_value));
  452. }
  453.         break;
  454.     case MODE_GETNEXT:
  455.     case MODE_GETBULK:
  456.     case MODE_SET_RESERVE1:
  457.     case MODE_SET_RESERVE2:
  458.     case MODE_SET_ACTION:
  459.     case MODE_SET_COMMIT:
  460.     case MODE_SET_FREE:
  461.     case MODE_SET_UNDO:
  462.         snmp_log(LOG_WARNING, "mibII/icmp: Unsupported mode (%d)n",
  463.                                reqinfo->mode);
  464.         break;
  465.     default:
  466.         snmp_log(LOG_WARNING, "mibII/icmp: Unrecognised mode (%d)n",
  467.                                reqinfo->mode);
  468.         break;
  469.     }
  470.     return SNMP_ERR_NOERROR;
  471. }
  472.         /*********************
  473.  *
  474.  *  Internal implementation functions
  475.  *
  476.  *********************/
  477. #ifdef hpux11
  478. int
  479. icmp_load(netsnmp_cache *cache, void *vmagic)
  480. {
  481.     int             fd;
  482.     struct nmparms  p;
  483.     unsigned int    ulen;
  484.     int             ret;
  485.     int             magic = (int) vmagic;
  486.     if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) < 0) {
  487.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP object %d (hpux11)n", magic));
  488.         return (-1);            /* error */
  489.     }
  490.     switch (magic) {
  491.     case ICMPINMSGS:
  492.         p.objid = ID_icmpInMsgs;
  493.         break;
  494.     case ICMPINERRORS:
  495.         p.objid = ID_icmpInErrors;
  496.         break;
  497.     case ICMPINDESTUNREACHS:
  498.         p.objid = ID_icmpInDestUnreachs;
  499.         break;
  500.     case ICMPINTIMEEXCDS:
  501.         p.objid = ID_icmpInTimeExcds;
  502.         break;
  503.     case ICMPINPARMPROBS:
  504.         p.objid = ID_icmpInParmProbs;
  505.         break;
  506.     case ICMPINSRCQUENCHS:
  507.         p.objid = ID_icmpInSrcQuenchs;
  508.         break;
  509.     case ICMPINREDIRECTS:
  510.         p.objid = ID_icmpInRedirects;
  511.         break;
  512.     case ICMPINECHOS:
  513.         p.objid = ID_icmpInEchos;
  514.         break;
  515.     case ICMPINECHOREPS:
  516.         p.objid = ID_icmpInEchoReps;
  517.         break;
  518.     case ICMPINTIMESTAMPS:
  519.         p.objid = ID_icmpInTimestamps;
  520.         break;
  521.     case ICMPINTIMESTAMPREPS:
  522.         p.objid = ID_icmpInTimestampReps;
  523.         break;
  524.     case ICMPINADDRMASKS:
  525.         p.objid = ID_icmpInAddrMasks;
  526.         break;
  527.     case ICMPINADDRMASKREPS:
  528.         p.objid = ID_icmpInAddrMaskReps;
  529.         break;
  530.     case ICMPOUTMSGS:
  531.         p.objid = ID_icmpOutMsgs;
  532.         break;
  533.     case ICMPOUTERRORS:
  534.         p.objid = ID_icmpOutErrors;
  535.         break;
  536.     case ICMPOUTDESTUNREACHS:
  537.         p.objid = ID_icmpOutDestUnreachs;
  538.         break;
  539.     case ICMPOUTTIMEEXCDS:
  540.         p.objid = ID_icmpOutTimeExcds;
  541.         break;
  542.     case ICMPOUTPARMPROBS:
  543.         p.objid = ID_icmpOutParmProbs;
  544.         break;
  545.     case ICMPOUTSRCQUENCHS:
  546.         p.objid = ID_icmpOutSrcQuenchs;
  547.         break;
  548.     case ICMPOUTREDIRECTS:
  549.         p.objid = ID_icmpOutRedirects;
  550.         break;
  551.     case ICMPOUTECHOS:
  552.         p.objid = ID_icmpOutEchos;
  553.         break;
  554.     case ICMPOUTECHOREPS:
  555.         p.objid = ID_icmpOutEchoReps;
  556.         break;
  557.     case ICMPOUTTIMESTAMPS:
  558.         p.objid = ID_icmpOutTimestamps;
  559.         break;
  560.     case ICMPOUTTIMESTAMPREPS:
  561.         p.objid = ID_icmpOutTimestampReps;
  562.         break;
  563.     case ICMPOUTADDRMASKS:
  564.         p.objid = ID_icmpOutAddrMasks;
  565.         break;
  566.     case ICMPOUTADDRMASKREPS:
  567.         p.objid = ID_icmpOutAddrMaskReps;
  568.         break;
  569.     default:
  570.         icmpstat = 0;
  571.         close_mib(fd);
  572.         return (0);
  573.     }
  574.     p.buffer = (void *)&icmpstat;
  575.     ulen = sizeof(ICMP_STAT_STRUCTURE);
  576.     p.len = &ulen;
  577.     ret = get_mib_info(fd, &p);
  578.     close_mib(fd);
  579.     DEBUGMSGTL(("mibII/icmp", "%s ICMP object %d (hpux11)n",
  580.                (ret < 0 ? "Failed to load" : "Loaded"),  magic));
  581.     return (ret);               /* 0: ok, < 0: error */
  582. }
  583. #else                           /* hpux11 */
  584. #ifdef linux
  585. int
  586. icmp_load(netsnmp_cache *cache, void *vmagic)
  587. {
  588.     long            ret_value = -1;
  589.     ret_value = linux_read_icmp_stat(&icmpstat);
  590.     if ( ret_value < 0 ) {
  591.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (linux)n"));
  592.     } else {
  593.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (linux)n"));
  594.     }
  595.     return ret_value;
  596. }
  597. #else /* linux */
  598. #ifdef solaris2
  599. int
  600. icmp_load(netsnmp_cache *cache, void *vmagic)
  601. {
  602.     long            ret_value = -1;
  603.     ret_value =
  604.         getMibstat(MIB_ICMP, &icmpstat, sizeof(mib2_icmp_t), GET_FIRST,
  605.                    &Get_everything, NULL);
  606.     if ( ret_value < 0 ) {
  607.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (solaris)n"));
  608.     } else {
  609.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (solaris)n"));
  610.     }
  611.     return ret_value;
  612. }
  613. #else /* solaris2 */
  614. #if defined (WIN32) || defined (cygwin)
  615. int
  616. icmp_load(netsnmp_cache *cache, void *vmagic)
  617. {
  618.     long            ret_value = -1;
  619.     ret_value = GetIcmpStatistics(&icmpstat);
  620.     if ( ret_value < 0 ) {
  621.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (win32)n"));
  622.     } else {
  623.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (win32)n"));
  624.     }
  625.     return ret_value;
  626. }
  627. #else /* WIN32 cygwin */
  628. #if (defined(CAN_USE_SYSCTL) && defined(ICMPCTL_STATS))
  629. int
  630. icmp_load(netsnmp_cache *cache, void *vmagic)
  631. {
  632.     long            ret_value = -1;
  633.     static int      sname[4] =
  634.         { CTL_NET, PF_INET, IPPROTO_ICMP, ICMPCTL_STATS };
  635.     size_t          len = sizeof(icmpstat);
  636.     ret_value = sysctl(sname, 4, &icmpstat, &len, 0, 0);
  637.     if ( ret_value < 0 ) {
  638.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (sysctl)n"));
  639.     } else {
  640.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (sysctl)n"));
  641.     }
  642.     return ret_value;
  643. }
  644. #else /* CAN_USE_SYSCTL && ICMPCTL_STATS */
  645. #ifdef HAVE_SYS_TCPIPSTATS_H
  646. int
  647. icmp_load(netsnmp_cache *cache, void *vmagic)
  648. {
  649.     long            ret_value = -1;
  650.     ret_value =
  651.         sysmp(MP_SAGET, MPSA_TCPIPSTATS, &icmpstat, sizeof icmpstat);
  652.     if ( ret_value < 0 ) {
  653.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (tcpipstats)n"));
  654.     } else {
  655.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (tcpipstats)n"));
  656.     }
  657.     return ret_value;
  658. }
  659. #else /* HAVE_SYS_TCPIPSTATS_H */
  660. #ifdef ICMPSTAT_SYMBOL
  661. int
  662. icmp_load(netsnmp_cache *cache, void *vmagic)
  663. {
  664.     long            ret_value = -1;
  665.     if (auto_nlist(ICMPSTAT_SYMBOL, (char *)&icmpstat, sizeof(icmpstat)))
  666.         ret_value = 0;
  667.     if ( ret_value < 0 ) {
  668.         DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (icmpstat)n"));
  669.     } else {
  670.         DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (icmpstat)n"));
  671.     }
  672.     return ret_value;
  673. }
  674. #else /* ICMPSTAT_SYMBOL */
  675. int
  676. icmp_load(netsnmp_cache *cache, void *vmagic)
  677. {
  678.     long            ret_value = -1;
  679.     DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (null)n"));
  680.     return ret_value;
  681. }
  682. #endif /* ICMPSTAT_SYMBOL */
  683. #endif /* HAVE_SYS_TCPIPSTATS_H */
  684. #endif /* CAN_USE_SYSCTL && ICMPCTL_STATS */
  685. #endif /* WIN32 cygwin */
  686. #endif /* solaris2 */
  687. #endif /* linux */
  688. #endif /* hpux11 */
  689. void
  690. icmp_free(netsnmp_cache *cache, void *magic)
  691. {
  692.     memset(&icmpstat, 0, sizeof(icmpstat));
  693. }