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

📄 topn_m.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 <limits.h>#include <dnpap.h>#include <dmath.h>#include <hostx.h>#include <stdlib.h>#include <memory.h>#include <message.h>#include <mibsup.h>#include "topn_d.h"#include "topn_e.h"#include "topn_c.h"#include "topn.h"IMPORT BOOLEAN BeholderStrictRMON;#define CONTROLINDEXSIZE   1#define TOPNINDEXSIZE      2static MIB_LOCAL    *TopNControlInstance = NULL;static BOOLEAN RmonNext (SNMP_OBJECT *obj, MIB_LOCAL **local, WORD idlen, WORD indexsize, TOPN_ENTRY **elem);BOOLEAN TopNMInit(VOID){    MessageConfig(TOPN_ERROR, "TopN");    return TRUE;}BOOLEAN RmonNext (SNMP_OBJECT *obj, MIB_LOCAL **local, WORD idlen, WORD indexsize, TOPN_ENTRY **elem){    if (*local == NULL || indexsize < 1)        return FALSE;    switch (indexsize)    {                case TOPNINDEXSIZE:	    if (obj->IdLen >= idlen + indexsize)	    {        if (((TOPN_CONTROL*)(*local)->Data)->Status == SNMP_VALID &&            ((TOPN_CONTROL*)(*local)->Data)->TimeRemaining == 0 &&            ((TOPN_CONTROL*)(*local)->Data)->TableSize > 0 &&            ((TOPN_CONTROL*)(*local)->Data)->TopNArray != NULL &&            obj->Id[idlen+1] < min(((TOPN_CONTROL*)(*local)->Data)->RequestedSize, ((TOPN_CONTROL*)(*local)->Data)->TableSize))        {            obj->Id[idlen] = (*local)->Index;            obj->Id[idlen+1]++;            obj->IdLen = idlen + TOPNINDEXSIZE;            *elem = ((TOPN_CONTROL*)(*local)->Data)->TopNArray[obj->Id[idlen+1]-1];            break;        }        *local = (*local)->Next;		}        while (*local != NULL &&             (((TOPN_CONTROL*)(*local)->Data)->Status != SNMP_VALID ||             ((TOPN_CONTROL*)(*local)->Data)->TimeRemaining > 0 ||             ((TOPN_CONTROL*)(*local)->Data)->TableSize == 0 ||             ((TOPN_CONTROL*)(*local)->Data)->TopNArray == NULL))            *local = (*local)->Next;        if (*local == NULL)            return FALSE;        obj->Id[idlen] = (*local)->Index;        obj->Id[idlen+1] = 1;        obj->IdLen = idlen + TOPNINDEXSIZE;        *elem = ((TOPN_CONTROL*)(*local)->Data)->TopNArray[0];        break;    case CONTROLINDEXSIZE:	    if (obj->IdLen >= idlen + indexsize)	    {		/* only go to next collector if requested index was higher or equal */		if (obj->Id[idlen] >= (*local)->Index)            *local = (*local)->Next;        if (*local == NULL)            return FALSE;		}        obj->Id[idlen] = (*local)->Index;        obj->IdLen = idlen + CONTROLINDEXSIZE;        break;    }    return TRUE;}WORD HostTopNControlIndex(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL    *local = NULL;    if ((local = MibRmon (obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;            switch (obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        obj->Syntax.LngInt = local->Index;        return SNMP_NOERROR;    case SNMP_PDU_SET:        return SNMP_READONLY;    }    return SNMP_GENERROR;}WORD HostTopNHostIndex(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = data->HostIndex;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (TOPN_CONTROL*) local->Data;        if (data->Status != SNMP_UNDERCREATION)            return SNMP_READONLY;        data->HostIndex = obj->Syntax.LngInt;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD HostTopNRateBase(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = data->RateBase;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (TOPN_CONTROL*) local->Data;        if (data->Status != SNMP_UNDERCREATION)            return SNMP_READONLY;        if (obj->Syntax.LngInt < TOPN_RATEBASEMIN || obj->Syntax.LngInt > TOPN_RATEBASEMAX)            return SNMP_BADVALUE;        data->RateBase = obj->Syntax.LngInt;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD HostTopNTimeRemaining(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = data->TimeRemaining;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (TOPN_CONTROL*) local->Data;        if (obj->Syntax.LngInt < 1)            return SNMP_BADVALUE;        data->TimeRemaining = obj->Syntax.LngInt;        data->Duration = data->TimeRemaining;        if (data->Status == SNMP_VALID)        {            if (TopNCStop(data) == FALSE)            {                DnpapMessage(DMC_ERROR, TOPN_STOP, "topN: collector %ld could not be stopped", local->Index);                return SNMP_GENERROR;            }            if (TopNCStart(data) == FALSE)            {                DnpapMessage(DMC_ERROR, TOPN_START, "topN: collector %ld could not be started", local->Index);                return SNMP_BADVALUE;            }        }        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD HostTopNDuration(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = data->Duration;        return SNMP_NOERROR;    case SNMP_PDU_SET:        return SNMP_READONLY;    }    return SNMP_GENERROR;}WORD HostTopNRequestedSize(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = data->RequestedSize;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (TOPN_CONTROL*) local->Data;        if (obj->Syntax.LngInt < 0)            return SNMP_BADVALUE;        if (FillEntryTable(data, obj->Syntax.LngInt) != TRUE)            return SNMP_GENERROR;        data->RequestedSize = obj->Syntax.LngInt;        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD HostTopNGrantedSize(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngInt = min(data->RequestedSize, data->TableSize);        return SNMP_NOERROR;    case SNMP_PDU_SET:        return SNMP_READONLY;    }    return SNMP_GENERROR;}WORD HostTopNStartTime(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL     *local = NULL;TOPN_CONTROL  *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {               case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;        obj->Syntax.LngUns = data->StartTime;        return SNMP_NOERROR;    case SNMP_PDU_SET:        return SNMP_READONLY;    }    return SNMP_GENERROR;}WORD HostTopNOwner(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL    *local = NULL;TOPN_CONTROL *data;    if ((local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE)) == NULL)        return SNMP_NOSUCHNAME;    switch (obj->Request)    {    case SNMP_PDU_NEXT:        if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE)            return SNMP_NOSUCHNAME;    case SNMP_PDU_GET:        data = (TOPN_CONTROL*) local->Data;		if (BeholderStrictRMON && !BooleanCheck(data->ObjectSet, TOPN_BOOLEAN_OWNER))			return SNMP_NOSUCHNAME;        memcpy (obj->Syntax.BufChr, data->Owner, data->OwnerLen);        obj->SyntaxLen = data->OwnerLen;        return SNMP_NOERROR;    case SNMP_PDU_SET:        data = (TOPN_CONTROL*) local->Data;        if (data->Status != SNMP_UNDERCREATION)            return SNMP_READONLY;        memcpy (data->Owner, obj->Syntax.BufChr, obj->SyntaxLen);        data->OwnerLen = obj->SyntaxLen;		BooleanSetTrue(data->ObjectSet, TOPN_BOOLEAN_OWNER);        return SNMP_NOERROR;    }    return SNMP_GENERROR;}WORD HostTopNStatus(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL    *local = NULL;TOPN_CONTROL *data;    local = MibRmon(obj, TopNControlInstance, idlen, CONTROLINDEXSIZE);    switch (obj->Request)    {    case SNMP_PDU_GET:        if (local == NULL)        {            obj->Syntax.LngInt = SNMP_INVALID;            return SNMP_NOSUCHNAME;        }        data = (TOPN_CONTROL*) local->Data;

⌨️ 快捷键说明

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