📄 m2iflib.c
字号:
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); /* 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); else m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifInMulticastPkts), 1); m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInNUcastPkts), 1); } else /* unicast address */ { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifInUcastPkts), 1); } break; } case M2_PACKET_OUT: { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutOctets), 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); else m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibXIfTbl.ifOutMulticastPkts), 1); m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutNUcastPkts), 1); } else /* unicast address */ { m2IfIncr32Bit(pMib2Data, &(pMib2Data->mibIfTbl.ifOutUcastPkts), 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* ----------------------------------------* ifDescr | char ** ifType | UINT* ifMtu | ULONG* ifSpeed | ULONG* ifPhysAddress | M2_PHYADDR ** ifAdminStatus | ULONG* ifOperStatus | ULONG* ifLastChange | ULONG* ifOutQLen | ULONG* ifSpecific | M2_OBJECTID ** ifName | char ** ifLinkUpDownTrapEnable | UINT* ifHighSpeed | ULONG* ifPromiscuousMode | UINT* ifConnectorPresent | UINT* ifAlias | char ** \te* RETURNS: ERROR, if the M2_ID is NULL; OK, if the variable was updated.*/STATUS m2IfVariableUpdate ( M2_ID * pId, /* The pointer to the device M2_ID object */ UINT varId, /* Variable to update */ caddr_t pData /* Data to use */ ) { M2_DATA * pMib2Data; if (pId == NULL) return ERROR; pMib2Data = &(pId->m2Data); switch (varId) { case M2_varId_ifDescr: strcpy(pMib2Data->mibIfTbl.ifDescr, (char *)pData); break; case M2_varId_ifType: pMib2Data->mibIfTbl.ifType = (UINT)pData; break; case M2_varId_ifMtu: pMib2Data->mibIfTbl.ifMtu = (ULONG)pData; break; case M2_varId_ifSpeed: pMib2Data->mibIfTbl.ifSpeed = (ULONG)pData; break; case M2_varId_ifPhysAddress: memcpy(&(pMib2Data->mibIfTbl.ifPhysAddress), (M2_PHYADDR *)pData, sizeof(M2_PHYADDR)); break; case M2_varId_ifAdminStatus: pMib2Data->mibIfTbl.ifAdminStatus = (ULONG)pData; break; case M2_varId_ifOperStatus: pMib2Data->mibIfTbl.ifOperStatus = (ULONG)pData; break; case M2_varId_ifLastChange: pMib2Data->mibIfTbl.ifLastChange = (ULONG)pData; break; case M2_varId_ifOutQLen: pMib2Data->mibIfTbl.ifOutQLen = (ULONG)pData; break; case M2_varId_ifSpecific: memcpy(&(pMib2Data->mibIfTbl.ifSpecific), (M2_OBJECTID *)pData, sizeof(M2_OBJECTID)); break; case M2_varId_ifName: strcpy(pMib2Data->mibXIfTbl.ifName, (char *)pData); break; case M2_varId_ifLinkUpDownTrapEnable: pMib2Data->mibXIfTbl.ifLinkUpDownTrapEnable = (UINT)pData; break; case M2_varId_ifHighSpeed: pMib2Data->mibXIfTbl.ifHighSpeed = (ULONG)pData; break; case M2_varId_ifPromiscuousMode: pMib2Data->mibXIfTbl.ifPromiscuousMode = (UINT)pData; break; case M2_varId_ifConnectorPresent: pMib2Data->mibXIfTbl.ifConnectorPresent = (UINT)pData; break; case M2_varId_ifAlias: strcpy(pMib2Data->mibXIfTbl.ifAlias, (char *)pData); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -