func (pdu *V3PDU) decodePDU(native *C.snmp_pdu_t) (bool, SnmpError) { pdu.requestId = int(native.request_id) pdu.identifier = int(native.identifier) pdu.op = SnmpType(native.pdu_type) pdu.contextEngine = readGoBytes(&native.context_engine[0], native.context_engine_len) pdu.contextName = readGoString(&native.context_name[0], SNMP_CONTEXT_NAME_LEN) pdu.engine = new(snmpEngine) pdu.engine.engine_id = readGoBytes(&native.engine.engine_id[0], native.engine.engine_len) pdu.engine.engine_boots = int(native.engine.engine_boots) pdu.engine.engine_time = int(native.engine.engine_time) pdu.maxMsgSize = uint(native.engine.max_msg_size) pdu.error_status = int32(native.error_status) pdu.securityModel = new(USM) err := pdu.securityModel.Read(&native.user) if nil != err { return false, newError(SNMP_CODE_FAILED, err, "read security model failed") } decodeBindings(native, pdu.GetVariableBindings()) if native.pdu_type == C.SNMP_PDU_REPORT { ret_code := C.snmp_check_bad_oids(native) if ret_code != 0 { err = Error(SnmpResult(ret_code), "check pdu failed, "+C.GoString(C.snmp_get_error(ret_code))) return true, err //newError(, err, "check pdu failed") } } if C.SNMP_ERR_NOERROR != native.error_status { ret_code := uint32(C.SNMP_CODE_ERR_NOERROR + native.error_status) err = Error(SnmpResult(ret_code), "check pdu failed, "+C.GoString(C.snmp_get_error(ret_code))) return true, err //newError(, err, "check pdu failed") } return true, nil }
func (pdu *V2CPDU) decodePDU(native *C.snmp_pdu_t) (bool, SnmpError) { native.community[MAX_COMMUNITY_LEN-1] = 0 pdu.community = C.GoString(&native.community[0]) pdu.requestId = int(native.request_id) pdu.op = SnmpType(native.pdu_type) pdu.version = SnmpVersion(native.version) pdu.error_status = int32(native.error_status) decodeBindings(native, pdu.GetVariableBindings()) if C.SNMP_ERR_NOERROR != native.error_status { ret_code := uint32(C.SNMP_CODE_ERR_NOERROR + native.error_status) err := Error(SnmpResult(ret_code), "check pdu failed, "+C.GoString(C.snmp_get_error(ret_code))) return true, err //newError(, err, "check pdu failed") } return true, nil }