📄 m2iflib.c
字号:
} else { UI64_ADD32(pStat, amount); } }/***************************************************************************** m2IfGenericPacketCount - increment the interface packet counters ** This function updates the basic interface counters for a packet. It knows * nothing of the underlying media. Thus, so only the 'ifInOctets', * 'ifHCInOctets', 'ifOutOctets', 'ifHCOutOctets', and * 'ifCounterDiscontinuityTime' variables are incremented. The <ctrl> * argument specifies whether the packet is being sent or just received * (M2_PACKET_IN or M2_PACKET_OUT).** RETURNS: ERROR if the M2_ID is NULL, OK if the counters were updated.*/STATUS m2IfGenericPacketCount ( M2_ID * pId, /* The pointer to the device M2_ID object */ UINT ctrl, /* Update In or Out counters */ UCHAR * pPkt, /* The incoming/outgoing packet */ ULONG pktLen /* Length of the packet */ ) { M2_DATA * pMib2Data; if (pId == NULL) return ERROR; pMib2Data = &(pId->m2Data); switch (ctrl) { case M2_PACKET_IN: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInOctets), pktLen); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInOctets), pktLen); break; case M2_PACKET_OUT: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutOctets), pktLen); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutOctets), pktLen); break; default: return ERROR; } return OK; }/**************************************************************************** * m2If8023PacketCount - increment the packet counters for an 802.3 device ** This function is used to update basic interface counters for a packet. The* ctrl argument specifies whether the packet is being sent or just received* (M2_PACKET_IN or M2_PACKET_OUT). This function only works for 802.3* devices as it understand the Ethernet packet format. The following counters* are updated:* \ml* \m - * ifInOctets* \m - * ifInUcastPkts* \m - * ifInNUcastPkts* \m - * ifOutOctets* \m - * ifOutUcastPkts* \m - * ifOutNUcastPkts* \m - * ifInMulticastPkts* \m - * ifInBroadcastPkts* \m - * ifOutMulticastPkts* \m - * ifOutBroadcastPkts* \m - * ifHCInOctets* \m - * ifHCInUcastPkts* \m - * ifHCOutOctets* \m - * ifHCOutUcastPkts* \m - * ifHCInMulticastPkts* \m - * ifHCInBroadcastPkts* \m - * ifHCOutMulticastPkts* \m - * ifHCOutBroadcastPkts* \m - * ifCounterDiscontinuityTime* \me* This function should be called right after the netMblkToBufCopy() function* has been completed. The first 6 bytes in the resulting buffer must contain * the destination MAC address and the second 6 bytes of the buffer must * contain the source MAC address.* * The type of MAC address (i.e. broadcast, multicast, or unicast) is* determined by the following:* \ml* \m broadcast address: * ff:ff:ff:ff:ff:ff* \m multicast address: * first bit is set* \m unicast address: * any other address not matching the above* \me* RETURNS: ERROR, if the M2_ID is NULL, or the ctrl is invalid; OK, if* the counters were updated.*/STATUS m2If8023PacketCount ( M2_ID * pId, /* The pointer to the device M2_ID object */ UINT ctrl, /* Update In or Out counters */ UCHAR * pPkt, /* The incoming/outgoing packet */ ULONG pktLen /* Length of the packet */ ) { M2_DATA * pMib2Data; UCHAR pBcastAddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; UCHAR mcastBit = 0x01; USHORT *pSrc, *pDst; if (pId == NULL) return ERROR; pMib2Data = &(pId->m2Data); pDst = (USHORT *)pBcastAddr; pSrc = (USHORT *)pPkt; switch (ctrl) { case M2_PACKET_IN: { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInOctets), pktLen); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInOctets), pktLen); /* the first 6 bytes is the destination MAC address */ if (*pPkt & mcastBit) /* multicast address */ { if (pSrc[0] == pDst[0] && pSrc[1] == pDst[1] && pSrc[2] == pDst[2]) { m2IfIncr32Bit(pMib2Data, /* broadcast address */ &(pMib2Data->mibXIfTbl.ifInBroadcastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInBroadcastPkts), 1); } else { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifInMulticastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInMulticastPkts), 1); } m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInNUcastPkts), 1); } else /* unicast address */ { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInUcastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInUcastPkts), 1); } break; } case M2_PACKET_OUT: { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutOctets), pktLen); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutOctets), pktLen); /* the first 6 bytes is the destination MAC address */ if (*pPkt & mcastBit) /* multicast address */ { if (pSrc[0] == pDst[0] && pSrc[1] == pDst[1] && pSrc[2] == pDst[2]) { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifOutBroadcastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutBroadcastPkts), 1); } else { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifOutMulticastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutMulticastPkts), 1); } m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutNUcastPkts), 1); } else /* unicast address */ { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutUcastPkts), 1); if (m2If64BitCounters) m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutUcastPkts), 1); } break; } default: return ERROR; } return OK; }/***************************************************************************** m2IfCounterUpdate - increment interface counters ** This function is used to directly update an interface counter. The counter* is specified by <ctrId> and the amount to increment it is specified by value.* If the counter would roll over then the 'ifCounterDiscontinuityTime' is* updated with the current system uptime.** RETURNS: ERROR if the M2_ID is NULL, OK if the counter was updated.*/STATUS m2IfCounterUpdate ( M2_ID * pId, /* The pointer to the device M2_ID object */ UINT ctrId, /* Counter to update */ ULONG value /* Amount to update the counter by */ ) { M2_DATA * pMib2Data; if (pId == NULL) return ERROR; pMib2Data = &(pId->m2Data); switch (ctrId) { case M2_ctrId_ifInOctets: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInOctets), value); break; case M2_ctrId_ifInUcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInUcastPkts), value); break; case M2_ctrId_ifInNUcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInNUcastPkts), value); break; case M2_ctrId_ifInDiscards: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInDiscards), value); break; case M2_ctrId_ifInErrors: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInErrors), value); break; case M2_ctrId_ifInUnknownProtos: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInUnknownProtos), value); break; case M2_ctrId_ifOutOctets: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutOctets), value); break; case M2_ctrId_ifOutUcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutUcastPkts), value); break; case M2_ctrId_ifOutNUcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutNUcastPkts), value); break; case M2_ctrId_ifOutDiscards: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutDiscards), value); break; case M2_ctrId_ifOutErrors: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutErrors), value); break; case M2_ctrId_ifInMulticastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifInMulticastPkts), value); break; case M2_ctrId_ifInBroadcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifInBroadcastPkts), value); break; case M2_ctrId_ifOutMulticastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifOutMulticastPkts), value); break; case M2_ctrId_ifOutBroadcastPkts: m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifOutBroadcastPkts), value); break; case M2_ctrId_ifHCInOctets: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInOctets), value); break; case M2_ctrId_ifHCInUcastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInUcastPkts), value); break; case M2_ctrId_ifHCInMulticastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInMulticastPkts), value); break; case M2_ctrId_ifHCInBroadcastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCInBroadcastPkts), value); break; case M2_ctrId_ifHCOutOctets: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutOctets), value); break; case M2_ctrId_ifHCOutUcastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutUcastPkts), value); break; case M2_ctrId_ifHCOutMulticastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutMulticastPkts), value); break; case M2_ctrId_ifHCOutBroadcastPkts: m2IfIncr64Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifHCOutBroadcastPkts), value); break; default: return ERROR; } return OK; }/***************************************************************************** m2IfVariableUpdate - update the contents of an interface non-counter object ** This function is used to update an interface variable. The variable is* specified by varId and the data to use is specified by pData. Note that* different variable expect different types of data. Here is a list of the* variables and the type of data expected. Therefore, pData will be cast to * the type listed below for each variable.* \ts* Variable | Casted to Type
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -