1 |
/* |
/* |
2 |
Copyright (C) 2001, Sergey Poznyakoff. |
Copyright (C) 2001,2003 Sergey Poznyakoff. |
3 |
|
|
4 |
This file is part of GNU Radius SNMP Library. |
This file is part of GNU Radius SNMP Library. |
5 |
|
|
34 |
Return: pointer to the first byte of the object. |
Return: pointer to the first byte of the object. |
35 |
Error: Returns NULL, does not change args */ |
Error: Returns NULL, does not change args */ |
36 |
u_char * |
u_char * |
37 |
asn_decode_length(data, length) |
asn_decode_length(u_char *data, u_int *length) |
|
u_char *data; |
|
|
u_int *length; |
|
38 |
{ |
{ |
39 |
u_char size = *data++; |
u_char size = *data++; |
40 |
|
|
66 |
Return:Pointer to the byte immediately past the encoded length |
Return:Pointer to the byte immediately past the encoded length |
67 |
Error: NULL */ |
Error: NULL */ |
68 |
u_char * |
u_char * |
69 |
asn_encode_length(data, datalength, length) |
asn_encode_length(u_char *data, int *datalength, u_int length) |
|
u_char *data; |
|
|
int *datalength; |
|
|
u_int length; |
|
70 |
{ |
{ |
71 |
if (*datalength < 1) { |
if (*datalength < 1) { |
72 |
SNMP_SET_ERRNO(E_ASN_ENCODE); |
SNMP_SET_ERRNO(E_ASN_ENCODE); |
98 |
} |
} |
99 |
|
|
100 |
u_char * |
u_char * |
101 |
asn_recode_length(data, length) |
asn_recode_length(u_char *data, u_int length) |
|
u_char *data; |
|
|
u_int length; |
|
102 |
{ |
{ |
103 |
/*length can be at most 0xffff */ |
/*length can be at most 0xffff */ |
104 |
*data++ = (u_char)(ASN_LONG_LEN|0x02); |
*data++ = (u_char)(ASN_LONG_LEN|0x02); |
117 |
data). |
data). |
118 |
Error: NULL */ |
Error: NULL */ |
119 |
u_char * |
u_char * |
120 |
asn_encode_header(data, datalength, type, length) |
asn_encode_header(u_char *data, int *datalength, u_char type, int length) |
|
u_char *data; |
|
|
int *datalength; |
|
|
u_char type; |
|
|
int length; |
|
121 |
{ |
{ |
122 |
if (*datalength < 1) { |
if (*datalength < 1) { |
123 |
SNMP_SET_ERRNO(E_ASN_ENCODE); |
SNMP_SET_ERRNO(E_ASN_ENCODE); |
129 |
} |
} |
130 |
|
|
131 |
u_char * |
u_char * |
132 |
asn_decode_header(data, datalength, type) |
asn_decode_header(u_char *data, int *datalength, u_char *type) |
|
u_char *data; |
|
|
int *datalength; |
|
|
u_char *type; |
|
133 |
{ |
{ |
134 |
if (*datalength < 1) { |
if (*datalength < 1) { |
135 |
SNMP_SET_ERRNO(E_ASN_DECODE); |
SNMP_SET_ERRNO(E_ASN_DECODE); |
141 |
} |
} |
142 |
|
|
143 |
u_char * |
u_char * |
144 |
asn_encode_null(data, datalength, type) |
asn_encode_null(u_char *data, int *datalength, u_char type) |
|
u_char *data; |
|
|
int *datalength; |
|
|
u_char type; |
|
145 |
{ |
{ |
146 |
return asn_encode_header(data, datalength, type, 0); |
return asn_encode_header(data, datalength, type, 0); |
147 |
} |
} |
161 |
Return:Pointer to the byte immediately past the decoded object. |
Return:Pointer to the byte immediately past the decoded object. |
162 |
Error: NULL */ |
Error: NULL */ |
163 |
u_char * |
u_char * |
164 |
asn_decode_int(data, datalength, type, intp, intsize) |
asn_decode_int(u_char *data, int *datalength, u_char *type, |
165 |
u_char *data; |
int *intp, int intsize) |
|
int *datalength; |
|
|
u_char *type; |
|
|
int *intp; |
|
|
int intsize; |
|
166 |
{ |
{ |
167 |
u_int count; |
u_int count; |
168 |
u_char *buf = data; |
u_char *buf = data; |
208 |
Error: NULL */ |
Error: NULL */ |
209 |
|
|
210 |
u_char * |
u_char * |
211 |
asn_encode_int(data, datalength, type, intval) |
asn_encode_int(u_char *data, int *datalength, u_char type, int intval) |
|
u_char *data; |
|
|
int *datalength; |
|
|
u_char type; |
|
|
int intval; |
|
212 |
{ |
{ |
213 |
u_int mask; |
u_int mask; |
214 |
u_int intsize = sizeof(int); |
u_int intsize = sizeof(int); |
261 |
Return:Pointer to the byte immediately past the decoded object. |
Return:Pointer to the byte immediately past the decoded object. |
262 |
Error: NULL */ |
Error: NULL */ |
263 |
u_char * |
u_char * |
264 |
asn_decode_string(data, datalength, type, string, strlength) |
asn_decode_string(u_char *data, int *datalength, u_char *type, |
265 |
u_char *data; |
u_char *string, int *strlength) |
|
int *datalength; |
|
|
u_char *type; |
|
|
u_char *string; |
|
|
int *strlength; |
|
266 |
{ |
{ |
267 |
u_char *buf = data; |
u_char *buf = data; |
268 |
int count; |
int count; |
292 |
Return:Pointer to the byte immediately past the encoded object. |
Return:Pointer to the byte immediately past the encoded object. |
293 |
Error: NULL */ |
Error: NULL */ |
294 |
u_char * |
u_char * |
295 |
asn_encode_string(data, datalength, type, string, strlength) |
asn_encode_string(u_char *data, int *datalength, u_char type, |
296 |
u_char *data; |
u_char *string, int strlength) |
|
int *datalength; |
|
|
u_char type; |
|
|
u_char *string; |
|
|
int strlength; |
|
297 |
{ |
{ |
298 |
data = asn_encode_header(data, datalength, type, strlength); |
data = asn_encode_header(data, datalength, type, strlength); |
299 |
if (!data || *datalength < strlength) { |
if (!data || *datalength < strlength) { |
328 |
Return:Pointer to the byte immediately past the decoded object. |
Return:Pointer to the byte immediately past the decoded object. |
329 |
Error: NULL */ |
Error: NULL */ |
330 |
u_char * |
u_char * |
331 |
asn_decode_oid(data, datalength, type, obid, obidlength) |
asn_decode_oid(u_char *data, int *datalength, u_char *type, |
332 |
u_char *data; |
oid_t obid, int *obidlength) |
|
int *datalength; |
|
|
u_char *type; |
|
|
oid_t obid; |
|
|
int *obidlength; |
|
333 |
{ |
{ |
334 |
u_char *buf = data; |
u_char *buf = data; |
335 |
u_int count; |
u_int count; |
384 |
Return:Pointer to the byte immediately past the encoded object. |
Return:Pointer to the byte immediately past the encoded object. |
385 |
Error: NULL */ |
Error: NULL */ |
386 |
u_char * |
u_char * |
387 |
asn_encode_oid(data, datalength, type, obid, obidlength) |
asn_encode_oid(u_char *data, int *datalength, u_char type, |
388 |
u_char *data; |
oid_t obid, int obidlength) |
|
int *datalength; |
|
|
u_char type; |
|
|
oid_t obid; |
|
|
int obidlength; |
|
389 |
{ |
{ |
390 |
int length; |
int length; |
391 |
u_char *buf, *bp; |
u_char *buf, *bp; |