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

📄 statm.c

📁 嵌入式RMON,RMON为Remote monitor的缩写,基于SNMP为网络提供主动监控及错误告警,智能交换路由必备协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group *//* See file COPYING 'GNU General Public Licence' for copyright details   */#include <memory.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <config.h>#include <snmp.h>#include <mibrqs.h>#include <mibsup.h>#include <message.h>#include <mac.h>#include "state.h"#include "statc.h"#include "stat.h"IMPORT BOOLEAN BeholderStrictRMON;#define INDEXSIZE   1static MIB_LOCAL    *etherStats = NULL;static BOOLEAN RmonNext (SNMP_OBJECT *Obj, MIB_LOCAL **Local, WORD IdLen, WORD IdSze, ETHER_STATS **Elm);BOOLEAN EtherStatsMInit(VOID){LONG i, nriface;CHAR s[81];BOOLEAN v;MAC_IFACE *iface;LONG statsource[] = {1,3,6,1,2,1,2,2,1,1,1};CHAR statowner[] = "monitorEtherStats";#define STATUSINDEX     11SNMP_OBJECT statobj[] = {    { SNMP_PDU_SET, {1,3,6,1,2,1,16,1,1,1,21,1}, 12, SNMP_INTEGER },    { SNMP_PDU_SET, {1,3,6,1,2,1,16,1,1,1,20,1}, 12, SNMP_DISPLAYSTR },    { SNMP_PDU_SET, {1,3,6,1,2,1,16,1,1,1,2,1},  12, SNMP_OBJECTID }};    MessageConfig(STATISTICS_ERROR, "EtherStat");    nriface = (LONG)MacIfaceCount();    for (i = 1; i <= nriface; i++)    {        sprintf(s, "beholder.stat.iface.%ld", i);        if (ConfigGetBoolean(s, &v) == TRUE)        {            iface = MacIfaceGet((WORD)i);            if (iface != NULL && v == TRUE &&                (iface->type == MAC_TYPE_ETHERNET_CSMACD ||                 iface->type == MAC_TYPE_88023_CSMACD))            {                statobj[0].Id[STATUSINDEX] = i;                statobj[1].Id[STATUSINDEX] = i;                statobj[2].Id[STATUSINDEX] = i;                statobj[0].Syntax.LngInt = SNMP_INVALID;                MibRequest(&statobj[0]);                statobj[0].Syntax.LngInt = SNMP_CREATEREQUEST;                if (MibRequest(&statobj[0]) != SNMP_NOERROR)                {                    DnpapMessage(DMC_WARNING, STAT_STATINIT, "etherStats: couldn't create etherStats collector %ld", i);                    continue;                }                strncpy(statobj[1].Syntax.BufChr, statowner, statobj[1].SyntaxLen = strlen(statowner));                if (MibRequest(&statobj[1]) != SNMP_NOERROR)                {                    DnpapMessage(DMC_WARNING, STAT_STATINIT, "etherStats: couldn't set owner of etherStats collector %ld", i);                    statobj[0].Syntax.LngInt = SNMP_INVALID;                    MibRequest(&statobj[0]);                    continue;                }                memcpy(statobj[2].Syntax.BufInt, statsource, sizeof(statsource));                statobj[2].Syntax.BufInt[sizeof(statsource)/sizeof(statsource[0])-1] = i;                statobj[2].SyntaxLen = sizeof(statsource)/sizeof(statsource[0]);                if (MibRequest(&statobj[2]) != SNMP_NOERROR)                {                    DnpapMessage(DMC_WARNING, STAT_STATINIT, "etherStats: couldn't set datasource of etherStats collector %ld", i);                    statobj[0].Syntax.LngInt = SNMP_INVALID;                    MibRequest(&statobj[0]);                    continue;                }                statobj[0].Syntax.LngInt = SNMP_VALID;                if (MibRequest(&statobj[0]) != SNMP_NOERROR)                {                    DnpapMessage(DMC_WARNING, STAT_STATINIT, "etherStats: couldn't set etherStats collector %ld to valid", i);                    statobj[0].Syntax.LngInt = SNMP_INVALID;                    MibRequest(&statobj[0]);                    continue;                }            }        }    }    return TRUE;}/******************************************************************* NAME:        RmonNext** SYNOPSIS:    BOOLEAN RmonNext (SNMP_OBJECT *Obj,**                                  MIB_LOCAL **Local, WORD IdLen,**                                  WORD IdSze, VOID **Elm)** PARAMETERS:  Obj: requested object**              Local: local datastructure: a collector**              IdLen: identifier length known to the MIB**              IdSze: number of indices after the MIB**              Elm: pointer to object if tables are used** DESCRIPTION: application specific RMON NEXT function.**              only called after MibRmon() for next requests **              searches the next object in the collector** REMARKS:     ONLY FOR INTERNAL USE** RETURNS:     TRUE: object found**                    OPTIONAL: Elm -> pointer to object in table*******************************************************************/BOOLEAN RmonNext (SNMP_OBJECT *Obj, MIB_LOCAL **Local, WORD IdLen, WORD IdSze, ETHER_STATS **Elm){MIB_LOCAL    *local = *Local;    if (local == NULL)        return FALSE;    if (Obj->IdLen == IdLen || local->Index > Obj->Id[IdLen])    {        /********************************************************************        **  OPTIONAL: search function to find first obj in a table !!         **  if (not found)        **      search next collector        **  adjust object identifier to identifier first object        **  Elm -> found table obj        ********************************************************************/        Obj->IdLen = IdLen + IdSze;        Obj->Id[IdLen] = local->Index;        return TRUE;    }    /********************************************************************    **  OPTIONAL: search function to find next obj in a table !!     **  if (found)    **      adjust object identifier to identifier next object    **      Elm -> found table obj    **      return TRUE    ********************************************************************/    *Local = local->Next;    return RmonNext(Obj, Local, IdLen, IdSze, Elm);}WORD EtherStatsIndex (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        Obj->Syntax.LngInt = local->Index;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsDataSource (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_IFACE    *iface;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;		if (BeholderStrictRMON && !BooleanCheck(data->ObjectSet, STAT_BOOLEAN_DATASOURCE))			return SNMP_NOSUCHNAME;        memcpy (Obj->Syntax.BufInt, data->Source, data->SourceLen * sizeof (LONG));        Obj->SyntaxLen = data->SourceLen;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (ETHER_STATS*) local->Data;        if (data->Status != SNMP_UNDERCREATION)            return SNMP_READONLY;        if (data->SourceLen != Obj->SyntaxLen ||            memcmp(data->Source, Obj->Syntax.BufInt, (data->SourceLen-1) * sizeof (LONG)))            return SNMP_BADVALUE;        if ((iface = MacIfaceGet((WORD) Obj->Syntax.BufInt[Obj->SyntaxLen-1])) == NULL)            return SNMP_BADVALUE;        if (iface->type != MAC_TYPE_ETHERNET_CSMACD && iface->type != MAC_TYPE_88023_CSMACD)        	return SNMP_BADVALUE;        memcpy (data->Source, Obj->Syntax.BufInt, Obj->SyntaxLen * sizeof (LONG));        data->SourceLen = Obj->SyntaxLen;        data->Iface = iface;		BooleanSetTrue(data->ObjectSet, STAT_BOOLEAN_DATASOURCE);        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsDropEvents (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_STAT     stat;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        if (data->Status != SNMP_VALID)        {            Obj->Syntax.LngUns = 0UL;            return SNMP_NOERROR;        }        MacStatistics(data->Iface, &stat);        Obj->Syntax.LngUns = stat.LostPkts + stat.DiscardedPkts - (data->BaseStat.LostPkts + data->BaseStat.DiscardedPkts);        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsOctets (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        Obj->Syntax.LngUns = data->Octets;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsPkts (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        Obj->Syntax.LngUns = data->Pkts;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}                                                WORD EtherStatsBroadcastPkts (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_STAT     stat;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        if (data->Status != SNMP_VALID)        {            Obj->Syntax.LngUns = 0UL;            return SNMP_NOERROR;        }        MacStatistics(data->Iface, &stat);        Obj->Syntax.LngUns = stat.BroadcastPkts - data->BaseStat.BroadcastPkts;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsMulticastPkts (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_STAT     stat;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        if (data->Status != SNMP_VALID)        {            Obj->Syntax.LngUns = 0UL;            return SNMP_NOERROR;        }        MacStatistics(data->Iface, &stat);        Obj->Syntax.LngUns = stat.MulticastPkts - data->BaseStat.MulticastPkts;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsCRCAlignErrors (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_STAT     stat;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;        if (data->Status != SNMP_VALID)        {            Obj->Syntax.LngUns = 0UL;            return SNMP_NOERROR;        }        MacStatistics(data->Iface, &stat);        Obj->Syntax.LngUns = stat.CRCAlignErrors - data->BaseStat.CRCAlignErrors;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD EtherStatsUndersizePkts (SNMP_OBJECT *Obj, WORD IdLen){MIB_LOCAL    *local = NULL;ETHER_STATS  *data;MAC_STAT     stat;    if ((local = MibRmon(Obj, etherStats, IdLen, INDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (Obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (Obj, &local, IdLen, INDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (ETHER_STATS*) local->Data;

⌨️ 快捷键说明

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