This is a discussion on Re: noSuchName within the SNMP Coders forums, part of the Networking and Network Related category; --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 27, 2005 at 02:31:52PM +...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
--6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 27, 2005 at 02:31:52PM +0100, Dave Shield wrote: > On Tue, 2005-09-27 at 13:05 +0100, Patrick Welche wrote: > > Good plan: snmpget: > > > > { GetRequest(28) R=86800923 system.sysUpTime.0 } > > { GetResponse(32) R=86800923 system.sysUpTime.0=1062737154 } > > > > and my broken programme: > > > > { GetRequest(36) R=1548568929 system.sysUpTime.0 .0.0.0.0.0[|snmp] } > > { GetResponse(36) R=1548568929 noSuchName@2 system.sysUpTime.0= .0.0.0.0.0=[|snmp] } > > So it's adding two varbinds instead of one > (the second of which is bogus) ah - so the question is, what is the life cycle of a pdu? pdu=snmp_pdu_create(SNMP_MSG_GET); gets me an empty pdu snmp_add_null_var snmp_add_null_var adds two oids to it snmp_sess_synch_response sends them off and snmp_free_pdu core dumps saying its already free ? Given the simple code attached, I still see GetRequest(36) R=869755998 system.sysUpTime.0 .iso.org.dod.internet.mgmt[|snmp] ^^^^^^^^^^^^^^^^^^^^^^^^^^ this extra stuff as opposed to GetRequest(28) R=736117813 system.sysUpTime.0 from snmpget. Still playing spot the difference.. Any tips/hints? Cheers, Patrick --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bit.c" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> void do_send(void *sessp, netsnmp_pdu *pdu, netsnmp_pdu *response, netsnmp_session *ss) { int i, status; netsnmp_variable_list *vars; status = snmp_sess_synch_response(sessp, pdu, &response); if (status == STAT_SUCCESS) { if ((response)->errstat == SNMP_ERR_NOERROR) { printf("All...\n"); for (vars = (response)->variables; vars; vars = vars->next_variable) print_variable(vars->name, vars->name_length, vars); printf("...OK\n"); } else { fprintf(stderr, "Error in packet.\nReason %d/%ld: %s\n",snmp_errno,response->errstat, snmp_errstring((response)->errstat)); if ((response)->errindex != 0) { fprintf(stderr, "Failed object: "); for (i = 1, vars = (response)->variables; vars && (i != (response)->errindex); vars = vars->next_variable, i++); if (vars) fprint_objid(stderr, vars->name, vars->name_length); fprintf(stderr, "\n"); } exit(2); } } else if (status == STAT_TIMEOUT) { fprintf(stderr, "Timeout: No Response\n"); exit(1); } else { /* status == STAT_ERROR */ snmp_sess_perror("do_snmp", ss); exit(1); } } int main() { #define NOIDS 3 static const char *varname[]={ "SNMPv2-MIB::sysUpTime.0", "SNMPv2-MIB::sysDescr.0", "IF-MIB::ifIndex.1" }; void *sessp; netsnmp_session session, *ss; netsnmp_pdu *pdu; netsnmp_pdu *response; oid value[NOIDS][MAX_OID_LEN]; size_t valuelen[NOIDS]; int i, failures; struct tree *mibtree; /* just to keep gcc quiet */ response=NULL; init_snmp("test"); snmp_sess_init(&session); session.peername="localhost"; session.version=SNMP_VERSION_1; session.community="hello"; session.community_len=strlen(session.community); SOCK_STARTUP; /* ?? */ sessp=snmp_sess_open(&session); ss=snmp_sess_session(sessp); if(ss==NULL) { snmp_perror("Couldn't establish the session"); exit(1); } init_mib(); mibtree=read_module("SNMPv2-MIB"); mibtree=read_module("IF-MIB"); /* parse all oids */ failures=0; for (i=0; i<NOIDS; ++i) { valuelen[i]=sizeof(value[i])/sizeof(oid); if (!snmp_parse_oid(varname[i], value[i], &valuelen[i])) { snmp_perror(varname[i]); failures++; } fprintf(stderr,"%2d,%3d: ",i,valuelen[i]); fprint_objid(stderr,value[i],valuelen[i]); }; if (failures) { SOCK_CLEANUP; exit(1); } pdu=snmp_pdu_create(SNMP_MSG_GET); snmp_add_null_var(pdu,value[0],valuelen[0]); snmp_add_null_var(pdu,value[1],valuelen[1]); do_send(sessp, pdu, response, ss); snmp_free_pdu(pdu); if (response) snmp_free_pdu(response); pdu=snmp_pdu_create(SNMP_MSG_GET); value[2][valuelen[2]-1]=1; snmp_add_null_var(pdu,value[2],valuelen[2]); value[2][valuelen[2]-1]=2; snmp_add_null_var(pdu,value[2],valuelen[2]); value[2][valuelen[2]-1]=3; snmp_add_null_var(pdu,value[2],valuelen[2]); do_send(sessp, pdu, response, ss); snmp_free_pdu(pdu); if (response) snmp_free_pdu(response); shutdown_mib(); snmp_sess_close(sessp); return 0; } --6sX45UoQRIJXqkqR-- ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/...et-snmp-coders |