📄 icmp.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/icmp.c,v 1.2 2001/11/09 21:49:01 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1988-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: icmp.c,v $ * Revision 1.2 2001/11/09 21:49:01 josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1 2001/11/05 17:49:16 tneale * Tornado shuffle * * Revision 7.6 2001/01/19 22:25:01 paul * Update copyright. * * Revision 7.5 2000/03/17 00:15:19 meister * Update copyright message * * Revision 7.4 1998/02/25 04:58:19 sra * Update copyrights. * * Revision 7.3 1997/03/20 06:54:08 sra * DFARS-safe copyright text. Zap! * * Revision 7.2 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 7.1 1997/01/08 23:01:49 sar * Updated copyright and modified include files to use envoy/h as * appropriate * * Revision 7.0 1996/03/15 22:07:57 sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.0 1995/05/31 21:49:43 sra * Release 6.0. * * Revision 5.1 1995/03/21 19:36:16 sar * Updated method routines to use new api & scheme * * Revision 5.0 1994/05/16 16:20:43 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 17:34:02 sar * Updated rev to 4.0 copyright to 93 * * Revision 3.0 1992/04/03 19:53:44 dab * Release 3.0 * * Revision 2.101 92/02/04 10:46:44 dab * Updated for release 3.0 of SNMP. * * Revision 2.100 92/02/03 16:46:08 dab * Generic unix SNMP agent. * * * Rev 2.0 31 Mar 1990 15:34:20 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*/#include <stdio.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <sys/param.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <net/if.h>#include <netinet/if_ether.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#include <netinet/ip_icmp.h>#include <netinet/icmp_var.h>#include "snmpvars.h"#include "general.h"#define LM_icmpInMsgs 1#define LM_icmpInErrors 2#define LM_icmpInDestUnreachs 3#define LM_icmpInTimeExcds 4#define LM_icmpInParmProbs 5#define LM_icmpInSrcQuenchs 6#define LM_icmpInRedirects 7#define LM_icmpInEchos 8#define LM_icmpInEchoReps 9#define LM_icmpInTimestamps 10#define LM_icmpIntimestampReps 11#define LM_icmpInAddrMasks 12#define LM_icmpInAddrMaskReps 13#define LM_icmpOutMsgs 14#define LM_icmpOutErrors 15#define LM_icmpOutDestUnreachs 16#define LM_icmpOutTimeExcds 17#define LM_icmpOutParmProbs 18#define LM_icmpOutSrcQuenchs 19#define LM_icmpOutRedirects 20#define LM_icmpOutEchos 21#define LM_icmpOutEchoReps 22#define LM_icmpOutTimestamps 23#define LM_icmpOutTimestampReps 24#define LM_icmpOutAddrMasks 25#define LM_icmpOutAddrMaskReps 26static struct icmpstat icmps;#define CACHE_LIFETIME 4static struct kernel_symbol icmpstat = { "_icmpstat", 0, 0};static time_t icmp_cache_time = 0;staticintread_icmp(){time_t now;if ((time(&now) - icmp_cache_time) <= CACHE_LIFETIME) return 0;icmp_cache_time = now;if (find_loc(&icmpstat) == 0) return -1;read_bytes((off_t)icmpstat.offset, (char *)&icmps, sizeof(struct icmpstat));return 0;}/****************************************************************************NAME: get_icmp_infoPURPOSE: Find the appropriate entry in the icmp struct and attach information from it to the vbp using the getproc_got_* functions. If we can't find an entry indicate that by calling getproc_nosuchins.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void get_icmp_info(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){int i, total = 0;/* test that we have an instance with a single oid which is equal to 0 */if ((tcount != 1) || (*tlist != 0)) { getproc_nosuchins(pktp, vbp); return; }if (read_icmp() == -1) { getproc_error(pktp, vbp, GEN_ERR); return; }switch(last_match) { case LM_icmpInMsgs: for (i = ICMP_MAXTYPE + 1; i; i--) total += icmps.icps_inhist[i]; total += icmps.icps_tooshort + icmps.icps_checksum; getproc_got_uint32(pktp, vbp, total, VT_COUNTER); break; case LM_icmpInErrors: total = icmps.icps_badcode + icmps.icps_tooshort + icmps.icps_checksum + icmps.icps_badlen; getproc_got_uint32(pktp, vbp, total, VT_COUNTER); break; case LM_icmpInDestUnreachs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_UNREACH], VT_COUNTER); break; case LM_icmpInTimeExcds: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_TIMXCEED], VT_COUNTER); break; case LM_icmpInParmProbs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_PARAMPROB], VT_COUNTER); break; case LM_icmpInSrcQuenchs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_SOURCEQUENCH], VT_COUNTER); break; case LM_icmpInRedirects: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_REDIRECT], VT_COUNTER); break; case LM_icmpInEchos: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_ECHO], VT_COUNTER); break; case LM_icmpInEchoReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_ECHOREPLY], VT_COUNTER); break; case LM_icmpInTimestamps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_TSTAMP], VT_COUNTER); break; case LM_icmpIntimestampReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_TSTAMPREPLY], VT_COUNTER); break; case LM_icmpInAddrMasks: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_MASKREQ], VT_COUNTER); break; case LM_icmpInAddrMaskReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_inhist[ICMP_MASKREPLY], VT_COUNTER); break; case LM_icmpOutMsgs: for (i = ICMP_MAXTYPE + 1; i; i--) total += icmps.icps_outhist[i]; getproc_got_uint32(pktp, vbp, total, VT_COUNTER); break; case LM_icmpOutErrors: total = icmps.icps_oldshort + icmps.icps_oldicmp; getproc_got_uint32(pktp, vbp, total, VT_COUNTER); break; case LM_icmpOutDestUnreachs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_UNREACH], VT_COUNTER); break; case LM_icmpOutTimeExcds: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_TIMXCEED], VT_COUNTER); break; case LM_icmpOutParmProbs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_PARAMPROB], VT_COUNTER); break; case LM_icmpOutSrcQuenchs: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_SOURCEQUENCH], VT_COUNTER); break; case LM_icmpOutRedirects: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_REDIRECT], VT_COUNTER); break; case LM_icmpOutEchos: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_ECHO], VT_COUNTER); break; case LM_icmpOutEchoReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_ECHOREPLY], VT_COUNTER); break; case LM_icmpOutTimestamps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_TSTAMP], VT_COUNTER); break; case LM_icmpOutTimestampReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_TSTAMPREPLY], VT_COUNTER); break; case LM_icmpOutAddrMasks: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_MASKREQ], VT_COUNTER); break; case LM_icmpOutAddrMaskReps: getproc_got_uint32(pktp, vbp, (UINT_32_T)icmps.icps_outhist[ICMP_MASKREPLY], VT_COUNTER); break; }return;}int icmp_init(){if (find_loc(&icmpstat) == 0) return -1;return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -