From f08b94a47c3de253f486f254abf220448d16db75 Mon Sep 17 00:00:00 2001 From: mrm Date: Mon, 8 Dec 1997 20:29:45 +0000 Subject: Eric Newton fixes --- ASNMP/agent/Makefile | 11 ++++++++--- ASNMP/agent/agent_impl.cpp | 2 +- ASNMP/asnmp/pdu.cpp | 5 +++-- ASNMP/asnmp/sagent.cpp | 7 ++++--- ASNMP/asnmp/transaction.cpp | 16 +++++++++++++++- ASNMP/asnmp/transaction.h | 5 ++--- ASNMP/asnmp/vb.cpp | 21 +++++++++++++-------- ASNMP/asnmp/wpdu.cpp | 2 ++ ASNMP/examples/walk/Makefile | 2 +- ASNMP/tests/Octet_Test.cpp | 4 ++-- 10 files changed, 51 insertions(+), 24 deletions(-) diff --git a/ASNMP/agent/Makefile b/ASNMP/agent/Makefile index e3d1e009596..043ccfa45e0 100644 --- a/ASNMP/agent/Makefile +++ b/ASNMP/agent/Makefile @@ -1,10 +1,15 @@ +# Sample SNMPv1 Agent +# Makefile for Solaris 2.x +# $Id$ + OBJS = main.o snmp_agent.o agent_impl.o -CC=g++ INCL = -I$(ACE_ROOT) -I$(ACE_ROOT)/ASNMP -DEBUG = -g +CC=CC +SOL_FLAGS=-mt -R $(ACE_ROOT)/ASNMP/asnmp:$(ACE_ROOT)/ace +DEBUG = -g $(SOL_FLAGS) CFLAGS =$(INCL) $(DEBUG) RUNPATH = -LIBS = -L $(ACE_ROOT)/ASNMP/asnmp -lasnmp -L $(ACE_ROOT)/ace -lACE -ldl -lefence +LIBS = -L $(ACE_ROOT)/ASNMP/asnmp -lasnmp -L $(ACE_ROOT)/ace -lACE -ldl agent: $(OBJS) $(CC) -o agent $(DEBUG) $(OBJS) $(LIBS) $(RUNPATH) diff --git a/ASNMP/agent/agent_impl.cpp b/ASNMP/agent/agent_impl.cpp index 4a2a04062a5..2f456cc2d91 100644 --- a/ASNMP/agent/agent_impl.cpp +++ b/ASNMP/agent/agent_impl.cpp @@ -4,8 +4,8 @@ #include #include #include -#include "agent_impl.h" +#include "agent_impl.h" agent_impl::agent_impl(unsigned short port, const char *rd, const char *wr) : sagent(port) diff --git a/ASNMP/asnmp/pdu.cpp b/ASNMP/asnmp/pdu.cpp index 3b45d811a1d..68c7c0c2fcd 100644 --- a/ASNMP/asnmp/pdu.cpp +++ b/ASNMP/asnmp/pdu.cpp @@ -43,7 +43,8 @@ output_(0) //=====================[ constructor with vbs_ and count ]============== Pdu::Pdu( Vb* pvbs, const int pvb_count): vb_count_(0), error_index_(0), -validity_(FALSE), request_id_(0), pdu_type_(0), notify_timestamp_(0) +validity_(FALSE), request_id_(0), pdu_type_(0), notify_timestamp_(0), +output_(0) { int z; // looping variable @@ -75,7 +76,7 @@ validity_(FALSE), request_id_(0), pdu_type_(0), notify_timestamp_(0) //=====================[ constructor with another Pdu instance ]======== Pdu::Pdu( const Pdu &pdu): vb_count_(0), error_index_(0), validity_(FALSE), request_id_(0), pdu_type_(0), -notify_timestamp_(0) +notify_timestamp_(0), output_(0) { *this = pdu; return; diff --git a/ASNMP/asnmp/sagent.cpp b/ASNMP/asnmp/sagent.cpp index d7330815aa0..ed616760f64 100644 --- a/ASNMP/asnmp/sagent.cpp +++ b/ASNMP/asnmp/sagent.cpp @@ -8,9 +8,9 @@ // sagent.cpp // // = DESCRIPTION -// SNMP agent class defintion. The sagent class provides an object oriented -// approach for creating SNMP Agents. The sagent class is an encapsulation of SNMP -// sessions, gets, sets, etc. +// SNMP agent class definition. The sagent class provides an object oriented +// approach for creating SNMP Agents. The sagent class is an encapsulation +// of SNMP sessions, gets, sets, etc. // // = AUTHOR // Michael R. MacFaden @@ -86,6 +86,7 @@ ACE_HANDLE sagent::get_handle() const int sagent::respond(Pdu& pdu,UdpTarget& tgt) { + pdu.set_type(sNMP_PDU_RESPONSE); transaction tr(pdu, tgt, iv_snmp_session_); tr.send(); return 0; diff --git a/ASNMP/asnmp/transaction.cpp b/ASNMP/asnmp/transaction.cpp index c28bb29908c..f22126ce469 100644 --- a/ASNMP/asnmp/transaction.cpp +++ b/ASNMP/asnmp/transaction.cpp @@ -42,6 +42,9 @@ transaction::transaction(const Pdu& pdu, const UdpTarget& target, transaction::~transaction() { + ACE_Reactor::instance()->remove_handler(this, READ_MASK | DONT_CALL); + ACE_Reactor::instance()->cancel_timer(this); + delete [] receive_iovec_.iov_base; } @@ -112,8 +115,12 @@ int transaction::run(transaction_result * r) int transaction::handle_input (ACE_HANDLE) { // OS allocates iovec_.iov_base ptr and len + delete [] receive_iovec_.iov_base; + reset_receive_buffer(receive_iovec_); int rc = session_.recv(&receive_iovec_, receive_addr_, 0); if (rc == -1) { + delete [] receive_iovec_.iov_base; + reset_receive_buffer(receive_iovec_); if (result_) result_->result(this, SNMP_CLASS_RESOURCE_UNAVAIL); return SNMP_CLASS_RESOURCE_UNAVAIL; @@ -147,7 +154,7 @@ const ACE_INET_Addr& transaction::get_from_addr() const // return pdu to caller -int transaction::result(Pdu& pdu, char *comm_str, ACE_INET_Addr *from) const +int transaction::result(Pdu& pdu, char *comm_str, ACE_INET_Addr *from) { // TODO: check to see the sender matches the receiver address.. @@ -171,6 +178,13 @@ int transaction::result(Pdu& pdu, char *comm_str, ACE_INET_Addr *from) const return rc; } +transaction::transaction(ACE_SOCK_Dgram& io) +: result_(0), session_(io) +{ + reset_receive_buffer(receive_iovec_); +} + + int transaction::send() { iovec io = wp_.get_buffer(); diff --git a/ASNMP/asnmp/transaction.h b/ASNMP/asnmp/transaction.h index 20bf58f29e9..056f48f68be 100644 --- a/ASNMP/asnmp/transaction.h +++ b/ASNMP/asnmp/transaction.h @@ -34,9 +34,8 @@ class ACE_Export transaction : public ACE_Event_Handler public: transaction(const Pdu& pdu, const UdpTarget& target, ACE_SOCK_Dgram& io); - transaction(ACE_SOCK_Dgram& io):result_(0), session_(io) { } + transaction(ACE_SOCK_Dgram& io); // constructor - ~transaction(); // destructor @@ -44,7 +43,7 @@ class ACE_Export transaction : public ACE_Event_Handler int run(transaction_result *r); // Async interface, with callback object // begin polling for values - int result(Pdu& pdu, char *comm_str = 0, ACE_INET_Addr *from_addr = 0) const; + int result(Pdu& pdu, char *comm_str = 0, ACE_INET_Addr *from_addr = 0); // return pdu with result from agent after run() is completed rc = 0 // optionally get community str diff --git a/ASNMP/asnmp/vb.cpp b/ASNMP/asnmp/vb.cpp index 4de5104f9e0..7767018fa7a 100644 --- a/ASNMP/asnmp/vb.cpp +++ b/ASNMP/asnmp/vb.cpp @@ -217,14 +217,19 @@ int Vb::get_value( SnmpInt32 &i) int Vb::get_value( SnmpUInt32 &u) { - if (iv_vb_value_ && - iv_vb_value_->valid() && - (iv_vb_value_->get_syntax() == sNMP_SYNTAX_UINT32 )) { - u = *((SnmpUInt32 *) iv_vb_value_); - return SNMP_CLASS_SUCCESS; + if (iv_vb_value_ && iv_vb_value_->valid()) + { + SmiUINT32 syntax = iv_vb_value_->get_syntax(); + if (syntax == sNMP_SYNTAX_GAUGE32 || + syntax == sNMP_SYNTAX_CNTR32 || + syntax == sNMP_SYNTAX_TIMETICKS || + syntax == sNMP_SYNTAX_UINT32) + { + u = *((SnmpUInt32 *) iv_vb_value_); + return SNMP_CLASS_SUCCESS; + } } - else - return SNMP_CLASS_INVALID; + return SNMP_CLASS_INVALID; } int Vb::get_value( Gauge32 &g) @@ -355,7 +360,7 @@ char *Vb::to_string() char *ptr = ""; if (iv_vb_value_) ptr = iv_vb_value_->to_string(); - len += ACE_OS::strlen(ptr); + len += ACE_OS::strlen(ptr) + 3 + 1; // " / " + null ACE_NEW_RETURN(output_, char[len], ""); ACE_OS::sprintf(output_, "%s / %s", iv_vb_oid_.to_string(), ptr); return output_; diff --git a/ASNMP/asnmp/wpdu.cpp b/ASNMP/asnmp/wpdu.cpp index 6b0f6f06c02..6922be7d0be 100644 --- a/ASNMP/asnmp/wpdu.cpp +++ b/ASNMP/asnmp/wpdu.cpp @@ -73,6 +73,8 @@ wpdu::wpdu(const Pdu& pdu, const UdpTarget& target): if (set_trap_info(raw_pdu, pdu)) // will free raw_pdu return; break; + case sNMP_PDU_RESPONSE: + break; default: ACE_ASSERT(0); diff --git a/ASNMP/examples/walk/Makefile b/ASNMP/examples/walk/Makefile index 5de4959da60..833fa1311f3 100644 --- a/ASNMP/examples/walk/Makefile +++ b/ASNMP/examples/walk/Makefile @@ -14,7 +14,7 @@ BIN = walk CCFLAGS = -I$(ACE_ROOT)/ASNMP/ LSRC = $(addsuffix .cpp,$(BIN)) -LDLIBS := -L$(ACE_ROOT)/ASNMP/asnmp -lasnmp $(LDLIBS:%=%$(VAR)) +LDLIBS := -L$(ACE_ROOT)/ASNMP/asnmp -lasnmp $(LDLIBS:%=%$(VAR)) BUILD = $(VBIN) diff --git a/ASNMP/tests/Octet_Test.cpp b/ASNMP/tests/Octet_Test.cpp index d5dd7a9d440..618893e57dd 100644 --- a/ASNMP/tests/Octet_Test.cpp +++ b/ASNMP/tests/Octet_Test.cpp @@ -89,9 +89,9 @@ static void TestOctet() { char *str = "A test of octet strings...!@@#$%^&*()_+|~{}:,./<>?"; OctetStr o1; - ACE_ASSERT(o1.valid() == 0); + ACE_ASSERT(o1.valid() == 1); ACE_ASSERT(o1.length() == 0); - ACE_ASSERT(o1.data() == (unsigned char *)0); + ACE_ASSERT(o1.data() != (unsigned char *)0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o1(\"\") [%s]\n", o1.to_string())); o1.set_data((SmiBYTE *)str); -- cgit v1.2.1