Get BITS value
"Yong Chen (yongche)" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <52E903A38F544F46A2A6632AC66103EEDF7D27@xmb-sjc-221.amer.cisco.com> |
Hi,
I have a question regarding BITS object, please help. I'm using netsnmp
5.1.
Say I have an object defined as:
example_obj OBJECT-TYPE
SYNTAX BITS {
v0 (0),
v1 (1),
v2 (2),
v3 (3),
v4 (4),
v5 (5),
v6 (6),
v7 (7),
v8 (8),
v9 (9),
v10 (10),
v11 (11),
v12 (12),
v13 (13)
}
MAX-ACCESS .....
Mib2c compiles BITS into enum, and treats it as int32_t.
typedef enum example_obj_ {
example_obj_V0 =0,
example_obj_V1 =0,
example_obj_V2 =0,
example_obj_V3 =0,
example_obj_V4 =0,
example_obj_V5 =0,
example_obj_V6 =0,
example_obj_V7 =0,
example_obj_V8 =0,
example_obj_V9 =0,
example_obj_V10 =0,
example_obj_V11 =0,
example_obj_V12 =0,
example_obj_V13 =0,
} example_object_t;
Lets say in get func, I want to return the value with v0, v3 and v10
set, so the value is: 1 + 4 + 512 = 517.
Assuming the value is being held in a static local variable: static
int32_t rv=517. Do I just do following:
*var_len=sizeof(int32_t));
return (unsigned char *)&rv;
Or I have to do some bits re-ordering (per RFC 3417, see below), I don't
know if net-snmp agent is doing this conversion (re-ordering) already or
not.
If not, then I'll need to do it. But how? Is following pseudo code
correct?
rv=517; //which is bit15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 (bit
location)
0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 (value
with bit 0,3 and 10 set)
static char v[2]; //since I have bits 0-13, 2 bytes can hold all of
them
//and b15-b8 will be put in v[1] with b8(lowest)
going to b7 of v[1](highest),
//b9 to b6 of v[1]..., b15 to b0 of v[1],
basically reversing the order.
//also b7-b0 will be put in v[0] with b0(lowest)
going to b7 of v[0],
//b1 to b6..., b7 to b0 of v[0].
//since b15-b8 is 00000100, reversed order is 00100000 which is 0x20,
so
v[1]|= 0x20;
//since b7-b0 is 00001001, reversed order is 10010000, which is 0x90,
so
v[0]|=0x90;
*var_len=2;
return v;
Please let me know if it's correct or not.
(Also mib2c by default puts *var_len=sizeof(int32_t), am I correct in
saying it may be wrong? Since it depends on how many bits defined in the
mib, like in this case, the *var_len is 2)
Thanks,
Yong Chen
RFC 3417
8. (3) When encoding an object whose syntax is described using the
BITS construct, the value is encoded as an OCTET STRING, in
which all the named bits in (the definition of) the bitstring,
commencing with the first bit and proceeding to the last bit,
are placed in bits 8 (high order bit) to 1 (low order bit) of
the first octet, followed by bits 8 to 1 of each subsequent
octet in turn, followed by as many bits as are needed of the
final subsequent octet, commencing with bit 8. Remaining bits,
if any, of the final octet are set to zero on generation and
ignored on receipt.
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users