NetBurner 3.5.8
PDF Version
Toggle main menu visibility
asn1.h
1
/*NB_REVISION*/
2
3
/*NB_COPYRIGHT*/
4
5
#ifndef _ASN1_H_
6
#define _ASN1_H_
7
8
#define ASNERR_TOO_int32_t -5
/* data too long for provided buffer */
9
10
#define ASNERR_ASN_ENCODE -6
11
#define ASNERR_ASN_DECODE -7
12
#define ASNERR_PDU_TRANSLATION -8
13
#define ASNERR_OS_ERR -9
14
#define ASNERR_INVALID_TXTOID -10
15
16
#define ASNERR_UNABLE_TO_FIX -11
17
#define ASNERR_UNSUPPORTED_TYPE -12
18
#define ASNERR_PDU_PARSE -13
19
#define ASNERR_PACKET_ERR -14
20
#define ASNERR_WRONG_TYPE -15
21
#define ASNERR_ENDOFPACKET -16
22
23
24
25
class
UDPPacket
;
/* Forward declaration */
26
27
class
ASN
28
{
29
UDPPacket *m_pPkt;
30
uint8_t *protected_bufp;
31
uint16_t protected_len;
32
BOOL bOverSize;
33
34
35
// uint8_t *bufp;
36
// uint16_t len;
37
38
39
uint16_t put_header_offset;
40
41
42
int
parse_length();
43
44
void
StoreByte(uint8_t b)
45
{
46
*protected_bufp++=b;
47
protected_len++;
48
if
(protected_len>=(
MAX_UDPDATA
-20))
49
{
50
protected_len--;
51
protected_bufp--;
52
bOverSize=TRUE;
53
}
54
};
55
56
void
StoreWord(uint16_t w) {StoreByte(w>>8); StoreByte(w&0xff);};
57
58
/* Return 1 if there is an eeror */
59
public
:
60
int
RootParse(
int
&length, uint8_t &rv_type );
61
62
63
64
int
error;
65
66
67
ASN( UDPPacket &up );
68
ASN();
69
~ASN();
70
void
AttachPacket( UDPPacket &up );
71
UDPPacket *DetachPacket();
72
void
ResetPacket();
73
74
75
uint8_t GetHeader();
/* Parst ASN header */
76
uint8_t GetHeaderwLen(
int
&objlen );
/* Parse ASN header */
77
int
GetInt();
/* Type of int */
78
uint32_t GetUInt();
/* Unsigned int */
79
int
GetOctets( uint8_t *pData,
int
len );
80
int
GetOid(
int
*dest );
81
int
GetNullObject();
82
IPADDR
GetIPAddr();
83
uint32_t GetGauge32();
84
uint32_t GetCounter32();
85
uint32_t GetTimeTick();
86
long
long
GetCounter64();
87
int
GetOpaque( uint8_t *pData,
int
&len );
88
void
EatBytes(
int
len );
89
90
int
PeekType( uint8_t &type );
91
92
93
void
PutHeader( uint8_t typ );
/* Put ASN header */
94
void
FixUpHeader();
/*When putting together a structure one has to fix up the header length*/
95
/*Always called in a depth first order.
96
They can be at the same level, but not nested out of order
97
/-PutHeader (a)
98
| /-PutHeader (b)
99
| | /-PutHeader (c)
100
| | \-FixUpHeader(c)
101
| \-FixUpHeader(b)
102
| /-PutHeader (d)
103
| \-FixUpHeader(d)
104
\-FixUpHeader (a)
105
*/
106
107
void
PutInt(
int
);
/* Type of int */
108
void
PutUInt( uint32_t );
/* Unsigned int */
109
void
PutOctets(
const
uint8_t *pData,
int
len );
110
void
PutOctetString(
const
char
* );
111
void
PutOid(
int
*oid );
112
void
PutOidFromString(
const
char
* );
113
void
PutOidFromCoid(
const
char
* );
114
void
PutNullObject();
115
void
PutIPAddr(
IPADDR
);
116
void
PutGauge32( uint32_t val );
117
void
PutCounter32( uint32_t val );
118
void
PutTimeTick( uint32_t val );
119
void
PutCounter64(
long
long
val );
120
void
PutOpaque( uint8_t *pData,
int
len );
121
void
Put_NOSUCHINSTANCE();
122
void
Put_NOSUCHOBJECT();
123
void
Put_ENDOFMIBVIEW();
124
void
PutV1_NOSUCHOBJECT();
125
void
PutRawUnsigned( uint8_t type, uint32_t val );
126
127
void
PutCopyBlock(ASN & from);
128
129
130
int
PeekLen();
131
puint8_t GetpData()
132
{
133
return
protected_bufp;
134
}
135
void
FixSize();
136
//Debugging fiunction.
137
void
ShowRemainder();
138
bool
OverSize() {
return
bOverSize; };
139
140
};
141
142
void
PrintOid(
const
int
*oid );
143
#ifdef FILE
144
void
fPrintOid( FILE *fp,
const
int
*oidmlen );
145
#endif
146
147
148
int
CompOid(
const
int
*pOid,
const
int
*pOid2 );
149
150
int
CompOid(
const
int
*pOid,
const
char
*s );
151
152
153
#define MAX_SUBID 0xFFFFFFFF
154
155
156
#define MAX_OID_LEN 128
/* max subid's in an oid, per SNMP spec. */
157
158
#define ASN_BOOLEAN (0x01)
159
#define ASN_INTEGER (0x02)
160
#define ASN_BIT_STR (0x03)
161
#define ASN_OCTET_STR (0x04)
162
#define ASN_NULL (0x05)
163
#define ASN_OBJECT_ID (0x06)
164
#define ASN_SEQUENCE (0x10)
165
#define ASN_SET (0x11)
166
167
#define ASN_UNIVERSAL (0x00)
168
#define ASN_APPLICATION (0x40)
169
#define ASN_CONTEXT (0x80)
170
#define ASN_PRIVATE (0xC0)
171
172
#define ASN_PRIMITIVE (0x00)
173
#define ASN_CONSTRUCTOR (0x20)
174
175
#define ASN_int32_t_LEN (0x80)
176
#define ASN_EXTENSION_ID (0x1F)
177
#define ASN_BIT8 (0x80)
178
179
#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
180
#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
181
182
183
184
185
#define SMI_INTEGER ASN_INTEGER
186
#define SMI_STRING ASN_OCTET_STR
187
#define SMI_OBJID ASN_OBJECT_ID
188
#define SMI_NULLOBJ ASN_NULL
189
#define SMI_IPADDRESS (ASN_APPLICATION | 0)
/* OCTET STRING, net byte order */
190
#define SMI_COUNTER32 (ASN_APPLICATION | 1)
/* INTEGER */
191
#define SMI_GAUGE32 (ASN_APPLICATION | 2)
/* INTEGER */
192
#define SMI_UNSIGNED32 SMI_GAUGE32
193
#define SMI_TIMETICKS (ASN_APPLICATION | 3)
/* INTEGER */
194
#define SMI_OPAQUE (ASN_APPLICATION | 4)
/* OCTET STRING */
195
#define SMI_COUNTER64 (ASN_APPLICATION | 6)
/* INTEGER */
196
197
#define SMI_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
198
#define SMI_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
199
#define SMI_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
200
201
202
#define SNMP_PDU_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
203
#define SNMP_PDU_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
204
#define SNMP_PDU_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
205
#define SNMP_PDU_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
206
#define SNMP_PDU_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
207
#define TRP_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
/*Obsolete*/
208
#define SNMP_PDU_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
209
#define SNMP_PDU_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
210
#define SNMP_PDU_V2TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
211
#define SNMP_PDU_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
212
#define SNMP_VERSION_1 0
/* RFC 1157 */
213
#define SNMP_VERSION_2 1
/* RFC 1901 */
214
215
216
#define SNMP_ERR_NOERROR (0x0)
217
#define SNMP_ERR_TOOBIG (0x1)
218
#define SNMP_ERR_NOSUCHNAME (0x2)
219
#define SNMP_ERR_BADVALUE (0x3)
220
#define SNMP_ERR_READONLY (0x4)
221
#define SNMP_ERR_GENERR (0x5)
222
223
#define SNMP_COLDSTART_TRAP (0x0)
224
#define SNMP_WARMSTART_TRAP (0x1)
225
#define SNMP_LINKDOWN_TRAP (0x2)
226
#define SNMP_LINKUP_TRAP (0x3)
227
#define SNMP_AUTHENTICATIONFAIL_TRAP (0x4)
228
#define SNMP_ENTERPRISE_TRAP (0x6)
229
230
231
232
233
234
#endif
/* _ASN1_H_ */
235
236
UDPPacket
UDP Packet Class - Complete UDP packet management.
Definition
udp.h:602
MAX_UDPDATA
#define MAX_UDPDATA
Definition
constants.h:82
IPADDR
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6).
Definition
nettypes.h:568
nbrtos
include
snmp
asn1.h
Generated by
1.18.0