SNMP++  3.6.3
snmpmsg.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## snmpmsg.h
4  _##
5  _## SNMP++ v3.4
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2021 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, Frank Fock, and Jochen Katz make no representations
21  _## about the 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$
55 
56 #ifndef _SNMP_SNMPMSG_H_
57 #define _SNMP_SNMPMSG_H_
58 
59 #include <libsnmp.h>
60 #include "snmp_pp/config_snmp_pp.h"
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(
91 #ifdef _SNMPv3
92  v3MP* mpv3,
93 #endif
94  Pdu &pdu, // Pdu to serialize
95  const OctetStr &community, // community name to use
96  const snmp_version version, // SNMP version, v1 or v2
97  const OctetStr *engine_id, // optional v3
98  const OctetStr *security_name, // optional v3
99  const int security_model); // optional v3
100  public:
101  int load( Pdu &pdu, // Pdu to serialize
102  const OctetStr &community, // community name to use
103  const snmp_version version) // SNMP version, v1 or v2
104  { return load(
105 #ifdef _SNMPv3
106  0,
107 #endif
108  pdu, community, version, 0, 0, 0); };
109 
110  // load up message using ASN.1 data stream
111  // status is returned
112  int load( unsigned char *data, // data to be loaded
113  unsigned long len); // len of data to be loaded
114 
115  // unload ( unserialize ) into SNMP++ Pdu, community and version
116  // status is returned
117  private:
118  int unload( Pdu &pdu, // Pdu returned
119  OctetStr &community, // community name
120  snmp_version &version, // version
121  OctetStr *engine_id, // optional v3
122  OctetStr *security_name, // optional v3
123  long int *security_model,
124  UdpAddress *from_addr,
125  Snmp *snmp_session);
126  public:
127  int unload( Pdu &pdu, // Pdu returned
128  OctetStr &community, // community name
129  snmp_version &version) // version
130  { return unload(pdu, community, version, 0, 0, 0, 0, 0); };
131 
132 
133 #ifdef _SNMPv3
134  int loadv3( v3MP* mpv3, // v3 message processing model
135  Pdu &pdu, // Pdu to serialize
136  const OctetStr &engine_id, // engine_id to use
137  const OctetStr &sec_name, // securit_name to use
138  const int sec_model, // security_model to use
139  const snmp_version version) // SNMP version, v3
140  { return load(mpv3, pdu, "", version, &engine_id, &sec_name, sec_model); }
141 
142  int unloadv3( Pdu &pdu, // Pdu returned
143  snmp_version &version, // version
144  OctetStr &engine_id, // optional v3
145  OctetStr &security_name, // optional v3
146  long int &security_model,
147  UdpAddress &from_addr,
148  Snmp &snmp_session);
149 
150  // returns TRUE if the message in the buffer is a v3 message
151  bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
152 
153 #endif
154 
155  // return the validity of the message
156  bool valid() const { return valid_flag;};
157 
158  // return raw data
159  // check validity
160  unsigned char *data() { return databuff; };
161 
162  // returns len
163  // check validity
164  unsigned long len() const { return bufflen; };
165 
166 protected:
167 
168  unsigned char databuff[MAX_SNMP_PACKET];
169  unsigned int bufflen;
171 };
172 
173 #ifdef SNMP_PP_NAMESPACE
174 } // end of namespace Snmp_pp
175 #endif
176 
177 #endif // _SNMP_SNMPMSG_H_
#define MAX_SNMP_PACKET
The maximum size of a message that can be sent or received.
#define _SNMPv3
DLLOPT int convertVbToSmival(const Vb &, SmiVALUE *)
bool valid() const
Definition: snmpmsg.h:156
bool valid_flag
Definition: snmpmsg.h:170
bool is_v3_message()
Definition: snmpmsg.h:151
SnmpMessage()
Definition: snmpmsg.h:85
The Vb class is the encapsulation of the SNMP variable binding.
Definition: vb.h:88
SNMP class definition.
Definition: uxsnmp.h:107
int unload(Pdu &pdu, OctetStr &community, snmp_version &version)
Definition: snmpmsg.h:127
DLLOPT void freeSmivalDescriptor(SmiVALUE *)
unsigned int bufflen
Definition: snmpmsg.h:169
#define DLLOPT
int load(Pdu &pdu, const OctetStr &community, const snmp_version version)
Definition: snmpmsg.h:101
The SNMPv3 Message Processing Model (v3MP).
Definition: mp_v3.h:107
snmp_version
The SNMP version to use is passed with this enum.
Definition: target.h:76
unsigned char * data()
Definition: snmpmsg.h:160
Definition: octet.h:67
unsigned long len() const
Definition: snmpmsg.h:164
static bool is_v3_msg(unsigned char *buffer, int length)
Tests if the given buffer contains a SNMPv3-Message.
Pdu class...
Definition: pdu.h:82
int loadv3(v3MP *mpv3, Pdu &pdu, const OctetStr &engine_id, const OctetStr &sec_name, const int sec_model, const snmp_version version)
Definition: snmpmsg.h:134