int trapapp::run() { if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } if (address_.get_port() == 0) address_.set_port(DEF_TRAP_PORT); target_.set_address( address_); // make a target using the address //-------[ issue the request, blocked mode ]----------------------------- cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \ " TRAP GENERATOR SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n"; target_.get_address(address_); // target updates port used int rc; const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Community=" << community_.to_string() << " ]"<< endl; if (snmp_.trap( pdu_, target_) == SNMP_CLASS_SUCCESS) { cout << "Trap was written to network...\n"; } else { const char *ptr = snmp_.error_string(); cout << "ASNMP:ERROR: trap command failed reason: " << ptr << endl; } cout << "ASNMP:INFO:command completed normally.\n"<< endl; return 0; }
void Snmp::check_default_port(UdpTarget& target, unsigned short port) { UdpAddress tmp; target.get_address(tmp); if (tmp.get_port() == 0) { tmp.set_port(port); target.set_address(tmp); } }
int getapp::run() { //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } //--------[ build up ASNMP object needed ]------------------------------- if (address_.get_port() == 0) address_.set_port(DEF_AGENT_PORT); target_.set_address( address_); // make a target using the address //-------[ issue the request, blocked mode ]----------------------------- cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \ " GET SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n"; target_.get_address(address_); // target updates port used int rc; const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; //FUZZ: disable check_for_lack_ACE_OS cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; //FUZZ: enable check_for_lack_ACE_OS cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; if (snmp_.get( pdu_, target_) == SNMP_CLASS_SUCCESS) { Vb vb; // check to see if there are any errors if (pdu_.get_error_status()) { cout << "ERROR: agent replied as follows\n"; cout << pdu_.agent_error_reason() << endl; } else { VbIter iter(pdu_); while (iter.next(vb)) { cout << "\tOid = " << vb.to_string_oid() << "\n"; cout << "\tValue = " << vb.to_string_value() << "\n"; } } } else { const char *ptr = snmp_.error_string(); cout << "ASNMP:ERROR: get command failed reason: " << ptr << endl; } cout << "\nASNMP:INFO: command completed normally.\n"<< endl; return 0; }
int walkapp::run() { //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } //--------[ build up ASNMP object needed ]------------------------------- if (address_.get_port() == 0) address_.set_port(DEF_AGENT_PORT); target_.set_address( address_); // make a target using the address //-------[ issue the request, blocked mode ]----------------------------- cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \ " WALK SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n"; target_.get_address(address_); // target updates port used int rc; const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; //FUZZ: disable check_for_lack_ACE_OS cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; //FUZZ: enable check_for_lack_ACE_OS cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; MibIter iter(&snmp_, pdu_, &target_); char *err_str = 0; Vb vb; unsigned ctr = 0; while (iter.next(vb, err_str)) { cout << "\tOid = " << vb.to_string_oid() << "\n"; cout << "\tValue = " << vb.to_string_value() << "\n"; ctr++; } if (!err_str) { cout << "ERROR: walk: " << err_str << endl; return 0; } cout << "ASNMP:INFO:command completed normally. ACE Rocks...\n"<< endl; return 0; }
static void TestSnmpTarget() { OctetStr rd("rd_comm"), wr("wr_comm"); ACE_ASSERT(rd.valid() == 1); ACE_ASSERT(wr.valid() == 1); // constructor and get tests UdpAddress ga; ACE_ASSERT(ga.valid() == 0); UdpTarget c1; ACE_ASSERT(c1.valid() == 0); OctetStr a, b("public"), c("private"); c1.get_read_community(a); ACE_ASSERT(a == b); c1.get_write_community(a); ACE_ASSERT(a == c); c1.get_address (ga); ACE_ASSERT(c1.get_version() == version1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c1(\"\") [%s]\n", c1.to_string())); IpAddress ip("127.0.0.1"); UdpTarget c2(ip); ACE_ASSERT(c2.valid() == 1); c2.get_address (ga); ACE_ASSERT(ga.valid() == 1); ACE_ASSERT(c2.get_version() == version1); ACE_ASSERT(ga.valid() == 1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c2(\"\") [%s]\n", c2.to_string())); UdpTarget *c5 = new UdpTarget(c2); ACE_ASSERT(c5 != 0); ACE_ASSERT(c5->valid() == 1); c5->get_address (ga); ACE_ASSERT(ga.valid() == 1); ACE_ASSERT(c5->get_version() == version1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) UdpTarget:c5(\"\") [%s]\n", c5->to_string())); delete c5; // these are not supported yet // ACE_ASSERT(c5 == c5); // c5 = c2; // ACE_ASSERT(c5 == c2); }
int getapp::run() { //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } //--------[ build up ASNMP object needed ]------------------------------- if (address_.get_port() == 0) address_.set_port(DEF_AGENT_PORT); target_.set_address( address_); // make a target using the address //-------[ issue the request, blocked mode ]----------------------------- cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \ " GET SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n"; target_.get_address(address_); // target updates port used int rc; const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; //FUZZ: disable check_for_lack_ACE_OS cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; //FUZZ: enable check_for_lack_ACE_OS cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; if (snmp_.get( pdu_, target_, this) != SNMP_CLASS_SUCCESS) { const char *ptr = snmp_.error_string(); cout << "ASNMP:ERROR: get command failed reason: " << ptr << endl; } else { ACE_Reactor::instance()->run_reactor_event_loop(); } return 0; }