diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2004-04-26 18:36:44 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2004-04-26 18:36:44 +0000 |
commit | 0a6e111495f321bb9582b6035e53101911dcaf9a (patch) | |
tree | 6397567d7351813c552e5133874110ada446abfc /ASNMP/examples | |
parent | 35020bc2dbe4ff5996f09b2c2c68719a44030252 (diff) | |
download | ATCD-0a6e111495f321bb9582b6035e53101911dcaf9a.tar.gz |
ChangeLogTag: Mon Apr 26 18:33:11 UTC 2004 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'ASNMP/examples')
-rw-r--r-- | ASNMP/examples/get/get.cpp | 50 | ||||
-rw-r--r-- | ASNMP/examples/get/get_async.cpp | 54 | ||||
-rw-r--r-- | ASNMP/examples/next/next.cpp | 50 | ||||
-rw-r--r-- | ASNMP/examples/set/set.cpp | 70 | ||||
-rw-r--r-- | ASNMP/examples/trap/trap.cpp | 36 | ||||
-rw-r--r-- | ASNMP/examples/walk/walk.cpp | 64 |
6 files changed, 162 insertions, 162 deletions
diff --git a/ASNMP/examples/get/get.cpp b/ASNMP/examples/get/get.cpp index 983a2bd1ce7..d335ab43f98 100644 --- a/ASNMP/examples/get/get.cpp +++ b/ASNMP/examples/get/get.cpp @@ -9,7 +9,7 @@ // get.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::get API +// Sample application demonstrating synchronous Snmp::get API // to access an SNMP Version 1 agent. // // = AUTHOR @@ -21,7 +21,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -52,7 +52,7 @@ class getapp { int run(); // issue transaction static void usage(); // operator help message - private: + private: getapp(const getapp&); UdpAddress address_; @@ -65,8 +65,8 @@ class getapp { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { getapp get(argc, argv); if (get.valid()) @@ -76,16 +76,16 @@ int main( int argc, char *argv[]) return 1; } -int getapp::valid() const -{ - return valid_; +int getapp::valid() const +{ + return valid_; } getapp::getapp(int argc, char *argv[]): valid_(0) { Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default is sysDescr - if ( argc < 2) - return; - + if ( argc < 2) + return; + address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -98,23 +98,23 @@ getapp::getapp(int argc, char *argv[]): valid_(0) switch (c) { case 'o': - req = get_opt.optarg; - if (req.valid() == 0) - cout << "ERROR: oid value: " <<get_opt.optarg \ + req = get_opt.opt_arg(); + if (req.valid() == 0) + cout << "ERROR: oid value: " <<get_opt.opt_arg() \ << "is not valid. using default.\n"; break; case 'c': - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_read_community(community_); break; case 'r': - target_.set_retry(ACE_OS::atoi (get_opt.optarg)); + target_.set_retry(ACE_OS::atoi (get_opt.opt_arg())); break; case 't': - target_.set_timeout(ACE_OS::atoi (get_opt.optarg)); + target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg())); break; default: @@ -122,9 +122,9 @@ getapp::getapp(int argc, char *argv[]): valid_(0) } Vb vb; // construct a Vb object - if (req.valid()) + if (req.valid()) vb.set_oid( req); // set the Oid portion of the Vb - else { + else { vb.set_oid( def_oid); // set the Oid portion of the Vb } pdu_ += vb; @@ -144,11 +144,11 @@ void getapp::usage() int getapp::run() -{ +{ //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -166,7 +166,7 @@ int getapp::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; @@ -175,8 +175,8 @@ int getapp::run() 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; + cout << "ERROR: agent replied as follows\n"; + cout << pdu_.agent_error_reason() << endl; } else { VbIter iter(pdu_); @@ -193,5 +193,5 @@ int getapp::run() cout << "\nASNMP:INFO: command completed normally.\n"<< endl; return 0; -} +} diff --git a/ASNMP/examples/get/get_async.cpp b/ASNMP/examples/get/get_async.cpp index dbfa7e7c5b9..ff90105591b 100644 --- a/ASNMP/examples/get/get_async.cpp +++ b/ASNMP/examples/get/get_async.cpp @@ -7,7 +7,7 @@ // get.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::get API +// Sample application demonstrating synchronous Snmp::get API // to access an SNMP Version 1 agent. // // = AUTHOR @@ -19,7 +19,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -52,7 +52,7 @@ class getapp : public Snmp_Result { virtual void result(Snmp * r, int rc); - private: + private: getapp(const getapp&); UdpAddress address_; @@ -65,8 +65,8 @@ class getapp : public Snmp_Result { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { getapp get(argc, argv); if (get.valid()) @@ -76,16 +76,16 @@ int main( int argc, char *argv[]) return 1; } -int getapp::valid() const -{ - return valid_; +int getapp::valid() const +{ + return valid_; } getapp::getapp(int argc, char *argv[]): valid_(0) { Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default is sysDescr - if ( argc < 2) - return; - + if ( argc < 2) + return; + address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -98,23 +98,23 @@ getapp::getapp(int argc, char *argv[]): valid_(0) switch (c) { case 'o': - req = get_opt.optarg; - if (req.valid() == 0) - cout << "ERROR: oid value: " <<get_opt.optarg \ + req = get_opt.opt_arg(); + if (req.valid() == 0) + cout << "ERROR: oid value: " <<get_opt.opt_arg() \ << "is not valid. using default.\n"; break; case 'c': - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_read_community(community_); break; case 'r': - target_.set_retry(ACE_OS::atoi (get_opt.optarg)); + target_.set_retry(ACE_OS::atoi (get_opt.opt_arg())); break; case 't': - target_.set_timeout(ACE_OS::atoi (get_opt.optarg)); + target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg())); break; default: @@ -122,9 +122,9 @@ getapp::getapp(int argc, char *argv[]): valid_(0) } Vb vb; // construct a Vb object - if (req.valid()) + if (req.valid()) vb.set_oid( req); // set the Oid portion of the Vb - else { + else { vb.set_oid( def_oid); // set the Oid portion of the Vb } pdu_ += vb; @@ -144,11 +144,11 @@ void getapp::usage() int getapp::run() -{ +{ //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -166,7 +166,7 @@ int getapp::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; @@ -175,10 +175,10 @@ int getapp::run() const char *ptr = snmp_.error_string(); cout << "ASNMP:ERROR: get command failed reason: " << ptr << endl; } else { - ACE_Reactor::instance()->run_event_loop(); + ACE_Reactor::instance()->run_reactor_event_loop(); } return 0; -} +} void getapp::result(Snmp *, int rc) { @@ -190,8 +190,8 @@ void getapp::result(Snmp *, int rc) } else { // 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; + cout << "ERROR: agent replied as follows\n"; + cout << pdu_.agent_error_reason() << endl; } else { VbIter iter(pdu_); @@ -202,5 +202,5 @@ void getapp::result(Snmp *, int rc) } } cout << "\nASNMP:INFO: command completed normally.\n"<< endl; - ACE_Reactor::instance()->end_event_loop(); + ACE_Reactor::instance()->end_reactor_event_loop(); } diff --git a/ASNMP/examples/next/next.cpp b/ASNMP/examples/next/next.cpp index 5d55a94d117..c8c58db88d4 100644 --- a/ASNMP/examples/next/next.cpp +++ b/ASNMP/examples/next/next.cpp @@ -9,7 +9,7 @@ // next.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::get_next API +// Sample application demonstrating synchronous Snmp::get_next API // to access an SNMP Version 1 agent. // // = AUTHOR @@ -20,7 +20,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -51,7 +51,7 @@ class nextapp { int run(); // issue transaction static void usage(); // operator help message - private: + private: nextapp(const nextapp&); UdpAddress address_; @@ -64,8 +64,8 @@ class nextapp { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { nextapp get(argc, argv); if (get.valid()) @@ -75,16 +75,16 @@ int main( int argc, char *argv[]) return 1; } -int nextapp::valid() const -{ - return valid_; +int nextapp::valid() const +{ + return valid_; } nextapp::nextapp(int argc, char *argv[]): valid_(0) { Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default is sysDescr - if ( argc < 2) - return; - + if ( argc < 2) + return; + address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -97,23 +97,23 @@ nextapp::nextapp(int argc, char *argv[]): valid_(0) switch (c) { case 'o': - req = get_opt.optarg; - if (req.valid() == 0) - cout << "ERROR: oid value: " <<get_opt.optarg \ + req = get_opt.opt_arg(); + if (req.valid() == 0) + cout << "ERROR: oid value: " <<get_opt.opt_arg() \ << "is not valid. using default.\n"; break; case 'c': - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_read_community(community_); break; case 'r': - target_.set_retry(ACE_OS::atoi (get_opt.optarg)); + target_.set_retry(ACE_OS::atoi (get_opt.opt_arg())); break; case 't': - target_.set_timeout(ACE_OS::atoi (get_opt.optarg)); + target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg())); break; default: @@ -121,9 +121,9 @@ nextapp::nextapp(int argc, char *argv[]): valid_(0) } Vb vb; // construct a Vb object - if (req.valid()) + if (req.valid()) vb.set_oid( req); // set the Oid portion of the Vb - else { + else { vb.set_oid( def_oid); // set the Oid portion of the Vb } pdu_ += vb; @@ -143,11 +143,11 @@ void nextapp::usage() int nextapp::run() -{ +{ //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -165,7 +165,7 @@ int nextapp::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; @@ -174,8 +174,8 @@ int nextapp::run() 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; + cout << "ERROR: agent replied as follows\n"; + cout << pdu_.agent_error_reason() << endl; } else { VbIter iter(pdu_); @@ -191,5 +191,5 @@ int nextapp::run() } cout << "ASNMP:INFO:command completed normally. ACE Rocks...\n"<< endl; return 0; -} +} diff --git a/ASNMP/examples/set/set.cpp b/ASNMP/examples/set/set.cpp index b08042fd4a6..cb3cb4f451d 100644 --- a/ASNMP/examples/set/set.cpp +++ b/ASNMP/examples/set/set.cpp @@ -9,7 +9,7 @@ // set.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::set API +// Sample application demonstrating synchronous Snmp::set API // to update an oid in an SNMP Version 1 agent. // // = AUTHOR @@ -20,7 +20,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -51,7 +51,7 @@ class set { int run(); // issue transaction static void usage(); // operator help message - private: + private: set(const set&); UdpAddress address_; @@ -64,8 +64,8 @@ class set { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { set get(argc, argv); if (get.valid()) @@ -76,18 +76,18 @@ int main( int argc, char *argv[]) } int -set::valid() const -{ - return valid_; +set::valid() const +{ + return valid_; } set::set(int argc, char *argv[]): valid_(0) { Vb vb; // construct a Vb object Oid req; - if ( argc < 2) - return; - target_.get_write_community(community_); + if ( argc < 2) + return; + target_.get_write_community(community_); address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -100,28 +100,28 @@ set::set(int argc, char *argv[]): valid_(0) switch (c) { case 'o': - req = get_opt.optarg; - if (req.valid() == 0) - cout << "ERROR: oid value: " <<get_opt.optarg \ + req = get_opt.opt_arg(); + if (req.valid() == 0) + cout << "ERROR: oid value: " <<get_opt.opt_arg() \ << "is not valid. using default.\n"; break; case 'c': - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_write_community(community_); break; case 'r': - target_.set_retry(ACE_OS::atoi (get_opt.optarg)); + target_.set_retry(ACE_OS::atoi (get_opt.opt_arg())); break; case 't': - target_.set_timeout(ACE_OS::atoi (get_opt.optarg)); + target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg())); break; case 'I': // Integer32 { - SnmpInt32 o(ACE_OS::atoi(get_opt.optarg)); + SnmpInt32 o(ACE_OS::atoi(get_opt.opt_arg())); vb.set_value(o); pdu_ += vb; } @@ -129,7 +129,7 @@ set::set(int argc, char *argv[]): valid_(0) case 'U': // Unsigned32 { - SnmpUInt32 o(ACE_OS::atoi(get_opt.optarg)); + SnmpUInt32 o(ACE_OS::atoi(get_opt.opt_arg())); vb.set_value(o); pdu_ += vb; } @@ -137,7 +137,7 @@ set::set(int argc, char *argv[]): valid_(0) case 'C': // Counter32 { - Counter32 o(ACE_OS::atoi(get_opt.optarg)); + Counter32 o(ACE_OS::atoi(get_opt.opt_arg())); vb.set_value(o); pdu_ += vb; } @@ -145,7 +145,7 @@ set::set(int argc, char *argv[]): valid_(0) case 'G': // Gauge32 { - Gauge32 o(ACE_OS::atoi(get_opt.optarg)); + Gauge32 o(ACE_OS::atoi(get_opt.opt_arg())); vb.set_value(o); pdu_ += vb; } @@ -153,22 +153,22 @@ set::set(int argc, char *argv[]): valid_(0) case 'T': // TimeTicks { - TimeTicks o(ACE_OS::atoi(get_opt.optarg)); + TimeTicks o(ACE_OS::atoi(get_opt.opt_arg())); vb.set_value(o); pdu_ += vb; } break; - case 'O': // Oid as a variable identifier + case 'O': // Oid as a variable identifier { - oid_ = get_opt.optarg; + oid_ = get_opt.opt_arg(); vb.set_oid(oid_); // when value is set, pdu updated } break; case 'S': // Octet String { - OctetStr o(get_opt.optarg); + OctetStr o(get_opt.opt_arg()); vb.set_value(o); // set the Oid portion of the Vb pdu_ += vb; } @@ -176,7 +176,7 @@ set::set(int argc, char *argv[]): valid_(0) case 'P': // Oid String as a value { - Oid o(get_opt.optarg); + Oid o(get_opt.opt_arg()); vb.set_value(o); // set the Oid portion of the Vb pdu_ += vb; } @@ -186,7 +186,7 @@ set::set(int argc, char *argv[]): valid_(0) break; } - // if user didn't set anything use defaults + // if user didn't set anything use defaults if (pdu_.get_vb_count() == 0) { Oid def_oid("1.3.6.1.2.1.1.4.0"); // defualt is sysName OctetStr def_value("sysName.0 updated by ASNMP set command"); @@ -194,7 +194,7 @@ set::set(int argc, char *argv[]): valid_(0) vb.set_value(def_value); pdu_ += vb; cout << "INFO: using defaults, setting sysName to : " << \ - def_value.to_string() << endl; + def_value.to_string() << endl; } valid_ = 1; @@ -207,18 +207,18 @@ void set::usage() cout << " -o OID starts with oid after 1.3.6.1.2.1.1.1.0 (mibII sysDescr.0) \n"; cout << " -c Community_name, default is 'private' \n"; cout << " -r N retries default is N = 1 retry\n"; - cout << " -t N timeout in seconds default is 1 second\n"; + cout << " -t N timeout in seconds default is 1 second\n"; cout << " -O oid_to_set -{I,U,G,S,P} value\n"; cout << " where I=int32, U=uint32, G=gauge32, S=octet, P=oid" << endl; } int set::run() -{ +{ //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -236,7 +236,7 @@ int set::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; @@ -245,8 +245,8 @@ int set::run() 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; + cout << "ERROR: agent replied as follows\n"; + cout << pdu_.agent_error_reason() << endl; } else { VbIter iter(pdu_); @@ -262,5 +262,5 @@ int set::run() } cout << "ASNMP:INFO:command completed normally.\n"<< endl; return 0; -} +} diff --git a/ASNMP/examples/trap/trap.cpp b/ASNMP/examples/trap/trap.cpp index c0dfbd93991..cb1ad66a1e4 100644 --- a/ASNMP/examples/trap/trap.cpp +++ b/ASNMP/examples/trap/trap.cpp @@ -9,7 +9,7 @@ // trap.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::trap API +// Sample application demonstrating synchronous Snmp::trap API // to send to an SNMP Version 1 trap listener app. // // = AUTHOR @@ -20,7 +20,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -53,7 +53,7 @@ class trapapp { int run(); // issue transaction static void usage(); // operator help message - private: + private: trapapp(const trapapp&); UdpAddress address_; @@ -66,8 +66,8 @@ class trapapp { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { trapapp get(argc, argv); if (get.valid()) @@ -77,18 +77,18 @@ int main( int argc, char *argv[]) return 1; } -int trapapp::valid() const -{ - return valid_; +int trapapp::valid() const +{ + return valid_; } trapapp::trapapp(int argc, char *argv[]): valid_(0) { - Oid def_ent_oid("1.3.6.1.2.1.1.1.2.0.1"); // def enterprise oid + Oid def_ent_oid("1.3.6.1.2.1.1.1.2.0.1"); // def enterprise oid Oid ent, trap; // user specified values if ( argc < 2) // hostname mandatory - return; - + return; + address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -101,16 +101,16 @@ trapapp::trapapp(int argc, char *argv[]): valid_(0) switch (c) { case 'c': // community string - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_read_community(community_); break; case 'e': // trap oid to send - ent = get_opt.optarg; + ent = get_opt.opt_arg(); break; case 't': // trap oid - trap = get_opt.optarg; + trap = get_opt.opt_arg(); break;; default: @@ -148,9 +148,9 @@ void trapapp::usage() } int trapapp::run() -{ +{ if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -167,7 +167,7 @@ int trapapp::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Community=" << community_.to_string() << " ]"<< endl; if (snmp_.trap( pdu_, target_) == SNMP_CLASS_SUCCESS) { @@ -180,5 +180,5 @@ int trapapp::run() cout << "ASNMP:INFO:command completed normally.\n"<< endl; return 0; -} +} diff --git a/ASNMP/examples/walk/walk.cpp b/ASNMP/examples/walk/walk.cpp index aab784e026f..0147b8fce0e 100644 --- a/ASNMP/examples/walk/walk.cpp +++ b/ASNMP/examples/walk/walk.cpp @@ -9,7 +9,7 @@ // walk.cpp // // = DESCRIPTION -// Sample application demonstrating synchronous Snmp::get, get_next API +// Sample application demonstrating synchronous Snmp::get, get_next API // to access an SNMP Version 1 agent. // // = AUTHOR @@ -20,7 +20,7 @@ /*=================================================================== Copyright (c) 1996 Hewlett-Packard Company - + ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees @@ -50,7 +50,7 @@ class walkapp { int run(); // issue transaction static void usage(); // operator help message - private: + private: walkapp(const walkapp&); UdpAddress address_; @@ -63,8 +63,8 @@ class walkapp { }; -// main entry point -int main( int argc, char *argv[]) +// main entry point +int main( int argc, char *argv[]) { walkapp get(argc, argv); if (get.valid()) @@ -74,17 +74,17 @@ int main( int argc, char *argv[]) return 1; } -int walkapp::valid() const -{ - return valid_; +int walkapp::valid() const +{ + return valid_; } walkapp::walkapp(int argc, char *argv[]): valid_(0) { - Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default begin walk with MIBII - if ( argc < 2) - return; - + Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default begin walk with MIBII + if ( argc < 2) + return; + address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ @@ -97,23 +97,23 @@ walkapp::walkapp(int argc, char *argv[]): valid_(0) switch (c) { case 'o': - req = get_opt.optarg; - if (req.valid() == 0) - cout << "ERROR: oid value: " <<get_opt.optarg \ + req = get_opt.opt_arg(); + if (req.valid() == 0) + cout << "ERROR: oid value: " <<get_opt.opt_arg() \ << "is not valid. using default.\n"; break; case 'c': - community_ = get_opt.optarg; + community_ = get_opt.opt_arg(); target_.set_read_community(community_); break; case 'r': - target_.set_retry(ACE_OS::atoi (get_opt.optarg)); + target_.set_retry(ACE_OS::atoi (get_opt.opt_arg())); break; case 't': - target_.set_timeout(ACE_OS::atoi (get_opt.optarg)); + target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg())); break; default: @@ -121,9 +121,9 @@ walkapp::walkapp(int argc, char *argv[]): valid_(0) } Vb vb; // construct a Vb object - if (req.valid()) + if (req.valid()) vb.set_oid( req); // set the Oid portion of the Vb - else { + else { vb.set_oid( def_oid); // set the Oid portion of the Vb } pdu_ += vb; @@ -143,7 +143,7 @@ void walkapp::usage() // -// simple mib iterator class +// simple mib iterator class // class MibIter { public: @@ -160,14 +160,14 @@ class MibIter { int valid_; // flag to obtain first entry }; -MibIter::MibIter(Snmp* snmp, Pdu& pdu, UdpTarget *target): - snmp_(snmp), target_(target), pdu_(pdu), first_(0), +MibIter::MibIter(Snmp* snmp, Pdu& pdu, UdpTarget *target): + snmp_(snmp), target_(target), pdu_(pdu), first_(0), valid_(0) { // verify we have a valid oid to begin iterating with Oid oid; Vb vb; - pdu.get_vb(vb, 0); + pdu.get_vb(vb, 0); vb.get_oid(oid); if (oid.valid()) valid_ = 1; @@ -187,7 +187,7 @@ int MibIter::next(Vb& vb, char *& reason) first_++; } else { - rc = snmp_->get_next( pdu_, *target_); + rc = snmp_->get_next( pdu_, *target_); } if (rc != SNMP_CLASS_SUCCESS) { @@ -201,9 +201,9 @@ int MibIter::next(Vb& vb, char *& reason) return 0; } - // 3. return vb to caller + // 3. return vb to caller pdu_.get_vb(vb, 0); - Oid nextoid; + Oid nextoid; vb.get_oid(nextoid); // and setup next oid to get Vb nextvb(nextoid); pdu_.delete_all_vbs(); @@ -213,11 +213,11 @@ int MibIter::next(Vb& vb, char *& reason) } int walkapp::run() -{ +{ //----------[ create a ASNMP session ]----------------------------------- if ( snmp_.valid() != SNMP_CLASS_SUCCESS) { - cout << "\nASNMP:ERROR:Create session failed: "<< + cout << "\nASNMP:ERROR:Create session failed: "<< snmp_.error_string()<< "\n"; return 1; } @@ -235,7 +235,7 @@ int walkapp::run() const char *name = address_.resolve_hostname(rc); cout << "Device: " << address_ << " "; - cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; + cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n"; cout << "[ Retries=" << target_.get_retry() << " \ Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \ community_.to_string() << " ]"<< endl; @@ -253,9 +253,9 @@ int walkapp::run() if (!err_str) { cout << "ERROR: walk: " << err_str << endl; return 0; - } + } cout << "ASNMP:INFO:command completed normally. ACE Rocks...\n"<< endl; return 0; -} +} |