NO_SUCH_INSTANCE exception not being caught in v2c - snmp++

Frank Fock Frank.Fock____t-online.de
Wed Jul 30 08:50:50 CEST 2003


Hi Pallavi,

As you mentioned in your subject, with SNMPv2c or SNMPv3
there will be no error status set if you request an
object that does not exist. Instead, an exception syntax
is returned. Thus, you will have to check the syntax of
the object for noSuchInstance, noSuchObject, and endOfMibView
exceptions.

Best regards,
Frank Fock

Pallavi Mahajan wrote:
> Hi,
> 
> Attached is a simple snmpGet program using snmp++, which tries to fetch the value of an OID.
> In case I enter a wrong OID, no error is returned, instead the value returned is "".
> 
> If I do the same by changing the version to v1, a proper error is returned in case of wrong OID.
> 
> For example: in the program attached which uses v2c:
> If I enter 1.3.6.1.2.1.1.5 (sysName) as the OID, I should get a proper error; whereas i dont get any error, but get a value of "".
> If I enter 1.3.6.1.2.1.1.5.0 (sysName.0) as the OID, I get the proper sysName value.
> 
> Please let me know if this is a known bug, or is there something wrong in our handling.
> 
> Regards,
> Pallavi
> 
> 
> ------------------------------------------------------------------------
> 
> #include <iostream.h>
> #include <snmp_pp.h>
> 
> #define SYSNAME_OID "1.3.6.1.2.1.1.5.0"
> 
> main()
> {
> 	int status;
> 	Snmp snmp(status);
> 	if (status != SNMP_CLASS_SUCCESS)
> 	{
> 		cout << "ERROR in initializing:: " << snmp.error_msg(status) << endl;
> 		return 0;
> 	}
> 
> 	char ip[200];
> 	cout << "Enter IP of the machine to be managed: ";
> 	cin >> ip;
> 
> 	int port;
> 	cout << "Enter port: ";
> 	cin >> port;
> 
> 	UdpAddress address(ip);
> 	address.set_port(port);
> 	CTarget ctarget( address);
> 	//CTarget ctarget( (IpAddress)ip);
> 	ctarget.set_version(version2c);
> 
> 	char sysname_oid[100];
> 	cout << "enter oid: (1 for sysname) ";
> 	cin >> sysname_oid;
> 
> 	if (strcmp(sysname_oid, "1") == 0)
> 		strcpy(sysname_oid, SYSNAME_OID);
> 
> 	Pdu pdu;
> 	Vb vb(sysname_oid);
> 	pdu += vb;
> 
> 	if ( (status = snmp.get(pdu, ctarget))  != SNMP_CLASS_SUCCESS )
> 	{
> 		cout << "error #: " << status << endl;
> 		cout << "ERROR in get..:: " << snmp.error_msg(status) << endl;
> 		return 0;
> 	}
> 	else
> 	{
> 		pdu.get_vb(vb, 0);
> 		if (strcmp(vb.get_printable_value(), ""))
> 			cout << "Value = " << vb.get_printable_value() << endl;
> 		else
> 			cout << "error.." << endl;
> 	}
> 
> 	return 1;
> }






More information about the AGENTPP mailing list