📄 icmp.c
字号:
/* * ICMP MIB group implementation - icmp.c * */#include <config.h>#if defined(IFNET_NEEDS_KERNEL) && !defined(_KERNEL)#define _KERNEL 1#define _I_DEFINED_KERNEL#endif#if HAVE_SYS_PARAM_H#include <sys/param.h>#endif#if HAVE_SYS_SOCKET_H#include <sys/socket.h>#endif#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#if HAVE_NETINET_IN_H#include <netinet/in.h>#endif#if HAVE_SYS_SYSMP_H#include <sys/sysmp.h>#endif#if HAVE_SYS_TCPIPSTATS_H#include <sys/tcpipstats.h>#endif#if HAVE_NET_IF_H#include <net/if.h>#endif#if HAVE_NET_IF_VAR_H#include <net/if_var.h>#endif#ifdef _I_DEFINED_KERNEL#undef _KERNEL#endif#if HAVE_NETINET_IN_SYSTM_H#include <netinet/in_systm.h>#endif#if HAVE_NETINET_IP_H#include <netinet/ip.h>#endif#if HAVE_NETINET_IP_ICMP_H#include <netinet/ip_icmp.h>#endif#if HAVE_NETINET_ICMP_VAR_H#include <netinet/icmp_var.h>#endif#if HAVE_SYS_SYSCTL_H#include <sys/sysctl.h>#endif#if HAVE_INET_MIB2_H#include <inet/mib2.h>#endif#if HAVE_WINSOCK_H#include <winsock.h>#endif#if HAVE_DMALLOC_H#include <dmalloc.h>#endif#include "tools.h"#ifdef solaris2#include "kernel_sunos5.h"#endif#ifdef linux#include "kernel_linux.h"#endif#include "mibincl.h"#include "util_funcs.h"#include "system.h"#include "asn1.h"#include "snmp_debug.h"#include "auto_nlist.h"#ifdef hpux#include <sys/mib.h>#include <netinet/mib_kern.h>#endif /* hpux */#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#endifmarker_t icmp_stats_cache_marker = NULL; /********************* * * Kernel & interface information, * and internal forward declarations * *********************/ /********************* * * Initialisation & common implementation functions * *********************//* define the structure we're going to ask the agent to register our information at */struct variable2 icmp_variables[] = { {ICMPINMSGS, ASN_COUNTER, RONLY, var_icmp, 1, {1}}, {ICMPINERRORS, ASN_COUNTER, RONLY, var_icmp, 1, {2}}, {ICMPINDESTUNREACHS, ASN_COUNTER, RONLY, var_icmp, 1, {3}}, {ICMPINTIMEEXCDS, ASN_COUNTER, RONLY, var_icmp, 1, {4}}, {ICMPINPARMPROBS, ASN_COUNTER, RONLY, var_icmp, 1, {5}}, {ICMPINSRCQUENCHS, ASN_COUNTER, RONLY, var_icmp, 1, {6}}, {ICMPINREDIRECTS, ASN_COUNTER, RONLY, var_icmp, 1, {7}}, {ICMPINECHOS, ASN_COUNTER, RONLY, var_icmp, 1, {8}}, {ICMPINECHOREPS, ASN_COUNTER, RONLY, var_icmp, 1, {9}}, {ICMPINTIMESTAMPS, ASN_COUNTER, RONLY, var_icmp, 1, {10}}, {ICMPINTIMESTAMPREPS, ASN_COUNTER, RONLY, var_icmp, 1, {11}}, {ICMPINADDRMASKS, ASN_COUNTER, RONLY, var_icmp, 1, {12}}, {ICMPINADDRMASKREPS, ASN_COUNTER, RONLY, var_icmp, 1, {13}}, {ICMPOUTMSGS, ASN_COUNTER, RONLY, var_icmp, 1, {14}}, {ICMPOUTERRORS, ASN_COUNTER, RONLY, var_icmp, 1, {15}}, {ICMPOUTDESTUNREACHS, ASN_COUNTER, RONLY, var_icmp, 1, {16}}, {ICMPOUTTIMEEXCDS, ASN_COUNTER, RONLY, var_icmp, 1, {17}}, {ICMPOUTPARMPROBS, ASN_COUNTER, RONLY, var_icmp, 1, {18}}, {ICMPOUTSRCQUENCHS, ASN_COUNTER, RONLY, var_icmp, 1, {19}}, {ICMPOUTREDIRECTS, ASN_COUNTER, RONLY, var_icmp, 1, {20}}, {ICMPOUTECHOS, ASN_COUNTER, RONLY, var_icmp, 1, {21}}, {ICMPOUTECHOREPS, ASN_COUNTER, RONLY, var_icmp, 1, {22}}, {ICMPOUTTIMESTAMPS, ASN_COUNTER, RONLY, var_icmp, 1, {23}}, {ICMPOUTTIMESTAMPREPS, ASN_COUNTER, RONLY, var_icmp, 1, {24}}, {ICMPOUTADDRMASKS, ASN_COUNTER, RONLY, var_icmp, 1, {25}}, {ICMPOUTADDRMASKREPS, ASN_COUNTER, RONLY, var_icmp, 1, {26}}};/* Define the OID pointer to the top of the mib tree that we're registering underneath */oid icmp_variables_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;#endifvoid init_icmp(void){ /* register ourselves with the agent to handle our mib tree */ REGISTER_MIB("mibII/icmp", icmp_variables, variable2, icmp_variables_oid);#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} /********************* * * System specific implementation functions * *********************/#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 cygwin#define WIN32#include <windows.h>#endif#ifdef hpux11#define ICMP_STAT_STRUCTURE int#endif#ifdef WIN32#include <iphlpapi.h>#define ICMP_STAT_STRUCTURE MIB_ICMP#endif#ifdef HAVE_SYS_ICMPIPSTATS_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#endiflong read_icmp_stat (ICMP_STAT_STRUCTURE *, int);u_char *var_icmp(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method){ static ICMP_STAT_STRUCTURE icmpstat; static long ret_value;#ifdef USES_TRADITIONAL_ICMPSTAT int i;#endif if (header_generic(vp, name, length, exact, var_len, write_method) == MATCH_FAILED ) return NULL; ret_value = read_icmp_stat (&icmpstat, vp->magic); if ( ret_value < 0 ) return NULL;#ifdef HAVE_SYS_TCPIPSTATS_H /* This actually reads statistics for *all* the groups together, so we need to isolate the ICMP-specific bits. */#ifndef NO_DOUBLE_ICMPSTAT#define icmpstat icmpstat.icmpstat#endif /* NO_ICMPSTATICMPSTAT */#endif switch (vp->magic){#ifdef USES_SNMP_DESIGNED_ICMPSTAT case ICMPINMSGS: return (u_char *) &icmpstat.icmpInMsgs; case ICMPINERRORS: return (u_char *) &icmpstat.icmpInErrors; case ICMPINDESTUNREACHS:return (u_char *) &icmpstat.icmpInDestUnreachs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -