Hello Net-SNMP community, first of all thank you for this amazing free software package!
I'm writing an application that relies on SNMP to exchange data. Following the documentation and the code samples I've written the client part that handles GET-NEXT requests, that I will use to display SNMP tables. However I'm puzzled by a behaviour difference from snmpgetnext: when I receive the PDU response, the next_variable of the variable_list struct is always NULL. However this is not the case, looking at the code for snmpgetnext. apps/snmpgetnext.c:189 > status = snmp_synch_response(ss, pdu, &response); > if (status == STAT_SUCCESS) { > if (response->errstat == SNMP_ERR_NOERROR) { > for (vars = response->variables; vars; > vars = vars->next_variable) > print_variable(vars->name, vars->name_length, vars); This not a big deal, since the answer is correct, but it's not where I would expect it to be. I read it from the variables pointer, instead of the next_variable one. I'm using Net-SNMP version 5.9.3 on Debian GNU/Linux. I've attached a sample of my code. Thank you for your input. -- Matteo Bini
SnmpResponse *SnmpClient::Request(const SnmpRequestType req, const std::string objid, const SnmpOidType type, const std::string value) { void *data; oid name[MAX_OID_LEN] = { 0 }; size_t name_length; netsnmp_pdu *request, *response; int pdu_type; SnmpResponse *retVal = NULL; int status; char *str; netsnmp_variable_list *var; char var_objid[MAX_TEXT_OBJID_SIZE]; response = NULL; if (!session && !Connect()) { return new SnmpResponse(objid, this->error); } if (req == SNMP_REQUEST_SET) pdu_type = SNMP_MSG_SET; else if (req == SNMP_REQUEST_GETNEXT) pdu_type = SNMP_MSG_GETNEXT; else pdu_type = SNMP_MSG_GET; request = snmp_pdu_create(pdu_type); name_length = MAX_OID_LEN; if (!read_objid(objid.c_str(), name, &name_length)) { return new SnmpResponse(objid, "Can't read OID " + objid + "."); } if (req == SNMP_REQUEST_SET) snmp_add_var(request, name, name_length, type, value.c_str()); else snmp_add_null_var(request, name, name_length); status = snmp_synch_response(session, request, &response); if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR && (var = response->variables)) { /* Why is next_variable always NULL? if (var && req == SNMP_REQUEST_GETNEXT) { var = var->next_variable; } */ if (var) { if (req == SNMP_REQUEST_GETNEXT) { if (snprint_objid(var_objid, MAX_TEXT_OBJID_SIZE, var->name, var->name_length) == -1) { throw std::length_error("objid buffer needs more than " + std::to_string(MAX_TEXT_OBJID_SIZE) + " bytes."); } } else { if (objid.length() >= MAX_TEXT_OBJID_SIZE) throw std::length_error("objid buffer needs more than " + std::to_string(MAX_TEXT_OBJID_SIZE) + " bytes."); strcpy(var_objid, objid.c_str()); } if (var->val_len > 0) { data = malloc(sizeof(u_char) * (var->val_len + 1)); memcpy(data, (void *) var->val.bitstring, var->val_len); str = (char *) data; str[var->val_len] = '\0'; retVal = new SnmpResponse(std::string(var_objid), data, var->val_len, var->type); } else if (var->val_len == 0) { retVal = new SnmpResponse(std::string(var_objid)); } else { retVal = new SnmpResponse(std::string(var_objid), "No data " + objid + "."); } } } else { if (status == STAT_SUCCESS) retVal = new SnmpResponse(snmp_errstring(response->errstat)); else if (status == STAT_TIMEOUT) retVal = new SnmpResponse("Timeout: no response from " + peerName + "."); else retVal = new SnmpResponse("Request generic error."); } if (response) snmp_free_pdu(response); return retVal; }
_______________________________________________ Net-snmp-users mailing list Net-snmp-users@lists.sourceforge.net Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users