21 #ifndef _SNMP_PP_EXT_H_
22 #define _SNMP_PP_EXT_H_
27 #include <snmp_pp/smi.h>
28 #include <snmp_pp/pdu.h>
29 #include <snmp_pp/vb.h>
30 #include <snmp_pp/octet.h>
31 #include <snmp_pp/oid.h>
32 #include <snmp_pp/snmpmsg.h>
35 #include <sys/types.h>
40 #ifdef SNMP_PP_NAMESPACE
41 #define NS_SNMP Snmp_pp::
46 #ifdef AGENTPP_NAMESPACE
74 Oidx(
const char* s) : Oid(s) { }
82 Oidx(
const unsigned long *data,
int length) : Oid(data, length) { }
89 Oidx(
const Oid& oid) : Oid(oid) { }
103 Oidx cut_left(
const unsigned int index)
const
105 return cut_left(*
this, index);
115 Oidx cut_right(
const unsigned int index)
const
117 return cut_right(*
this, index);
136 for (
unsigned int i=0; (i<len()) && (i<mask.len()*8); i++) {
137 char m = 0x80 >> (i%8);
138 if (!(mask[i/8] & m)) {
154 static Oidx cut_left(
const Oidx &oid,
const unsigned int index)
157 Oidx retval( oid.smival.value.oid.ptr + index, oid.smival.value.oid.len - index );
160 for (i=index; i<oid.smival.value.oid.len; i++)
161 retval += oid.smival.value.oid.ptr[i];
177 static Oidx cut_right(
const Oidx &oid,
const unsigned int index)
180 unsigned int l = oid.smival.value.oid.len >= index ? oid.smival.value.oid.len - index : 0;
181 Oidx retval( oid.smival.value.oid.ptr, l );
185 unsigned int s = index;
188 for (i=0; i<oid.len()-s; i++)
189 retval += oid.smival.value.oid.ptr[i];
202 unsigned long last()
const
205 if ((!Oid::valid()) || (smival.value.oid.len<1))
208 return smival.value.oid.ptr[smival.value.oid.len-1];
211 using NS_SNMP Oid::operator = ;
212 virtual Oidx& operator = (
unsigned long l)
215 if ( smival.value.oid.ptr ) {
216 delete [] smival.value.oid.ptr;
217 smival.value.oid.ptr =
NULL;
219 smival.value.oid.len = 1;
220 smival.value.oid.ptr = (SmiLPUINT32)
new unsigned long[1];
221 smival.value.oid.ptr[0] = l;
225 using NS_SNMP Oid::operator += ;
228 for (
int i = 0; i < ip.get_length(); i++)
229 *
this += (
unsigned long)ip[i];
233 Oidx &operator+=(
const char *);
234 Oidx &operator+=(
const unsigned long i);
235 Oidx &operator+=(
const Oid &);
245 bool in_subtree_of(
const Oidx& o)
const
247 if (len() <= o.len())
return FALSE;
248 for (
unsigned int i=0; i<o.len(); i++)
249 if ((*
this)[i] != o[i])
return FALSE;
260 bool is_root_of(
const Oidx& o)
const
262 if (len() >= o.len())
return false;
263 for (
unsigned int i=0; i<len(); i++)
264 if ((*
this)[i] != o[i])
return false;
282 int compare(
const Oidx&,
const NS_SNMP OctetStr&)
const;
296 int compare(
const Oidx&, u_int)
const;
308 NS_SNMP OctetStr as_string(
bool withoutLength =
false)
const
314 if (withoutLength && len() > 0 && len() == ((*
this)[0] + 1))
316 for (; i<(int)len(); i++) {
317 str += (
unsigned char)(*
this)[i];
336 oid += (long)str.len();
337 for (
unsigned int i=0; i<str.len(); i++)
351 if (o.len()==MAX_OID_LEN) {
352 if (o[MAX_OID_LEN-1] == 0xFFFFFFFFul) {
353 int i = MAX_OID_LEN-2;
354 while ((i>=0) && (o[i] == 0xFFFFFFFFul)) {
358 o.trim(MAX_OID_LEN-1-i);
379 if (o.len()==0)
return o;
380 if (o[o.len()-1] == 0) {
385 for (
int i=o.len(); i<MAX_OID_LEN; i++)
457 friend int operator==(
const Vbx&,
const Vbx&);
472 static bool equal(
Vbx*,
Vbx*,
int);
492 static int to_asn1(
Vbx*,
int,
unsigned char*&,
int&);
513 static int from_asn1(
Vbx*&,
int&,
unsigned char*&,
int&);
516 static unsigned char* asn_build_long_len_sequence(
unsigned char *,
520 static unsigned char* asn_build_long_length(
unsigned char*,
582 virtual bool operator==(
const OidxRange&)
const;
592 virtual bool operator<(
const OidxRange&)
const;
602 virtual bool operator>(
const OidxRange&)
const;
613 virtual bool includes(
const Oidx&)
const;
624 virtual bool includes_excl(
const Oidx&)
const;
636 virtual bool covers(
const OidxRange&)
const;
646 virtual bool overlaps(
const OidxRange&)
const;
654 virtual Oidx get_lower()
const;
662 virtual Oidx get_upper()
const;
684 Pdux(
NS_SNMP Vb* pvbs,
const int pvb_count): Pdu(pvbs, pvb_count) { }
685 Pdux(
const Pdu& pdu): Pdu(pdu) { }
731 Snmpx (
int &status , u_short port): Snmp(status, port) {};
733 #ifdef SNMP_PP_WITH_UDPADDR
744 Snmpx(
int& status,
const NS_SNMP UdpAddress& addr): Snmp(status, addr) { }
765 int receive(
struct timeval*,
Pdux&,
NS_SNMP UTarget&);
785 int receive(
struct timeval*,
Pdux&,
NS_SNMP UdpAddress&,
846 unsigned long ProcessizedReqId(
unsigned short);
847 unsigned long MyMakeReqId();
850 #ifdef AGENTPP_NAMESPACE