1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
// $Id$
// ============================================================================
//
// = LIBRARY
// asnmp
//
// = FILENAME
// target.cpp
//
// = DESCRIPTION
// Target class defines target SNMP agents.
//
// = AUTHOR
// Peter E Mellquist
// Michael R MacFaden mrm@cisco.com - rework & ACE port
// ============================================================================
/*===================================================================
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/target.h"
#include "ace/OS_NS_stdio.h"
ACE_RCSID(asnmp, target, "$Id$")
//----------------------------------------------------------------------
//--------[ Class default values ]----------------------
//----------------------------------------------------------------------
u_long SnmpTarget::default_timeout_ = DEF_TIMEOUT;
int SnmpTarget::default_retries_ = DEF_RETRIES;
u_long SnmpTarget::default_max_pdu_size_ = DEF_MAX_SNMP_PACKET;
snmp_version SnmpTarget::default_version_ = version1;
OctetStr UdpTarget::default_rd_community_(READ_COMM_STR);
OctetStr UdpTarget::default_wr_community_(WRITE_COMM_STR);
//----------------------------------------------------------------------
//--------[ Abstract SnmpTarget Member Functions ]----------------------
//----------------------------------------------------------------------
SnmpTarget::SnmpTarget():
validity_(0), timeout_(default_timeout_), retries_(default_retries_),
max_pdu_size_(default_max_pdu_size_), version_(default_version_)
{
}
// return validity of target
int SnmpTarget::valid() const
{
return validity_;
}
// allow destruction of derived classes
SnmpTarget::~SnmpTarget()
{
}
// set the timeout
void SnmpTarget::set_timeout( const u_long t)
{
timeout_ = t;
}
// change the default timeout
void SnmpTarget::set_default_timeout( const u_long t)
{
default_timeout_ = t;
}
// set the retry value
void SnmpTarget::set_retry( const int r)
{
retries_ = r;
}
// change the default retries
void SnmpTarget::set_default_retry( const int r)
{
default_retries_ = r;
}
void SnmpTarget:: set_max_pdu_size(const u_long max_pdu_sz)
{
max_pdu_size_ = max_pdu_sz;
}
void SnmpTarget::set_default_max_pdu_size(const u_long max_pdu_sz)
{
default_max_pdu_size_ = max_pdu_sz;
}
void SnmpTarget::set_version( const snmp_version v)
{
version_ = v;
}
void SnmpTarget::set_default_version( const snmp_version v)
{
default_version_ = v;
}
snmp_version SnmpTarget::get_version() const
{
return version_;
}
snmp_version SnmpTarget::get_default_version() const
{
return default_version_;
}
u_long SnmpTarget::get_max_pdu_size() const
{
return max_pdu_size_;
}
// get the retry value
int SnmpTarget::get_retry() const
{
return retries_;
}
// get the retry value
int SnmpTarget::get_default_retry() const
{
return default_retries_;
}
// get the timeout
u_long SnmpTarget::get_timeout() const
{
return timeout_;
}
SnmpTarget& SnmpTarget::operator=(const SnmpTarget& lhs)
{
if (this == &lhs)
return *this;
validity_ = lhs.validity_;
timeout_ = lhs.timeout_;
retries_ = lhs.retries_;
max_pdu_size_ =lhs.max_pdu_size_;
version_ = lhs.version_;
return *this;
}
bool operator==(const SnmpTarget& lhs, const SnmpTarget& rhs)
{
if (lhs.timeout_ != rhs.timeout_)
return false;
if (lhs.retries_ != rhs.retries_)
return false;
if (lhs.max_pdu_size_ != rhs.max_pdu_size_)
return false;
if (lhs.version_ != rhs.version_)
return false;
return true;
}
//----------------------------------------------------------------------
//--------[ IpTarget Member Functions ]----------------------------------
//----------------------------------------------------------------------
//---------[ UdpTarget::UdpTarget( void) ]----------------------------------
UdpTarget::UdpTarget()
{
validity_ = 0;
read_community_ = default_rd_community_; // assign by init fails
write_community_ = default_wr_community_;
}
UdpTarget::UdpTarget(const UdpAddress& udp) : udp_address_(udp)
{
if (udp_address_.valid())
validity_ = 1;
read_community_ = default_rd_community_;
write_community_ = default_wr_community_;
}
// - copy constructor can be synthesised by compiler
//-----------[ UdpTarget::~UdpTarget() ]--------------------------------
UdpTarget::~UdpTarget()
{
}
//-----------[ UdpTarget::clone() ]--------------------------------
SnmpTarget * UdpTarget::clone() const
{
return (SnmpTarget *) new UdpTarget(*this);
}
void UdpTarget::set_default_read_community(const OctetStr& rd_community)
{
default_rd_community_ = rd_community;
}
void UdpTarget::set_default_write_community(const OctetStr& wr_community)
{
default_wr_community_ = wr_community;
}
// get the read community name as an u_char and len
void UdpTarget::get_read_community( OctetStr& read_community_oct) const
{
read_community_oct = read_community_;
}
//---------[ UdpTarget::set_getcommunity ]---------------------------------
// set the read community name
void UdpTarget::set_read_community( const OctetStr& new_read_community)
{
read_community_ = new_read_community;
}
//---------[ UdpTarget::get_writecommunity ]----------------------------
// get the write community
void UdpTarget::get_write_community( OctetStr &write_community_oct) const
{
write_community_oct = write_community_;
}
//-----------[ UdpTarget::set_writecommunity ]---------------------------
// set the write community
void UdpTarget::set_write_community( const OctetStr& write_community_oct)
{
write_community_ = write_community_oct;
}
//------------[ Address& UdpTarget::get_address() ]---------------------
// get the address
void UdpTarget::get_address( UdpAddress &address) const
{
address = udp_address_;
return;
}
//-------------[ UdpTarget::set_address ]--------------------------------
// set the address
int UdpTarget::set_address( UdpAddress &udp_address)
{
udp_address_ = udp_address;
if ( udp_address_.valid())
validity_ = 1;
else
validity_ = 0;
return validity_;
}
// overloaded assignment
UdpTarget& UdpTarget::operator=( const UdpTarget& lhs)
{
if (this == &lhs)
return *this;
// assign base part
*((SnmpTarget *) this) = *((SnmpTarget *)&lhs);
udp_address_ = lhs.udp_address_;
read_community_ = lhs.read_community_;
write_community_ = lhs.write_community_;
validity_ = lhs.validity_;
return *this;
}
const char *UdpTarget::to_string()
{
ACE_OS::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_, (int) timeout_,
retries_, max_pdu_size_);
return output_buffer_;
}
//=============[ int operator == UdpTarget, UdpTarget ]===============
// equivlence operator overloaded
bool operator==( const UdpTarget &lhs,const UdpTarget &rhs)
{
// need to compare all the members of a UdpTarget
if ( lhs.read_community_ != rhs.read_community_)
return false; // !=
if ( lhs.write_community_ != rhs.write_community_)
return false; // !=
if ( lhs.udp_address_ != rhs.udp_address_)
return false;
if ( lhs.timeout_ != rhs.timeout_)
return false;
if ( lhs.retries_ != rhs.retries_)
return false;
return true; // they are equal
}
|