📄 statc.c
字号:
/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group *//* See file COPYING 'GNU General Public Licence' for copyright details */#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <dnpap.h>#include <message.h>#include <mac.h>#include <protocol.h>#include "state.h"#include "statc.h"IMPORT BOOLEAN BeholderStrictRMON;static BOOLEAN EtherStatsMacCallback(MAC_COLL *collector, PROT_PKT *pkt);/******************************************************************* NAME: EtherStatsCInit** SYNOPSIS: BOOLEAN EtherStatsCInit (ETHER_STATS *etherStats)** PARAMETERS: pointer to data etherStats entry** DESCRIPTION: initializes collector.** REMARKS: called when status is CREATE_REQUEST: see statm.c** RETURNS: TRUE: everything OK** FALSE: net not initialized*******************************************************************/BOOLEAN EtherStatsCInit (ETHER_STATS *etherStats){LONG source[] = {1,3,6,1,2,1,2,2,1,1,1}; etherStats->SourceLen = sizeof(source)/sizeof(long); memcpy (etherStats->Source, source, sizeof(source)); if ((etherStats->Iface = MacIfaceGet((WORD) etherStats->Source[etherStats->SourceLen-1])) == NULL) { DnpapMessage(DMC_ERROR, STAT_NETINIT, "etherStats: network initialization failed"); return (FALSE); } BooleanSetAllTrue(etherStats->ObjectSet); BooleanSetFalse(etherStats->ObjectSet, STAT_BOOLEAN_DATASOURCE); BooleanSetFalse(etherStats->ObjectSet, STAT_BOOLEAN_OWNER); return TRUE;}/******************************************************************* NAME: EtherStatsCStart** SYNOPSIS: BOOLEAN EtherStatsCStart (ETHER_STATS *etherStats)** PARAMETERS: pointer to data etherStats entry** DESCRIPTION: starts collector.** REMARKS: called when status is VALID: see statm.c** RETURNS: TRUE: everything OK** FALSE: net not registered*******************************************************************/BOOLEAN EtherStatsCStart (ETHER_STATS *etherStats){ if (BeholderStrictRMON && !BooleanCheckAllTrue(etherStats->ObjectSet)) return FALSE; etherStats->Coll.Rcve = EtherStatsMacCallback; etherStats->Coll.specific = etherStats; if (!MacCollRegister(&(etherStats->Coll))) { DnpapMessage(DMC_ERROR, STAT_NETINIT, "etherStats: network initialization failed"); return (FALSE); } MacStatistics(etherStats->Iface, ðerStats->BaseStat); etherStats->Octets = 0; etherStats->Pkts = 0; etherStats->Pkts64Octets = 0; etherStats->Pkts65to127Octets = 0; etherStats->Pkts128to255Octets = 0; etherStats->Pkts256to511Octets = 0; etherStats->Pkts512to1023Octets = 0; etherStats->Pkts1024to1518Octets = 0; return TRUE;}/******************************************************************* NAME: EtherStatsCStop ** SYNOPSIS: BOOLEAN EtherStatsCStop (ETHER_STATS *etherStats)** PARAMETERS: pointer to etherStats entry** DESCRIPTION: stops collector.** REMARKS: called when status is INVALID: see statm.c** RETURNS: TRUE: net registration removed *******************************************************************/BOOLEAN EtherStatsCStop (ETHER_STATS *etherStats){ MacCollRemove(&(etherStats->Coll)); return TRUE;}/******************************************************************* NAME: StatMacCallback** PARAMETERS: see Net manual** DESCRIPTION: analyses packets received from net** REMARKS: none** RETURNS: VOID*******************************************************************/BOOLEAN EtherStatsMacCallback(MAC_COLL *collector, PROT_PKT *pkt){ETHER_STATS *etherStats = collector->specific; EtherStatsHandlePkt(etherStats, pkt); return TRUE;}VOID EtherStatsHandlePkt(ETHER_STATS *etherStats, PROT_PKT *pkt){PROT_OBJ Interface = {1, {1,2}};PROT_OBJ Size = {1, {1,4}};LWORD size; if (ProtGetField(pkt,&Interface) == TRUE && Interface.Syntax.LngInt == etherStats->Source[etherStats->SourceLen-1]) { if (ProtGetField(pkt,&Size) == TRUE) { etherStats->Pkts++; size = Size.Syntax.LngUns + 4L; etherStats->Octets += size; if (size == 64) etherStats->Pkts64Octets++; if (size >= 65) { if (size <= 127) etherStats->Pkts65to127Octets++; else if (size <= 255) etherStats->Pkts128to255Octets++; else if (size <= 511) etherStats->Pkts256to511Octets++; else if (size <= 1023) etherStats->Pkts512to1023Octets++; else if (size <= 1518) etherStats->Pkts1024to1518Octets++; } } } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -