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
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
00439 static int from_asn1(Vbx*&, int&, unsigned char*&, int&);
00440
00441 private:
00442 static unsigned char* asn_build_long_len_sequence(unsigned char *,
00443 int*,
00444 unsigned char,
00445 int, int);
00446 static unsigned char* asn_build_long_length(unsigned char*,
00447 int*,
00448 int,
00449 int);
00450 };
00451
00452
00453
00454
00463 class AGENTPP_DECL OidxRange {
00464
00465 public:
00469 OidxRange();
00470
00480 OidxRange(const Oidx&, const Oidx&);
00481
00485 OidxRange(const OidxRange&);
00486
00490 virtual ~OidxRange();
00491
00498 virtual OidxRange* clone() const;
00499
00508 virtual int operator==(const OidxRange&) const;
00518 virtual int operator<(const OidxRange&) const;
00528 virtual int operator>(const OidxRange&) const;
00529
00539 virtual int includes(const Oidx&) const;
00540
00550 virtual int includes_excl(const Oidx&) const;
00551
00562 virtual boolean covers(const OidxRange&) const;
00563
00572 virtual boolean overlaps(const OidxRange&) const;
00573
00580 virtual Oidx get_lower() const;
00581
00588 virtual Oidx get_upper() const;
00589
00590 Oidx lower, upper;
00591 };
00592
00593
00594
00595
00607 class AGENTPP_DECL Pdux: public NS_SNMP Pdu {
00608 public:
00609 Pdux(): Pdu() { }
00610 Pdux(NS_SNMP Vb* pvbs, const int pvb_count): Pdu(pvbs, pvb_count) { }
00611 Pdux(const Pdu& pdu): Pdu(pdu) { }
00612 Pdux(const Pdux& pdu): Pdu(pdu) { }
00613
00614 virtual ~Pdux() { }
00615
00619 void clear();
00620
00621
00622 Pdux& operator+=(const NS_SNMP Vb&);
00623
00630 virtual Pdux* clone() const { return new Pdux(*this); }
00631 };
00632
00633
00634
00635
00647 class AGENTPP_DECL Snmpx: public NS_SNMP Snmp {
00648 public:
00658 Snmpx (int &status , u_short port): Snmp(status, port) {};
00659
00660 #ifdef SNMP_PP_WITH_UDPADDR
00661
00671 Snmpx(int& status, const NS_SNMP UdpAddress& addr): Snmp(status, addr) { }
00672 #endif
00673
00674 #ifdef _SNMPv3
00675
00692 int receive(struct timeval*, Pdux&, NS_SNMP UTarget&);
00693 #else
00694
00712 int receive(struct timeval*, Pdux&, NS_SNMP UdpAddress&,
00713 NS_SNMP snmp_version&, NS_SNMP OctetStr&);
00714 #endif
00715 #ifdef _SNMPv3
00716
00732 int send (Pdux, NS_SNMP SnmpTarget*);
00733 #else
00734
00749 int send (Pdux, NS_SNMP UdpAddress, NS_SNMP snmp_version, NS_SNMP OctetStr);
00750 #endif
00751
00757 u_short get_port();
00758
00769 SnmpSocket get_session_fds() { return iv_snmp_session; }
00770
00771
00772 protected:
00773 unsigned long ProcessizedReqId(unsigned short);
00774 unsigned long MyMakeReqId();
00775
00776 int snmp_engine( NS_SNMP Pdu &,
00777 long int,
00778 long int,
00779 NS_SNMP SnmpTarget&,
00780 const NS_SNMP snmp_callback cb,
00781 const void * cbd);
00782 };
00783
00784 #ifdef AGENTPP_NAMESPACE
00785 }
00786 #endif
00787
00788 #endif
00789
00790
00791
00792
00793
00794
00795