SNMP++  3.3.4
snmpmsg.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## snmpmsg.h
4  _##
5  _## SNMP++ v3.3
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2013 Jochen Katz, Frank Fock
8  _##
9  _## This software is based on SNMP++2.6 from Hewlett Packard:
10  _##
11  _## Copyright (c) 1996
12  _## Hewlett-Packard Company
13  _##
14  _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
15  _## Permission to use, copy, modify, distribute and/or sell this software
16  _## and/or its documentation is hereby granted without fee. User agrees
17  _## to display the above copyright notice and this license notice in all
18  _## copies of the software and any documentation of the software. User
19  _## agrees to assume all liability for the use of the software;
20  _## Hewlett-Packard and Jochen Katz make no representations about the
21  _## suitability of this software for any purpose. It is provided
22  _## "AS-IS" without warranty of any kind, either express or implied. User
23  _## hereby grants a royalty-free license to any and all derivatives based
24  _## upon this software code base.
25  _##
26  _##########################################################################*/
27 /*===================================================================
28 
29  Copyright (c) 1999
30  Hewlett-Packard Company
31 
32  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
33  Permission to use, copy, modify, distribute and/or sell this software
34  and/or its documentation is hereby granted without fee. User agrees
35  to display the above copyright notice and this license notice in all
36  copies of the software and any documentation of the software. User
37  agrees to assume all liability for the use of the software; Hewlett-Packard
38  makes no representations about the suitability of this software for any
39  purpose. It is provided "AS-IS without warranty of any kind,either express
40  or implied. User hereby grants a royalty-free license to any and all
41  derivatives based upon this software code base.
42 
43 
44  SNMP++ S N M P M E S S A G E . H
45 
46  SNMPMESSAGE CLASS DEFINITION
47 
48  DESIGN + AUTHOR: Peter E Mellquist
49 
50  DESCRIPTION:
51  ASN.1 encoding / decoding class
52 
53 =====================================================================*/
54 // $Id: snmpmsg.h 2359 2013-05-09 20:07:01Z fock $
55 
56 #ifndef _SNMPMSG
57 #define _SNMPMSG
58 
59 #include "snmp_pp/config_snmp_pp.h"
60 
61 #include "snmp_pp/smival.h"
62 #include "snmp_pp/pdu.h"
63 #include "snmp_pp/target.h"
64 #include "snmp_pp/asn1.h"
65 #include "snmp_pp/mp_v3.h"
66 
67 #ifdef SNMP_PP_NAMESPACE
68 namespace Snmp_pp {
69 #endif
70 
72 DLLOPT int convertVbToSmival( const Vb&, SmiVALUE* );
73 
74 #define SNMP_MSG_OID_SYSUPTIME "1.3.6.1.2.1.1.3.0"
75 #define SNMP_MSG_OID_TRAPID "1.3.6.1.6.3.1.1.4.1.0"
76 
77 class Snmp;
78 
79 // SnmpMessage Class
81 {
82  public:
83 
84  // construct a SnmpMessage object
85  SnmpMessage() : bufflen(MAX_SNMP_PACKET), valid_flag(false) {};
86  // load up using a Pdu, community and SNMP version
87  // performs ASN.1 serialization
88  // result status returned
89  private:
90  int load( const Pdu &pdu, // Pdu to serialize
91  const OctetStr &community, // community name to use
92  const snmp_version version, // SNMP version, v1 or v2
93  const OctetStr *engine_id, // optional v3
94  const OctetStr *security_name, // optional v3
95  const int security_model); // optional v3
96  public:
97  int load( const Pdu &pdu, // Pdu to serialize
98  const OctetStr &community, // community name to use
99  const snmp_version version) // SNMP version, v1 or v2
100  { return load(pdu, community, version, 0, 0, 0); };
101 
102  // load up message using ASN.1 data stream
103  // status is returned
104  int load( unsigned char *data, // data to be loaded
105  unsigned long len); // len of data to be loaded
106 
107  // unload ( unserialize ) into SNMP++ Pdu, community and version
108  // status is returned
109  private:
110  int unload( Pdu &pdu, // Pdu returned
111  OctetStr &community, // community name
112  snmp_version &version, // version
113  OctetStr *engine_id, // optional v3
114  OctetStr *security_name, // optional v3
115  long int *security_model,
116  UdpAddress *from_addr,
117  Snmp *snmp_session);
118  public:
119  int unload( Pdu &pdu, // Pdu returned
120  OctetStr &community, // community name
121  snmp_version &version) // version
122  { return unload(pdu, community, version, 0, 0, 0, 0, 0); };
123 
124 
125 #ifdef _SNMPv3
126  int loadv3( const Pdu &pdu, // Pdu to serialize
127  const OctetStr &engine_id, // engine_id to use
128  const OctetStr &sec_name, // securit_name to use
129  const int sec_model, // security_model to use
130  const snmp_version version) // SNMP version, v3
131  { return load(pdu, "", version, &engine_id, &sec_name, sec_model); }
132 
133  int unloadv3( Pdu &pdu, // Pdu returned
134  snmp_version &version, // version
135  OctetStr &engine_id, // optional v3
136  OctetStr &security_name, // optional v3
137  long int &security_model,
138  UdpAddress &from_addr,
139  Snmp &snmp_session);
140 
141  // returns TRUE if the message in the buffer is a v3 message
142  bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
143 
144 #endif
145 
146  // return the validity of the message
147  bool valid() const { return valid_flag;};
148 
149  // return raw data
150  // check validity
151  unsigned char *data() { return databuff; };
152 
153  // returns len
154  // check validity
155  unsigned long len() const { return bufflen; };
156 
157 protected:
158 
159  unsigned char databuff[MAX_SNMP_PACKET];
160  unsigned int bufflen;
162 };
163 
164 #ifdef SNMP_PP_NAMESPACE
165 } // end of namespace Snmp_pp
166 #endif
167 
168 #endif // _SNMPMSG
bool valid() const
Definition: snmpmsg.h:147
#define MAX_SNMP_PACKET
The maximum size of a message that can be sent or received.
DLLOPT int convertVbToSmival(const Vb &, SmiVALUE *)
bool valid_flag
Definition: snmpmsg.h:161
bool is_v3_message()
Definition: snmpmsg.h:142
unsigned long len() const
Definition: snmpmsg.h:155
SnmpMessage()
Definition: snmpmsg.h:85
The Vb class is the encapsulation of the SNMP variable binding.
Definition: vb.h:88
SNMP class defintion.
Definition: uxsnmp.h:99
int unload(Pdu &pdu, OctetStr &community, snmp_version &version)
Definition: snmpmsg.h:119
DLLOPT void freeSmivalDescriptor(SmiVALUE *)
unsigned int bufflen
Definition: snmpmsg.h:160
#define DLLOPT
int loadv3(const Pdu &pdu, const OctetStr &engine_id, const OctetStr &sec_name, const int sec_model, const snmp_version version)
Definition: snmpmsg.h:126
snmp_version
The SNMP version to use is passed with this enum.
Definition: target.h:75
unsigned char * data()
Definition: snmpmsg.h:151
Definition: octet.h:67
int load(const Pdu &pdu, const OctetStr &community, const snmp_version version)
Definition: snmpmsg.h:97
static bool is_v3_msg(unsigned char *buffer, int length)
Tests if the given buffer contains a SNMPv3-Message.
Pdu class...
Definition: pdu.h:81