summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-12-01 00:09:15 +0000
committermrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-12-01 00:09:15 +0000
commita50077501c0e9d965ff98c17185ef4565996b8b3 (patch)
tree1b8df033368b83d4698b68e7ac69cb48a2e99888
parent2d4911a6120251fb5584ac28fde4cc5dc4ab5b44 (diff)
downloadATCD-a50077501c0e9d965ff98c17185ef4565996b8b3.tar.gz
Updates for 1.6 (Eric Newton's changes)
Fix makefile to add -lasnmp to bld
-rw-r--r--ASNMP/agent/Makefile10
-rw-r--r--ASNMP/asnmp/address.cpp18
-rw-r--r--ASNMP/asnmp/asn1.cpp5
-rw-r--r--ASNMP/asnmp/ctr64.cpp5
-rw-r--r--ASNMP/asnmp/integer.cpp6
-rw-r--r--ASNMP/asnmp/octet.cpp2
-rw-r--r--ASNMP/asnmp/oid.cpp6
-rw-r--r--ASNMP/asnmp/oid.h2
-rw-r--r--ASNMP/asnmp/pdu.cpp25
-rw-r--r--ASNMP/asnmp/snmp.cpp54
-rw-r--r--ASNMP/asnmp/snmp.h24
-rw-r--r--ASNMP/asnmp/target.cpp8
-rw-r--r--ASNMP/asnmp/target.h2
-rw-r--r--ASNMP/asnmp/transaction.cpp55
-rw-r--r--ASNMP/asnmp/transaction.h15
-rw-r--r--ASNMP/asnmp/vb.cpp12
-rw-r--r--ASNMP/asnmp/wpdu.cpp2
-rw-r--r--ASNMP/asnmp/wpdu.h2
-rw-r--r--ASNMP/examples/get/Makefile4
-rw-r--r--ASNMP/examples/get/get.cpp2
20 files changed, 185 insertions, 74 deletions
diff --git a/ASNMP/agent/Makefile b/ASNMP/agent/Makefile
index baea2a6d268..e3d1e009596 100644
--- a/ASNMP/agent/Makefile
+++ b/ASNMP/agent/Makefile
@@ -1,13 +1,13 @@
OBJS = main.o snmp_agent.o agent_impl.o
-CC=CC
+CC=g++
INCL = -I$(ACE_ROOT) -I$(ACE_ROOT)/ASNMP
DEBUG = -g
-CFLAGS =$(INCL) -mt $(DEBUG)
-RUNPATH = -R $(ACE_ROOT)/ace:$(ACE_ROOT)/ASNMP/asnmp
-LIBS = -L $(ACE_ROOT)/ASNMP/asnmp -lasnmp -L $(ACE_ROOT)/ace -lACE -lnsl -lsocket
+CFLAGS =$(INCL) $(DEBUG)
+RUNPATH =
+LIBS = -L $(ACE_ROOT)/ASNMP/asnmp -lasnmp -L $(ACE_ROOT)/ace -lACE -ldl -lefence
agent: $(OBJS)
- $(CC) -o agent -mt $(DEBUG) $(OBJS) $(LIBS) $(RUNPATH)
+ $(CC) -o agent $(DEBUG) $(OBJS) $(LIBS) $(RUNPATH)
main.o: main.cpp
diff --git a/ASNMP/asnmp/address.cpp b/ASNMP/asnmp/address.cpp
index 06f56bd7955..b0b890776af 100644
--- a/ASNMP/asnmp/address.cpp
+++ b/ASNMP/asnmp/address.cpp
@@ -490,8 +490,6 @@ int IpAddress::parse_address( const char *inaddr)
// set and return validity flag
in_addr ipAddr;
- hostent *lookupResult;
- char *namePtr = NULL;
char ds[MAXHOSTNAMELEN +1];
// intialize the friendly_name member variable
@@ -534,9 +532,12 @@ int IpAddress::parse_address( const char *inaddr)
int IpAddress::addr_to_friendly()
{
in_addr ipAddr;
- if ((ipAddr.s_addr = ACE_OS::inet_addr(to_string())) == -1)
+ long result = ACE_OS::inet_addr(to_string());
+ if (result == -1)
return -1; // expected a dotted quad!
+ ipAddr.s_addr = result;
+
// set iv_friendly_name_ from ipAddr
if (resolve_to_hostname(ipAddr, iv_friendly_name_) == 0) {
return 0;
@@ -683,7 +684,7 @@ int Address_Iter::next(IpAddress& addr)
IpAddress tmp(*entry_++); // return data
addr = tmp;
- if (*entry_ = NULL)
+ if (*entry_ == NULL)
return 1;
return 0;
}
@@ -2414,7 +2415,8 @@ DecNetAddress::DecNetAddress( const char *inaddr): Address()
valid_flag = parse_address( (char *) inaddr);
DecNetAddress::format_output();
}
-DecNetAddress::DecNetAddress( const DecNetAddress& decaddr)
+
+DecNetAddress::DecNetAddress( const DecNetAddress&)
{
}
@@ -2549,7 +2551,7 @@ AppleTalkAddress::AppleTalkAddress( const char *inaddr): Address()
valid_flag = parse_address( (char *) inaddr);
AppleTalkAddress::format_output();
}
-AppleTalkAddress::AppleTalkAddress( const AppleTalkAddress& decaddr)
+AppleTalkAddress::AppleTalkAddress( const AppleTalkAddress&)
{
}
@@ -2641,8 +2643,8 @@ void AppleTalkAddress::format_output()
{
// if valid format else null it
if ( valid_flag)
- ACE_OS::sprintf( (char *) output_buffer,"%d.%d.%d",address_buffer[0],
- address_buffer[1]), address_buffer[3];
+ ACE_OS::sprintf( (char *) output_buffer,"%d.%d.%d", address_buffer[0],
+ address_buffer[1], address_buffer[3]);
else
output_buffer[0] = 0;
}
diff --git a/ASNMP/asnmp/asn1.cpp b/ASNMP/asnmp/asn1.cpp
index be20caac287..3131a864264 100644
--- a/ASNMP/asnmp/asn1.cpp
+++ b/ASNMP/asnmp/asn1.cpp
@@ -1287,7 +1287,6 @@ int cmu_snmp::build( struct snmp_pdu *pdu, u_char *packet,
u_char *cp;
struct variable_list *vp;
int length;
- long int zero = 0;
int totallength;
length = *out_length;
@@ -1531,10 +1530,8 @@ int cmu_snmp::parse( struct snmp_pdu *pdu,
int len, four;
u_char community[256];
int community_length = 256;
- struct variable_list *vp;
+ struct variable_list *vp = 0;
oid objid[MAX_NAME_LEN], *op;
- u_char *origdata = data;
- int origlength = length;
// authenticates message and returns length if valid
data = cmu_snmp::auth_parse(data,
diff --git a/ASNMP/asnmp/ctr64.cpp b/ASNMP/asnmp/ctr64.cpp
index f6a080354ee..799ba76b83f 100644
--- a/ASNMP/asnmp/ctr64.cpp
+++ b/ASNMP/asnmp/ctr64.cpp
@@ -200,9 +200,10 @@ int Counter64::valid() const
char * Counter64::to_string()
{
if ( high() != 0 )
- sprintf(output_buffer, "0x%X%08X", high(), low());
+ sprintf(output_buffer, "0x%X%08X",
+ (unsigned int)high(), (unsigned int)low());
else
- sprintf(output_buffer, "%d", low());
+ sprintf(output_buffer, "%d", (int) low());
return output_buffer;
}
diff --git a/ASNMP/asnmp/integer.cpp b/ASNMP/asnmp/integer.cpp
index 69ffc81446e..dacee4ffab6 100644
--- a/ASNMP/asnmp/integer.cpp
+++ b/ASNMP/asnmp/integer.cpp
@@ -61,7 +61,7 @@ SmiUINT32 SnmpUInt32::get_syntax()
}
// object validity
-SnmpUInt32::valid( void) const
+int SnmpUInt32::valid( void) const
{
return valid_flag;
}
@@ -120,7 +120,7 @@ SnmpSyntax* SnmpUInt32::clone() const
// ASCII format return
char * SnmpUInt32::to_string()
{
- sprintf(output_buffer, "%d", this->smival.value.uNumber);
+ sprintf(output_buffer, "%d", (int) (this->smival.value.uNumber));
return output_buffer;
}
@@ -219,7 +219,7 @@ SnmpSyntax* SnmpInt32::clone() const
char *SnmpInt32::to_string()
{
- sprintf(output_buffer, "%d", (long) this->smival.value.sNumber);
+ sprintf(output_buffer, "%d", (int) (long) this->smival.value.sNumber);
return output_buffer;
}
diff --git a/ASNMP/asnmp/octet.cpp b/ASNMP/asnmp/octet.cpp
index c35d1dea3a9..3e061a43b29 100644
--- a/ASNMP/asnmp/octet.cpp
+++ b/ASNMP/asnmp/octet.cpp
@@ -471,7 +471,7 @@ SnmpSyntax * OctetStr::clone() const
//================[ ASCII format return ]=============================
char * OctetStr::to_string()
{
- for ( long i=0; i < smival.value.string.len; i++) {
+ for ( unsigned long i=0; i < smival.value.string.len; i++) {
if (( smival.value.string.ptr[i] != '\r')&&
( smival.value.string.ptr[i] != '\n')&&
(isprint((int) (smival.value.string.ptr[i]))==0))
diff --git a/ASNMP/asnmp/oid.cpp b/ASNMP/asnmp/oid.cpp
index a350af60de3..fbd309cd1f0 100644
--- a/ASNMP/asnmp/oid.cpp
+++ b/ASNMP/asnmp/oid.cpp
@@ -62,7 +62,7 @@ Oid::Oid( const char * dotted_oid_string, size_t size)
return;
}
- if (size == -1)
+ if (size == (unsigned int)-1)
size = z;
if (size > z)
size = z;
@@ -118,7 +118,7 @@ Oid::Oid(const unsigned long *raw_oid, size_t oid_len)
if (raw_oid && oid_len > 0) {
ACE_NEW(smival.value.oid.ptr, SmiUINT32[ oid_len]);
smival.value.oid.len = oid_len;
- for (int i=0; i < oid_len; i++)
+ for (size_t i=0; i < oid_len; i++)
smival.value.oid.ptr[i] = raw_oid[i];
}
}
@@ -515,7 +515,7 @@ int Oid::suboid(Oid& new_oid, size_t start, size_t how_many)
if (how_many == 0)
return 0;
else
- if (how_many == -1)
+ if (how_many == (size_t)-1)
how_many = length();
else
if (how_many > length())
diff --git a/ASNMP/asnmp/oid.h b/ASNMP/asnmp/oid.h
index 5c416a72399..d98a75ccb2b 100644
--- a/ASNMP/asnmp/oid.h
+++ b/ASNMP/asnmp/oid.h
@@ -46,7 +46,7 @@ class ACE_Export Oid: public SnmpSyntax
// Implement RFC 1155 Object Identifier (OID) datatype
{
public:
- Oid( const char * dotted_oid_string = "", size_t size = -1);
+ Oid( const char * dotted_oid_string = "", size_t size = unsigned(-1) );
// constructor using a dotted string
Oid ( const Oid &oid);
diff --git a/ASNMP/asnmp/pdu.cpp b/ASNMP/asnmp/pdu.cpp
index cf3df561e3d..3b45d811a1d 100644
--- a/ASNMP/asnmp/pdu.cpp
+++ b/ASNMP/asnmp/pdu.cpp
@@ -35,15 +35,15 @@
#include "asnmp/pdu.h" // include Pdu class definition
//=====================[ constructor no args ]=========================
-Pdu::Pdu( void): vb_count_(0), pdu_type_(0), validity_(FALSE),
-error_index_(0), request_id_(0), notify_timestamp_(0), error_status_(0),
+Pdu::Pdu( void): vb_count_(0), error_status_(0), error_index_(0),
+validity_(FALSE), request_id_(0), pdu_type_(0), notify_timestamp_(0),
output_(0)
{
}
//=====================[ constructor with vbs_ and count ]==============
-Pdu::Pdu( Vb* pvbs, const int pvb_count): vb_count_(0), pdu_type_(0),
-validity_(FALSE), error_index_(0), request_id_(0), notify_timestamp_(0)
+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)
{
int z; // looping variable
@@ -73,8 +73,9 @@ validity_(FALSE), error_index_(0), request_id_(0), notify_timestamp_(0)
}
//=====================[ constructor with another Pdu instance ]========
-Pdu::Pdu( const Pdu &pdu): vb_count_(0), pdu_type_(0),
-validity_(FALSE), error_index_(0), request_id_(0), notify_timestamp_(0)
+Pdu::Pdu( const Pdu &pdu): vb_count_(0),
+error_index_(0), validity_(FALSE), request_id_(0), pdu_type_(0),
+notify_timestamp_(0)
{
*this = pdu;
return;
@@ -152,14 +153,16 @@ char * Pdu::to_string()
// determine how big a buffer and allocate it
const int HEADER_STR = 100;
unsigned size = HEADER_STR; // header takes up this much room
- for ( int z = 0; z < vb_count_; z++)
+ int z;
+
+ for ( z = 0; z < vb_count_; z++)
size += ACE_OS::strlen(vbs_[z]->to_string());
ACE_NEW_RETURN(output_, char[size], "");
// print pdu header info
sprintf(output_, "pdu: valid: %d type:%d, req:%d, cnt: %d, err stat: %d \
- err idx: %d\n", validity_, pdu_type_, request_id_,
+ err idx: %d\n", validity_, pdu_type_, (int) request_id_,
vb_count_, error_status_, error_index_ );
// now append vb pairs in this object
@@ -182,7 +185,8 @@ int Pdu::get_vblist( Vb* pvbs, const int pvb_count)
return FALSE;
// loop through all vbs_ and assign to params
- for (int z = 0; z < pvb_count; z++)
+ int z;
+ for (z = 0; z < pvb_count; z++)
pvbs[z] = *vbs_[z];
return TRUE;
@@ -198,7 +202,8 @@ int Pdu::set_vblist( Vb* pvbs, const int pvb_count)
return FALSE;
// free up current vbs_
- for ( int z = 0; z < vb_count_; z++)
+ int z;
+ for ( z = 0; z < vb_count_; z++)
delete vbs_[z];
vb_count_ = 0;
diff --git a/ASNMP/asnmp/snmp.cpp b/ASNMP/asnmp/snmp.cpp
index d1a8e05d02b..357b4e1537e 100644
--- a/ASNMP/asnmp/snmp.cpp
+++ b/ASNMP/asnmp/snmp.cpp
@@ -51,7 +51,7 @@ const authenticationFailureOid authenticationFailure;
const egpNeighborLossOid egpNeighborLoss;
const snmpTrapEnterpriseOid snmpTrapEnterprise;
-Snmp::Snmp(unsigned short port): construct_status_(SNMP_CLASS_ERROR), last_transaction_status_(0)
+Snmp::Snmp(unsigned short port): result_(0), construct_status_(SNMP_CLASS_ERROR), last_transaction_status_(0)
{
ACE_TRACE("Snmp::Snmp");
@@ -115,7 +115,7 @@ int Snmp::run_transaction(Pdu& pdu, UdpTarget& target)
int rc, done = 0;
// 1. set unique id to match this packet on return
- int hold_req_id = req_id_++;
+ size_t hold_req_id = req_id_++;
set_request_id(&pdu, hold_req_id);
// 2. write request to agent
@@ -137,6 +137,43 @@ int Snmp::run_transaction(Pdu& pdu, UdpTarget& target)
return 0;
}
+int Snmp::run_transaction(Pdu& pdu, UdpTarget& target, Snmp_Result * cb)
+{
+ if (!cb)
+ return run_transaction(pdu, target);
+
+ // 1. set unique id to match this packet on return
+ hold_req_id_ = req_id_++;
+ set_request_id(&pdu, hold_req_id_);
+ pdu_ = &pdu;
+ result_ = cb;
+
+ // 2. write request to agent
+ transaction * trans = new transaction(pdu, target, iv_snmp_session_);
+ return trans->run(this);
+}
+
+void Snmp::result(transaction *t, int rc)
+{
+ t->result(*pdu_);
+ // verify this is the pdu we are after
+ if (pdu_->get_request_id() == hold_req_id_)
+ {
+ last_transaction_status_ = rc;
+ delete t;
+ result_->result(this, rc);
+ }
+ else
+ {
+ rc = t->run(this);
+ if (rc < 0)
+ {
+ delete t;
+ result_->result(this, rc);
+ }
+ }
+}
+
int Snmp::validate_args(const Pdu& pdu, const UdpTarget& target) const
{
// 0. check object status
@@ -150,7 +187,7 @@ int Snmp::validate_args(const Pdu& pdu, const UdpTarget& target) const
}
// SYNC API: write request to wire then wait for reply or timeout
-int Snmp::get( Pdu &pdu, UdpTarget &target)
+int Snmp::get( Pdu &pdu, UdpTarget &target, Snmp_Result * cb)
{
ACE_TRACE("Snmp::get");
int rc;
@@ -159,10 +196,10 @@ int Snmp::get( Pdu &pdu, UdpTarget &target)
pdu.set_type( sNMP_PDU_GET);
check_default_port(target);
- return run_transaction(pdu, target);
+ return run_transaction(pdu, target, cb);
}
-int Snmp::get_next( Pdu &pdu, UdpTarget &target)
+int Snmp::get_next( Pdu &pdu, UdpTarget &target, Snmp_Result * cb)
{
ACE_TRACE("Snmp::get_next");
int rc;
@@ -171,10 +208,10 @@ int Snmp::get_next( Pdu &pdu, UdpTarget &target)
pdu.set_type( sNMP_PDU_GETNEXT);
check_default_port(target);
- return run_transaction(pdu, target);
+ return run_transaction(pdu, target, cb);
}
-int Snmp::set( Pdu &pdu, UdpTarget &target)
+int Snmp::set( Pdu &pdu, UdpTarget &target, Snmp_Result * cb)
{
ACE_TRACE("Snmp::set");
int rc;
@@ -183,7 +220,7 @@ int Snmp::set( Pdu &pdu, UdpTarget &target)
pdu.set_type( sNMP_PDU_SET);
check_default_port(target);
- return run_transaction(pdu, target);
+ return run_transaction(pdu, target, cb);
}
// one way, best of luck, non-confirmed alert
@@ -206,4 +243,5 @@ int Snmp::trap( Pdu &pdu, UdpTarget &target)
return -1;
}
+Snmp_Result::~Snmp_Result() {}
diff --git a/ASNMP/asnmp/snmp.h b/ASNMP/asnmp/snmp.h
index cca2dd7be6e..a26a90fb2aa 100644
--- a/ASNMP/asnmp/snmp.h
+++ b/ASNMP/asnmp/snmp.h
@@ -45,27 +45,39 @@
#include "asnmp/pdu.h" // snmp++ pdu class
#include "asnmp/snmperrs.h" // error macros and strings
#include "asnmp/address.h" // snmp++ address class defs
+#include "asnmp/transaction_result.h"
+
+class Snmp;
+class ACE_Export Snmp_Result
+{
+ public:
+ virtual ~Snmp_Result();
+ virtual void result(Snmp *snmp, int result) = 0;
+};
// Snmp session class - supports Version 1 operations in blocking mode
-class ACE_Export Snmp
+class ACE_Export Snmp : public transaction_result
// = TITLE
// Concrete class Snmp defined the session and interface to
// communicate with another SNMP Version 1 agent
{
+ Snmp_Result * result_;
+ Pdu * pdu_;
+ unsigned hold_req_id_;
public:
Snmp(unsigned short port = INADDR_ANY);
virtual ~Snmp();
- int get( Pdu &pdu, UdpTarget &target);
+ int get( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
// retrieve data from a peer agent for a given list of oid values
// default port 161
- int get_next( Pdu &pdu, UdpTarget &target);
+ int get_next( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
// retrieve data lexically adjacent to the oids specified in the pdu
// from the peer agent
// default port 161
- int set( Pdu &pdu, UdpTarget &target);
+ int set( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
// set data in the agent from the list of oids in the pdu
// default port 161
@@ -81,9 +93,13 @@ class ACE_Export Snmp
char * error_string();
// retrieve a reason string if any of the above commands fail
+ void result(transaction * t, int rc);
+ // for async transaction results
+
protected:
void check_default_port(UdpTarget& target,unsigned short port=DEF_AGENT_PORT);
int run_transaction(Pdu& pdu, UdpTarget& target);
+ int run_transaction(Pdu& pdu, UdpTarget& target, Snmp_Result * cb);
int validate_args(const Pdu& pdu, const UdpTarget& target) const;
Snmp(const Snmp&);
diff --git a/ASNMP/asnmp/target.cpp b/ASNMP/asnmp/target.cpp
index 00441b8ff75..7cb0a9c99e8 100644
--- a/ASNMP/asnmp/target.cpp
+++ b/ASNMP/asnmp/target.cpp
@@ -46,9 +46,9 @@ OctetStr UdpTarget::default_wr_community_(WRITE_COMM_STR);
//----------------------------------------------------------------------
//--------[ Abstract SnmpTarget Member Functions ]----------------------
//----------------------------------------------------------------------
-SnmpTarget::SnmpTarget(): timeout_(default_timeout_),
- retries_(default_retries_), validity_(FALSE), version_(default_version_),
- max_pdu_size_(default_max_pdu_size_)
+SnmpTarget::SnmpTarget():
+ validity_(FALSE), timeout_(default_timeout_), retries_(default_retries_),
+ max_pdu_size_(default_max_pdu_size_), version_(default_version_)
{
}
@@ -292,7 +292,7 @@ char *UdpTarget::to_string()
sprintf(output_buffer_,"UdpTarget: [ valid: %d addr: %s rd: %s wr: %s \
ver: %d, timeout: %d, retries: %d max_pdu_size: %d]",
valid(), udp_address_.to_string(), read_community_.to_string(),
- write_community_.to_string(), version_, timeout_,
+ write_community_.to_string(), version_, (int) timeout_,
retries_, max_pdu_size_);
return output_buffer_;
}
diff --git a/ASNMP/asnmp/target.h b/ASNMP/asnmp/target.h
index 8480456b9cd..ffa080a0e02 100644
--- a/ASNMP/asnmp/target.h
+++ b/ASNMP/asnmp/target.h
@@ -133,7 +133,7 @@ class ACE_Export SnmpTarget
protected:
SnmpTarget();
- SnmpTarget(const& SnmpTarget);
+ // SnmpTarget(const SnmpTarget &);
int validity_;
// used by derived class instances
diff --git a/ASNMP/asnmp/transaction.cpp b/ASNMP/asnmp/transaction.cpp
index 8e9146efdbc..c28bb29908c 100644
--- a/ASNMP/asnmp/transaction.cpp
+++ b/ASNMP/asnmp/transaction.cpp
@@ -28,6 +28,7 @@ inline void reset_receive_buffer(iovec& io)
transaction::transaction(const Pdu& pdu, const UdpTarget& target,
ACE_SOCK_Dgram& io):
+ result_(0),
wp_(pdu,target), params_(target), session_(io)
{
// last step, convert address (get ride of this once we have merged address
@@ -48,7 +49,7 @@ transaction::~transaction()
int transaction::run()
{
int rc, done = FALSE;
- unsigned retry_counter = 0;
+ int retry_counter = 0;
ACE_Time_Value to(params_.get_timeout(), 0); // seconds
ACE_Reactor reactor;
@@ -79,21 +80,65 @@ int transaction::run()
return SNMP_CLASS_INTERNAL_ERROR;
}
}
+ return SNMP_CLASS_INTERNAL_ERROR;
+}
+
+// implement state machine, send, wait (timeout/results) return
+int transaction::run(transaction_result * r)
+{
+ result_ = r;
+ int rc;
+
+ // 1. register io port for read access
+ ACE_Reactor * reactor = ACE_Reactor::instance();
+ if (reactor->register_handler(session_.get_handle(),
+ this,
+ READ_MASK) == -1)
+ return SNMP_CLASS_INTERNAL_ERROR;
+ retry_counter_ = 0;
+
+ // register a time handler and a socket with this
+ ACE_Time_Value to = params_.get_timeout();
+ if (reactor->schedule_timer(this, 0, to, to) < 0)
+ return SNMP_CLASS_INTERNAL_ERROR;
+
+ if ((rc = send()) < 0) // send pkt to agent
+ return rc;
+ return 0;
}
// got back response from SNMPv1 agent - process it
-int transaction::handle_input (ACE_HANDLE fd)
+int transaction::handle_input (ACE_HANDLE)
{
// OS allocates iovec_.iov_base ptr and len
int rc = session_.recv(&receive_iovec_, receive_addr_, 0);
if (rc == -1) {
- return SNMP_CLASS_RESOURCE_UNAVAIL;
+ if (result_)
+ result_->result(this, SNMP_CLASS_RESOURCE_UNAVAIL);
+ return SNMP_CLASS_RESOURCE_UNAVAIL;
+ }
+ if (result_)
+ {
+ result_->result(this, rc);
+ return 0;
}
-
return rc;
}
+int transaction::handle_timeout(const ACE_Time_Value &,
+ const void *)
+{
+ int rc;
+ if ((rc = send()) < 0) // send pkt to agent
+ result_->result(this, 0);
+ else
+ if (retry_counter_++ > params_.get_retry())
+ result_->result(this, SNMP_CLASS_TIMEOUT);
+
+ return 0;
+}
+
const ACE_INET_Addr& transaction::get_from_addr() const
{
@@ -136,3 +181,5 @@ int transaction::send()
ssize_t rc = session_.send (io.iov_base, io.iov_len, addr_ , 0);
return rc;
}
+
+transaction_result::~transaction_result() {}
diff --git a/ASNMP/asnmp/transaction.h b/ASNMP/asnmp/transaction.h
index 87c9654be3b..20bf58f29e9 100644
--- a/ASNMP/asnmp/transaction.h
+++ b/ASNMP/asnmp/transaction.h
@@ -7,13 +7,9 @@
// asnmp
//
// = FILENAME
-// snmp.h
+// transaction.h
//
// = DESCRIPTION
-// SNMP class defintion. The Snmp class provides an object oriented
-// approach to SNMP. The SNMP class is an encapsulation of SNMP
-// sessions, gets, sets, etc. The class manages all SNMP
-// resources and provides complete retry and timeout capability.
//
// = AUTHOR
// Michael R. MacFaden port to ACE / use Reactor pattern
@@ -23,6 +19,7 @@
#include "ace/Event_Handler.h"
#include "asnmp/target.h"
#include "asnmp/pdu.h"
+#include "asnmp/transaction_result.h"
#include "asnmp/wpdu.h" // cmu adapter class
#include "ace/SOCK_Dgram.h"
@@ -32,15 +29,19 @@ class ACE_Export transaction : public ACE_Event_Handler
// two SNMP agents. Uses SnmpTarget class to implement retry/timeout
{
+ int retry_counter_;
+ transaction_result * result_;
+
public:
transaction(const Pdu& pdu, const UdpTarget& target, ACE_SOCK_Dgram& io);
- transaction(ACE_SOCK_Dgram& io):session_(io) { }
+ transaction(ACE_SOCK_Dgram& io):result_(0), session_(io) { }
// constructor
~transaction();
// destructor
int run();
+ 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;
@@ -49,6 +50,8 @@ class ACE_Export transaction : public ACE_Event_Handler
virtual int handle_input (ACE_HANDLE fd);
// called by reactor when data is ready to be read in from OS memory
+ virtual int handle_timeout (const ACE_Time_Value &, const void *);
+ // used for resend in asynchronous run()
int send();
// transmit buffer command to network...
diff --git a/ASNMP/asnmp/vb.cpp b/ASNMP/asnmp/vb.cpp
index 923381121dc..4de5104f9e0 100644
--- a/ASNMP/asnmp/vb.cpp
+++ b/ASNMP/asnmp/vb.cpp
@@ -42,22 +42,22 @@
//---------------[ Vb::Vb( void) ]--------------------------------------
// constructor with no arguments
// makes an vb, unitialized
-Vb::Vb( void): iv_vb_value_(NULL), exception_status_(SNMP_CLASS_SUCCESS),
- output_(NULL)
+Vb::Vb( void): output_(NULL), iv_vb_value_(NULL),
+ exception_status_(SNMP_CLASS_SUCCESS)
{
}
//---------------[ Vb::Vb( const Oid &oid) ]-----------------------------
// constructor to initialize the oid
// makes a vb with oid portion initialized
-Vb::Vb( const Oid &oid): iv_vb_oid_(oid), iv_vb_value_(NULL),
- exception_status_(SNMP_CLASS_SUCCESS), output_(NULL)
+Vb::Vb( const Oid &oid): output_(NULL), iv_vb_oid_(oid), iv_vb_value_(NULL),
+ exception_status_(SNMP_CLASS_SUCCESS)
{
}
//---------------[ Vb::Vb( const Oid &oid, const SmiSyntax &val) ]-------
Vb::Vb( const Oid &oid, const SnmpSyntax &val, const SmiUINT32 status):
- iv_vb_oid_(oid), iv_vb_value_(NULL), exception_status_(status), output_(NULL)
+ output_(NULL), iv_vb_oid_(oid), iv_vb_value_(NULL), exception_status_(status)
{
// iv_vb_value_ = recast_smi_object(val); // allocate and construct object
iv_vb_value_ = val.clone();
@@ -65,7 +65,7 @@ Vb::Vb( const Oid &oid, const SnmpSyntax &val, const SmiUINT32 status):
//---------------[ Vb::Vb( const Vb &vb) ]-----------------------------
// copy constructor
-Vb::Vb( const Vb &vb): iv_vb_value_(NULL), output_(NULL)
+Vb::Vb( const Vb &vb): output_(NULL), iv_vb_value_(NULL)
{
*this = vb;
}
diff --git a/ASNMP/asnmp/wpdu.cpp b/ASNMP/asnmp/wpdu.cpp
index d06bfbe6080..6b0f6f06c02 100644
--- a/ASNMP/asnmp/wpdu.cpp
+++ b/ASNMP/asnmp/wpdu.cpp
@@ -159,6 +159,7 @@ int wpdu::set_trap_info(snmp_pdu *raw_pdu, const Pdu& pdu) const
TimeTicks timestamp;
pdu.get_notify_timestamp( timestamp);
raw_pdu->time = ( unsigned long) timestamp;
+ return 0;
}
wpdu::wpdu(const iovec& iov): valid_flag_(FALSE),comm_len(MAX_COMM_STR_LEN)
@@ -305,6 +306,7 @@ int wpdu::convert_vb_to_smival( Vb &tempvb, SmiVALUE *smival )
}
}
}
+ break;
default:
ACE_DEBUG((LM_DEBUG, "wpdu::convert_vb_to_smival did not convert vb\n"));
diff --git a/ASNMP/asnmp/wpdu.h b/ASNMP/asnmp/wpdu.h
index 2d4df6a2664..51b9e4ebe55 100644
--- a/ASNMP/asnmp/wpdu.h
+++ b/ASNMP/asnmp/wpdu.h
@@ -27,7 +27,7 @@
// this is an adapter class, it peforms the following transformations
// PDU / Target -> iovec buffer
// iovec buffer -> PDU / Target
-
+struct snmp_pdu;
class ACE_Export wpdu
// = TITLE
// Implement an Adapter pattern between CMU SNMP and HP SNMP++
diff --git a/ASNMP/examples/get/Makefile b/ASNMP/examples/get/Makefile
index efba9b7161f..6849f0d6fd8 100644
--- a/ASNMP/examples/get/Makefile
+++ b/ASNMP/examples/get/Makefile
@@ -10,10 +10,10 @@
# ACE+SNMP
-BIN = get
+BIN = get get_async
CCFLAGS = -I$(ACE_ROOT)/ASNMP/
LSRC = $(addsuffix .cpp,$(BIN))
-VLDLIBS = -R$(ACE_ROOT)/ASNMP/asnmp -L$(ACE_ROOT)/ASNMP/asnmp -lasnmp $(LDLIBS:%=%$(VAR))
+LDLIBS := -L$(ACE_ROOT)/ASNMP/asnmp -lasnmp $(LDLIBS:%=%$(VAR))
BUILD = $(VBIN)
diff --git a/ASNMP/examples/get/get.cpp b/ASNMP/examples/get/get.cpp
index 5df6adfbf48..c6a9d7d0d8a 100644
--- a/ASNMP/examples/get/get.cpp
+++ b/ASNMP/examples/get/get.cpp
@@ -69,7 +69,7 @@ int main( int argc, char *argv[])
return 1;
}
-getapp::valid() const
+int getapp::valid() const
{
return valid_;
}