⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icmp.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  ICMP MIB group implementation - icmp.c * */#include <net-snmp/net-snmp-config.h>#include "mibII_common.h"#if HAVE_NETINET_IP_ICMP_H#include <netinet/ip_icmp.h>#endif#if HAVE_NETINET_ICMP_VAR_H#include <netinet/icmp_var.h>#endif#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include <net-snmp/agent/auto_nlist.h>#include <net-snmp/agent/cache_handler.h>#include <net-snmp/agent/scalar_group.h>#include "util_funcs.h"#include "icmp.h"#include "sysORTable.h"#ifndef MIB_STATS_CACHE_TIMEOUT#define MIB_STATS_CACHE_TIMEOUT	5#endif#ifndef ICMP_STATS_CACHE_TIMEOUT#define ICMP_STATS_CACHE_TIMEOUT	MIB_STATS_CACHE_TIMEOUT#endif        /*********************	 *	 *  Kernel & interface information,	 *   and internal forward declarations	 *	 *********************/        /*********************	 *	 *  Initialisation & common implementation functions	 *	 *********************//* * Define the OID pointer to the top of the mib tree that we're * registering underneath  */oid             icmp_oid[] = { SNMP_OID_MIB2, 5 };#ifdef USING_MIBII_IP_MODULEextern oid      ip_module_oid[];extern int      ip_module_oid_len;extern int      ip_module_count;#endifvoidinit_icmp(void){    netsnmp_handler_registration *reginfo;    /*     * register ourselves with the agent as a group of scalars...     */    DEBUGMSGTL(("mibII/icmp", "Initialising ICMP group\n"));    reginfo = netsnmp_create_handler_registration("icmp", icmp_handler,		    icmp_oid, OID_LENGTH(icmp_oid), HANDLER_CAN_RONLY);    netsnmp_register_scalar_group(reginfo, ICMPINMSGS, ICMPOUTADDRMASKREPS);    /*     * .... with a local cache     *    (except for HP-UX 11, which extracts objects individually)     */#ifndef hpux11    netsnmp_inject_handler( reginfo,		    netsnmp_get_cache_handler(ICMP_STATS_CACHE_TIMEOUT,			   		icmp_load, icmp_free,					icmp_oid, OID_LENGTH(icmp_oid)));#endif#ifdef USING_MIBII_IP_MODULE    if (++ip_module_count == 2)        REGISTER_SYSOR_TABLE(ip_module_oid, ip_module_oid_len,                             "The MIB module for managing IP and ICMP implementations");#endif#ifdef ICMPSTAT_SYMBOL    auto_nlist(ICMPSTAT_SYMBOL, 0, 0);#endif#ifdef solaris2    init_kernel_sunos5();#endif}        /*********************	 *	 *  System specific data formats	 *	 *********************/#ifdef hpux11#define ICMP_STAT_STRUCTURE	int#endif#ifdef linux#define ICMP_STAT_STRUCTURE	struct icmp_mib#define USES_SNMP_DESIGNED_ICMPSTAT#undef ICMPSTAT_SYMBOL#endif#ifdef solaris2#define ICMP_STAT_STRUCTURE	mib2_icmp_t#define USES_SNMP_DESIGNED_ICMPSTAT#endif#ifdef WIN32#include <iphlpapi.h>#define ICMP_STAT_STRUCTURE MIB_ICMP#endif/* ?? #if (defined(CAN_USE_SYSCTL) && defined(ICMPCTL_STATS)) ?? */#ifdef HAVE_SYS_ICMPIPSTATS_H/* or #ifdef		HAVE_SYS_TCPIPSTATS_H  ??? */#define ICMP_STAT_STRUCTURE	struct kna#define USES_TRADITIONAL_ICMPSTAT#endif#if !defined(ICMP_STAT_STRUCTURE)#define ICMP_STAT_STRUCTURE	struct icmpstat#define USES_TRADITIONAL_ICMPSTAT#endifICMP_STAT_STRUCTURE icmpstat;        /*********************	 *	 *  System independent handler	 *       (mostly!)	 *	 *********************/inticmp_handler(netsnmp_mib_handler          *handler,             netsnmp_handler_registration *reginfo,             netsnmp_agent_request_info   *reqinfo,             netsnmp_request_info         *requests){    netsnmp_request_info  *request;    netsnmp_variable_list *requestvb;    long     ret_value;    oid      subid;#ifdef USES_TRADITIONAL_ICMPSTAT    int      i;#endif    /*     * The cached data should already have been loaded by the     *    cache handler, higher up the handler chain.     * But just to be safe, check this and load it manually if necessary     */#ifndef hpux11    if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {        netsnmp_assert("cache" == "valid"); /* always false */        icmp_load( NULL, NULL );	/* XXX - check for failure */    }#endif    /*     *      *     */    DEBUGMSGTL(("mibII/icmp", "Handler - mode %s\n",                    se_find_label_in_slist("agent_mode", reqinfo->mode)));    switch (reqinfo->mode) {    case MODE_GET:        for (request=requests; request; request=request->next) {            requestvb = request->requestvb;            subid = requestvb->name[OID_LENGTH(icmp_oid)];  /* XXX */            DEBUGMSGTL(( "mibII/icmp", "oid: "));            DEBUGMSGOID(("mibII/icmp", requestvb->name,                                       requestvb->name_length));            DEBUGMSG((   "mibII/icmp", "\n"));            switch (subid) {#ifdef USES_SNMP_DESIGNED_ICMPSTAT    case ICMPINMSGS:        ret_value = icmpstat.icmpInMsgs;        break;    case ICMPINERRORS:        ret_value = icmpstat.icmpInErrors;        break;    case ICMPINDESTUNREACHS:        ret_value = icmpstat.icmpInDestUnreachs;        break;    case ICMPINTIMEEXCDS:        ret_value = icmpstat.icmpInTimeExcds;        break;    case ICMPINPARMPROBS:        ret_value = icmpstat.icmpInParmProbs;        break;    case ICMPINSRCQUENCHS:        ret_value = icmpstat.icmpInSrcQuenchs;        break;    case ICMPINREDIRECTS:        ret_value = icmpstat.icmpInRedirects;        break;    case ICMPINECHOS:        ret_value = icmpstat.icmpInEchos;        break;    case ICMPINECHOREPS:        ret_value = icmpstat.icmpInEchoReps;        break;    case ICMPINTIMESTAMPS:        ret_value = icmpstat.icmpInTimestamps;        break;    case ICMPINTIMESTAMPREPS:        ret_value = icmpstat.icmpInTimestampReps;        break;    case ICMPINADDRMASKS:        ret_value = icmpstat.icmpInAddrMasks;        break;    case ICMPINADDRMASKREPS:        ret_value = icmpstat.icmpInAddrMaskReps;        break;    case ICMPOUTMSGS:        ret_value = icmpstat.icmpOutMsgs;        break;    case ICMPOUTERRORS:        ret_value = icmpstat.icmpOutErrors;        break;    case ICMPOUTDESTUNREACHS:        ret_value = icmpstat.icmpOutDestUnreachs;        break;    case ICMPOUTTIMEEXCDS:        ret_value = icmpstat.icmpOutTimeExcds;        break;    case ICMPOUTPARMPROBS:        ret_value = icmpstat.icmpOutParmProbs;        break;    case ICMPOUTSRCQUENCHS:        ret_value = icmpstat.icmpOutSrcQuenchs;        break;    case ICMPOUTREDIRECTS:        ret_value = icmpstat.icmpOutRedirects;        break;    case ICMPOUTECHOS:        ret_value = icmpstat.icmpOutEchos;        break;    case ICMPOUTECHOREPS:        ret_value = icmpstat.icmpOutEchoReps;        break;    case ICMPOUTTIMESTAMPS:        ret_value = icmpstat.icmpOutTimestamps;        break;    case ICMPOUTTIMESTAMPREPS:        ret_value = icmpstat.icmpOutTimestampReps;        break;    case ICMPOUTADDRMASKS:        ret_value = icmpstat.icmpOutAddrMasks;        break;    case ICMPOUTADDRMASKREPS:        ret_value = icmpstat.icmpOutAddrMaskReps;        break;#else                          /* USES_SNMP_DESIGNED_ICMPSTAT */#ifdef USES_TRADITIONAL_ICMPSTAT    case ICMPINMSGS:        ret_value = icmpstat.icps_badcode +            icmpstat.icps_tooshort +            icmpstat.icps_checksum + icmpstat.icps_badlen;        for (i = 0; i <= ICMP_MAXTYPE; i++)            ret_value += icmpstat.icps_inhist[i];        break;    case ICMPINERRORS:        ret_value = icmpstat.icps_badcode +            icmpstat.icps_tooshort +            icmpstat.icps_checksum + icmpstat.icps_badlen;        break;    case ICMPINDESTUNREACHS:        ret_value = icmpstat.icps_inhist[ICMP_UNREACH];        break;    case ICMPINTIMEEXCDS:        ret_value = icmpstat.icps_inhist[ICMP_TIMXCEED];        break;    case ICMPINPARMPROBS:        ret_value = icmpstat.icps_inhist[ICMP_PARAMPROB];        break;    case ICMPINSRCQUENCHS:        ret_value = icmpstat.icps_inhist[ICMP_SOURCEQUENCH];        break;    case ICMPINREDIRECTS:        ret_value = icmpstat.icps_inhist[ICMP_REDIRECT];        break;    case ICMPINECHOS:        ret_value = icmpstat.icps_inhist[ICMP_ECHO];        break;    case ICMPINECHOREPS:        ret_value = icmpstat.icps_inhist[ICMP_ECHOREPLY];        break;    case ICMPINTIMESTAMPS:        ret_value = icmpstat.icps_inhist[ICMP_TSTAMP];        break;    case ICMPINTIMESTAMPREPS:        ret_value = icmpstat.icps_inhist[ICMP_TSTAMPREPLY];        break;    case ICMPINADDRMASKS:        ret_value = icmpstat.icps_inhist[ICMP_MASKREQ];        break;    case ICMPINADDRMASKREPS:        ret_value = icmpstat.icps_inhist[ICMP_MASKREPLY];        break;    case ICMPOUTMSGS:        ret_value = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;        for (i = 0; i <= ICMP_MAXTYPE; i++)            ret_value += icmpstat.icps_outhist[i];        break;    case ICMPOUTERRORS:        ret_value = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;        break;    case ICMPOUTDESTUNREACHS:        ret_value = icmpstat.icps_outhist[ICMP_UNREACH];        break;    case ICMPOUTTIMEEXCDS:        ret_value = icmpstat.icps_outhist[ICMP_TIMXCEED];        break;    case ICMPOUTPARMPROBS:        ret_value = icmpstat.icps_outhist[ICMP_PARAMPROB];        break;    case ICMPOUTSRCQUENCHS:        ret_value = icmpstat.icps_outhist[ICMP_SOURCEQUENCH];        break;    case ICMPOUTREDIRECTS:        ret_value = icmpstat.icps_outhist[ICMP_REDIRECT];        break;    case ICMPOUTECHOS:        ret_value = icmpstat.icps_outhist[ICMP_ECHO];        break;    case ICMPOUTECHOREPS:        ret_value = icmpstat.icps_outhist[ICMP_ECHOREPLY];        break;    case ICMPOUTTIMESTAMPS:        ret_value = icmpstat.icps_outhist[ICMP_TSTAMP];        break;    case ICMPOUTTIMESTAMPREPS:        ret_value = icmpstat.icps_outhist[ICMP_TSTAMPREPLY];        break;    case ICMPOUTADDRMASKS:        ret_value = icmpstat.icps_outhist[ICMP_MASKREQ];        break;    case ICMPOUTADDRMASKREPS:        ret_value = icmpstat.icps_outhist[ICMP_MASKREPLY];        break;#else                          /* USES_TRADITIONAL_ICMPSTAT */#ifdef hpux11    case ICMPINMSGS:    case ICMPINERRORS:    case ICMPINDESTUNREACHS:    case ICMPINTIMEEXCDS:    case ICMPINPARMPROBS:    case ICMPINSRCQUENCHS:    case ICMPINREDIRECTS:    case ICMPINECHOS:    case ICMPINECHOREPS:    case ICMPINTIMESTAMPS:    case ICMPINTIMESTAMPREPS:    case ICMPINADDRMASKS:    case ICMPINADDRMASKREPS:    case ICMPOUTMSGS:    case ICMPOUTERRORS:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -