// $Id$ // ============================================================================ // // = LIBRARY // asnmp // // = FILENAME // set.cpp // // = DESCRIPTION // Sample application demonstrating synchronous Snmp::set API // to update an oid in an SNMP Version 1 agent. // // = AUTHOR // Peter E. Mellquist original code // Michael R MacFaden mrm@cisco.com rework API/ACE integration // // ============================================================================ /*=================================================================== 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 to display the above copyright notice and this license notice in all copies of the software and any documentation of the software. User agrees to assume all liability for the use of the software; Hewlett-Packard makes no representations about the suitability of this software for any purpose. It is provided "AS-IS without warranty of any kind,either express or implied. User hereby grants a royalty-free license to any and all derivatives based upon this software code base. =====================================================================*/ #include "asnmp/snmp.h" #include "ace/Get_Opt.h" ACE_RCSID(set, set, "$Id$") // // SNMPv1 Set Application // class set { public: set(int argc, char **argv); // process command line args int valid() const; // verify transaction can proceed int run(); // issue transaction static void usage(); // operator help message private: set(const set&); UdpAddress address_; Pdu pdu_; // construct a request Pdu Oid oid_; OctetStr community_; Snmp snmp_; UdpTarget target_; int valid_; }; // main entry point int main( int argc, char *argv[]) { set get(argc, argv); if (get.valid()) return get.run(); else set::usage(); return 1; } 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_); address_ = argv[argc - 1]; if ( !address_.valid()) { cout << "ERROR: Invalid IPv4 address or DNS hostname: " \ << argv[argc] << "\n"; return; } ACE_Get_Opt get_opt (argc, argv, "o:c:r:t:I:U:C:G:T:O:S:P:"); for (int c; (c = get_opt ()) != -1; ) switch (c) { case 'o': req = get_opt.optarg; if (req.valid() == 0) cout << "ERROR: oid value: " <