How to encode and decode large OID values?

I have OID 1.3.6.1.2.1.2.2.1.8.4096 (ifOperStatus)

In my code, I have:

MIB[0]=0x2b MIB[1]=0x06 MIB[2]=0x01 MIB[3]=0x02 MIB[4]=0x01 MIB[5]=0x02 MIB[6]=0x02 MIB[7]=0x01 MIB[8]=0x08 MIB[9]=0xA0 MIB[10]=0x00 

where A0 00 represents 4096.

4096 in HEX is 1000. Violating this in 2 bytes will give me 10 00. SNMP data should be sent in single-byte format. Therefore, for large numbers, a special rule is required, because one byte (eight bits) can only represent a number from 0 to 255. The rule is that the highest order bit is used as a flag, so that the recipient knows that this number spans more than one byte.

I pushed the bits to the left and added 1 to the 8th bit.

Left Shift: 20 00
Bit 8 becomes 1: A0 00

Link: [OID Encoding] ( http://www.rane.com/note161.html )

Am I correctly encoded 4096?

What about decoding a data string in the original OID?

Examples would be good for me to understand the concept.

+4
source share
1 answer

Yes, you encoded the OID correctly (as far as the content is concerned). The full encoding (with the OID tag and the length that were omitted) will be 06 0b 2b 06 01 02 01 02 02 01 08 a0 00.

Regarding the encoding / decoding strings in the OID (presumably INDEX), the rules depend on whether this value refers to an object defined as a fixed-length string or a variable-length string, and regardless of whether the IMPLIED keyword was used to define INDEX.

If it is a fixed-length string or a variable-length string with the IMPLIED keyword (which should be the last INDEX object), then it is encoded simply as one subdiagnosis for each byte of the string. Otherwise, a variable-length string is encoded with one subband to indicate the length of the string, followed by each byte encoded in one subband, as with a fixed length.

Section 7.7 of RFC 2578 details the encoding rules for values ​​for INDEX objects in OIDs.

+4
source

Source: https://habr.com/ru/post/1496461/


All Articles