SnmpPduPacket makeErrorVarbindPdu(SnmpPduPacket req, int statusTag) { final SnmpVarBind[] vblist = req.varBindList; final int length = vblist.length; switch (statusTag) { case SnmpDataTypeEnums.errEndOfMibViewTag: for (int i=0 ; i<length ; i++) vblist[i].value = SnmpVarBind.endOfMibView; break; case SnmpDataTypeEnums.errNoSuchObjectTag: for (int i=0 ; i<length ; i++) vblist[i].value = SnmpVarBind.noSuchObject; break; case SnmpDataTypeEnums.errNoSuchInstanceTag: for (int i=0 ; i<length ; i++) vblist[i].value = SnmpVarBind.noSuchInstance; break; default: return newErrorResponsePdu(req,snmpRspGenErr,1); } return newValidResponsePdu(req,vblist); }
SnmpPduPacket makeNoMibErrorPdu(SnmpPduRequest req, Object userData) { // There is no agent registered // if (req.version == SnmpDefinitions.snmpVersionOne) { // Version 1: => NoSuchName return newErrorResponsePdu(req,snmpRspNoSuchName,1); } else if (req.version == SnmpDefinitions.snmpVersionTwo) { // Version 2: => depends on PDU type switch (req.type) { case pduSetRequestPdu : case pduWalkRequest : // SET request => NoAccess return newErrorResponsePdu(req,snmpRspNoAccess,1); case pduGetRequestPdu : // GET request => NoSuchObject return makeErrorVarbindPdu(req,SnmpDataTypeEnums. errNoSuchObjectTag); case pduGetNextRequestPdu : case pduGetBulkRequestPdu : // GET-NEXT or GET-BULK => EndOfMibView return makeErrorVarbindPdu(req,SnmpDataTypeEnums. errEndOfMibViewTag); default: } } // Something wrong here: => snmpRspGenErr return newErrorResponsePdu(req,snmpRspGenErr,1); }