NO_SUCH_INSTANCE exception not being caught in v2c - snmp++
Pallavi Mahajan
pallavi.mahajan____baypackets.com
Tue Jul 29 12:45:37 CEST 2003
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
-------------- next part --------------
#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