00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #ifndef _SNMP_PP_EXT_H_
00092 #define _SNMP_PP_EXT_H_
00093
00094 #include <agent_pp/agent++.h>
00095 #include <snmp_pp/oid.h>
00096 #include <snmp_pp/pdu.h>
00097 #include <snmp_pp/vb.h>
00098 #include <snmp_pp/octet.h>
00099 #include <snmp_pp/oid.h>
00100 #include <snmp_pp/snmpmsg.h>
00101
00102
00103 #define LENGTH_OF_IPADDRESS 4
00104
00105 #ifndef WIN32
00106 #include <sys/types.h>
00107 #include <sys/time.h>
00108 #include <unistd.h>
00109 #endif
00110
00111 #ifdef SNMP_PP_NAMESPACE
00112 #define NS_SNMP Snmp_pp::
00113 #else
00114 #define NS_SNMP
00115 #endif
00116
00117 #ifdef AGENTPP_NAMESPACE
00118 namespace Agentpp {
00119 #endif
00120
00121
00122
00123
00133 class AGENTPP_DECL Oidx: public NS_SNMP Oid {
00134 public:
00138 Oidx() : Oid() { };
00139
00145 Oidx(const char* s) : Oid(s) { };
00146
00153 Oidx(const unsigned long *data, int length) : Oid(data, length) { };
00154
00160 Oidx(const Oid& oid) : Oid(oid) { };
00161
00165 virtual ~Oidx() { };
00166
00174 Oidx cut_left(const unsigned int) const;
00175
00183 Oidx cut_right(const unsigned int) const;
00184
00185
00199 Oidx& mask(const NS_SNMP OctetStr&);
00200
00201
00210 static Oidx cut_left(const Oidx&, const unsigned int);
00211
00220 static Oidx cut_right(const Oidx&, const unsigned int);
00221
00227 unsigned long last() const;
00228
00229 virtual Oidx& operator=(unsigned long l);
00230
00231 Oidx &operator+=(NS_SNMP IpAddress&);
00232 Oidx &operator+=(const char *);
00233 Oidx &operator+=(const unsigned long i);
00234 Oidx &operator+=(const Oid &);
00235
00243 int in_subtree_of(const Oidx& o) const;
00244
00252 int is_root_of(const Oidx& o) const;
00253
00268 int compare(const Oidx&, const NS_SNMP OctetStr&) const;
00269
00282 int compare(const Oidx&, u_int) const;
00283
00291 NS_SNMP OctetStr as_string() const;
00292
00303 static Oidx from_string(const NS_SNMP OctetStr&, boolean withLength=TRUE);
00304
00311 Oidx successor() const;
00312
00319 Oidx predecessor() const;
00320
00330 Oidx next_peer() const;
00331 };
00332
00333
00334
00335
00347 class AGENTPP_DECL Vbx: public NS_SNMP Vb {
00348 public:
00349 Vbx(): Vb() { }
00350 Vbx(const NS_SNMP Vb& vb): Vb(vb) { }
00351 Vbx(const NS_SNMP Oid& oid): Vb(oid) { }
00352
00361 Vbx(const NS_SNMP Oid& oid, const NS_SNMP SnmpSyntax &val): Vb(oid) {
00362 set_value(val);
00363 }
00364
00371 Oidx get_oid() const { return iv_vb_oid; };
00372
00373 void get_oid(Oidx& oid) const { oid = iv_vb_oid; };
00374
00379 void clear();
00380
00381 Vbx* clone() const { return new Vbx(*this); }
00382
00383 friend int operator==(const Vbx&, const Vbx&);
00384
00398 static boolean equal(Vbx*, Vbx*, int);
00399
00418 static int to_asn1(Vbx*, int, unsigned char*&, int&);
00419
00438 static int from_asn1(Vbx*&, int&, unsigned char*&, int&);
00439
00440 private:
00441 static unsigned char* asn_build_long_len_sequence(unsigned char *,
00442 int*,
00443 unsigned char,
00444 int, int);
00445 static unsigned char* asn_build_long_length(unsigned char*,
00446 int*,
00447 int,
00448 int);
00449 };
00450
00451
00452
00453
00462 class AGENTPP_DECL OidxRange {
00463
00464 public:
00468 OidxRange();
00469
00479 OidxRange(const Oidx&, const Oidx&);
00480
00484 OidxRange(const OidxRange&);
00485
00489 virtual ~OidxRange();
00490
00497 virtual OidxRange* clone() const;
00498
00507 virtual int operator==(const OidxRange&) const;
00517 virtual int operator<(const OidxRange&) const;
00527 virtual int operator>(const OidxRange&) const;
00528
00538 virtual int includes(const Oidx&) const;
00539
00549 virtual int includes_excl(const Oidx&) const;
00550
00561 virtual boolean covers(const OidxRange&) const;
00562
00571 virtual boolean overlaps(const OidxRange&) const;
00572
00579 virtual Oidx get_lower() const;
00580
00587 virtual Oidx get_upper() const;
00588
00589 Oidx lower, upper;
00590 };
00591
00592
00593
00594
00606 class AGENTPP_DECL Pdux: public NS_SNMP Pdu {
00607 public:
00608 Pdux(): Pdu() { }
00609 Pdux(NS_SNMP Vb* pvbs, const int pvb_count): Pdu(pvbs, pvb_count) { }
00610 Pdux(const Pdu& pdu): Pdu(pdu) { }
00611 Pdux(const Pdux& pdu): Pdu(pdu) { }
00612
00613 virtual ~Pdux() { }
00614
00618 void clear();
00619
00620
00621 Pdux& operator+=(const NS_SNMP Vb&);
00622
00629 virtual Pdux* clone() const { return new Pdux(*this); }
00630 };
00631
00632
00633
00634
00646 class AGENTPP_DECL Snmpx: public NS_SNMP Snmp {
00647 public:
00657 Snmpx (int &status , u_short port): Snmp(status, port) {};
00658
00659 #ifdef SNMP_PP_WITH_UDPADDR
00660
00670 Snmpx(int& status, const NS_SNMP UdpAddress& addr): Snmp(status, addr) { }
00671 #endif
00672
00673 #ifdef _SNMPv3
00674
00691 int receive(struct timeval*, Pdux&, NS_SNMP UTarget&);
00692 #else
00693
00711 int receive(struct timeval*, Pdux&, NS_SNMP UdpAddress&,
00712 NS_SNMP snmp_version&, NS_SNMP OctetStr&);
00713 #endif
00714 #ifdef _SNMPv3
00715
00731 int send (Pdux, NS_SNMP SnmpTarget*);
00732 #else
00733
00748 int send (Pdux, NS_SNMP UdpAddress, NS_SNMP snmp_version, NS_SNMP OctetStr);
00749 #endif
00750
00756 u_short get_port();
00757
00768 SnmpSocket get_session_fds() { return iv_snmp_session; }
00769
00770
00771 protected:
00772 unsigned long ProcessizedReqId(unsigned short);
00773 unsigned long MyMakeReqId();
00774
00775 int snmp_engine( NS_SNMP Pdu &,
00776 long int,
00777 long int,
00778 NS_SNMP SnmpTarget&,
00779 const NS_SNMP snmp_callback cb,
00780 const void * cbd);
00781 };
00782
00783 #ifdef AGENTPP_NAMESPACE
00784 }
00785 #endif
00786
00787 #endif
00788
00789
00790
00791
00792
00793
00794