📄 target.cpp
字号:
/*_############################################################################ _## _## target.cpp _## _## SNMP++v3.2.21a _## ----------------------------------------------- _## Copyright (c) 2001-2006 Jochen Katz, Frank Fock _## _## This software is based on SNMP++2.6 from Hewlett Packard: _## _## 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 and Jochen Katz make 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. _## _## Stuttgart, Germany, Tue Nov 21 22:12:16 CET 2006 _## _##########################################################################*//*=================================================================== Copyright (c) 1999 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. T A R G E T . C P P DESIGN + AUTHOR: Peter E Mellquist LANGUAGE: ANSI C++ OPERATING SYSTEMS: MS-WINDOWS WIN32 BSD UNIX DESCRIPTION: Target class defines target SNMP agents.=====================================================================*/char target_cpp_version[]="#(@) SNMP++ $Id: target.cpp,v 1.6 2004/06/20 18:49:21 katz Exp $";#include "snmp_pp/target.h"#include "snmp_pp/v3.h"#ifdef SNMP_PP_NAMESPACEnamespace Snmp_pp {#endif#define PUBLIC "public"// class variables for default behavior controlunsigned long SnmpTarget::default_timeout = 100;int SnmpTarget::default_retries = 1;//----------------------------------------------------------------------//--------[ Abstract SnmpTarget Member Functions ]----------------------//----------------------------------------------------------------------// get the addressint SnmpTarget::get_address( GenAddress &address) const{ if (validity == false) return FALSE; address = my_address; return TRUE;}// set the addressint SnmpTarget::set_address( const Address &address){ my_address = address; if ( my_address.valid()) validity = true; else validity = false; return validity;}SnmpTarget* SnmpTarget::clone() const{ GenAddress addr = my_address; SnmpTarget* res = new SnmpTarget; res->set_timeout(timeout); res->set_retry(retries); res->set_address(addr); res->set_version(version); return res;}//=============[ int operator == SnmpTarget, SnmpTarget ]======================// equivlence operator overloadedint SnmpTarget::operator==( const SnmpTarget &rhs) const{ if (my_address != rhs.my_address) return 0; if (version != rhs.version) return 0; if (timeout != rhs.timeout) return 0; if (retries != rhs.retries) return 0; return 1; // they are equal}// reset the objectvoid SnmpTarget::clear(){ validity = false; timeout = default_timeout; retries = default_retries; version = version1; ttype = type_base; my_address.clear();}//----------------------------------------------------------------------//--------[ CTarget Member Functions ]----------------------------------//----------------------------------------------------------------------//---------[ CTarget::CTarget( void) ]----------------------------------// CTarget constructor no argsCTarget::CTarget( void) : read_community(PUBLIC), write_community(PUBLIC){ ttype = type_ctarget; // overwrite value set in SnmpTarget()}//-----------[ CTarget:: CTarget ]-------------------------------------// CTarget constructor with argsCTarget::CTarget( const Address &address, const char *read_community_name, const char *write_community_name) : SnmpTarget(address), read_community(read_community_name), write_community(write_community_name){ ttype = type_ctarget; // overwrite value set in SnmpTarget()}//-----------[ CTarget:: CTarget ]-----------------------------------// CTarget constructor with argsCTarget::CTarget( const Address &address, const OctetStr& read_community_name, const OctetStr& write_community_name) : SnmpTarget(address), read_community(read_community_name), write_community(write_community_name){ ttype = type_ctarget; // overwrite value set in SnmpTarget()}//-----------[ CTarget:: CTarget( Address &address) ]--------------// CTarget constructor with argsCTarget::CTarget( const Address &address) : SnmpTarget(address), read_community(PUBLIC), write_community(PUBLIC){ ttype = type_ctarget; // overwrite value set in SnmpTarget()}//-----------[ CTarget:: CTarget( const CTarget &target) ]-------// CTarget constructor with argsCTarget::CTarget( const CTarget &target){ read_community = target.read_community; write_community = target.write_community; my_address = target.my_address; timeout = target.timeout; retries = target.retries; version = target.version; validity = target.validity; ttype = type_ctarget;}//----------[ CTarget::resolve_to_V1 ]---------------------------------// resolve entity// common interface for Community based targetsint CTarget::resolve_to_C ( OctetStr &read_comm, OctetStr &write_comm, GenAddress &address, unsigned long &t, int &r, unsigned char &v) const{ // if the target is invalid then return false if ( !validity) return FALSE; read_comm = read_community; write_comm = write_community; address = my_address; t = timeout; r = retries; v = version; return TRUE;}// overloaded assignmentCTarget& CTarget::operator=( const CTarget& target){ if (this == &target) return *this; // check for self assignment timeout = target.timeout; retries = target.retries; read_community = target.read_community; write_community = target.write_community; validity = target.validity; my_address = target.my_address; version = target.version; return *this;}//=============[ int operator == CTarget, CTarget ]==========================// equivlence operator overloadedint CTarget::operator==( const CTarget &rhs) const{ if (SnmpTarget::operator==(rhs) == 0) return 0; // need to compare all the members of a CTarget if (read_community != rhs.read_community) return 0; if (write_community != rhs.write_community) return 0; return 1; // equal}// reset the objectvoid CTarget::clear(){ SnmpTarget::clear(); read_community.clear(); write_community.clear();}//----------------------------------------------------------------------//--------[ UTarget Member Functions ]----------------------------------//----------------------------------------------------------------------//---------[ UTarget::UTarget( void) ]----------------------------------// UTarget constructor no argsUTarget::UTarget() : security_name(INITIAL_USER),#ifdef _SNMPv3 security_model(SecurityModel_USM), engine_id("")#else security_model(SecurityModel_v1)#endif{#ifdef _SNMPv3 version = version3;#endif ttype = type_utarget;}//-----------[ UTarget:: UTarget ]-------------------------------------// UTarget constructor with argsUTarget::UTarget( const Address &address, const char *sec_name, const int sec_model) : SnmpTarget(address), security_name(sec_name), security_model(sec_model)#ifdef _SNMPv3 ,engine_id("")#endif{#ifdef _SNMPv3 version = version3;#endif ttype = type_utarget;}//-----------[ UTarget:: UTarget ]-----------------------------------// UTarget constructor with argsUTarget::UTarget( const Address &address, const OctetStr &sec_name, const int sec_model) : SnmpTarget(address), security_name(sec_name), security_model(sec_model)#ifdef _SNMPv3 ,engine_id("")#endif{#ifdef _SNMPv3 version = version3;#endif ttype = type_utarget;}//-----------[ UTarget:: UTarget( Address &address) ]--------------// UTarget constructor with argsUTarget::UTarget( const Address &address) : SnmpTarget(address), security_name(INITIAL_USER),#ifdef _SNMPv3 security_model(SecurityModel_USM), engine_id("")#else security_model(SecurityModel_v1)#endif{#ifdef _SNMPv3 version = version3;#endif ttype = type_utarget;}//-----------[ UTarget:: UTarget( const UTarget &target) ]-------// UTarget constructor with argsUTarget::UTarget( const UTarget &target){#ifdef _SNMPv3 engine_id = target.engine_id;#endif security_name = target.security_name; security_model = target.security_model; my_address = target.my_address; timeout = target.timeout; retries = target.retries; version = target.version; validity = target.validity; ttype = type_utarget;}// set the addressint UTarget::set_address(const Address &address){#ifdef _SNMPv3 engine_id = ""; // delete engine_id#endif return SnmpTarget::set_address(address);}int UTarget::resolve_to_U( OctetStr& sec_name, int &sec_model, GenAddress &address, unsigned long &t, int &r, unsigned char &v) const{ // if the target is invalid then return false if ( !validity) return FALSE; sec_name = security_name; sec_model = security_model; address = my_address; t = timeout; r = retries; v = version; return TRUE;}// overloaded assignmentUTarget& UTarget::operator=(const UTarget& target){ if (this == &target) return *this; // check for self assignment timeout = target.timeout; retries = target.retries;#ifdef _SNMPv3 engine_id = target.engine_id;#endif security_name = target.security_name; security_model = target.security_model; version = target.version; validity = target.validity; my_address = target.my_address; return *this;}//=============[ int operator == UTarget, UTarget ]==========================// equivlence operator overloadedint UTarget::operator==( const UTarget &rhs) const{ if (SnmpTarget::operator==(rhs) == 0) return 0; // need to compare all the members of a UTarget // but don`t compare engine_id if (security_name != rhs.security_name) return 0; if (security_model != rhs.security_model) return 0; return 1; // they are equal}// reset the objectvoid UTarget::clear(){ SnmpTarget::clear(); security_name = INITIAL_USER;#ifdef _SNMPv3 security_model = SecurityModel_USM; engine_id.clear(); version = version3;#else security_model = SecurityModel_v1;#endif ttype = type_utarget;}#ifdef SNMP_PP_NAMESPACE}; // end of namespace Snmp_pp#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -