0

I have a question about SNMP encoding of UNSIGNED32. I tried to implemet a stack to process SNMP requests, and I would like to use UNSIGNED32 type. But when I use a Wireshark to dump the net traffic, it shows, that the type is GAUGE32 (which is ok, according to SNMPv2) but it shows value "-1" (I sent data 0xFFFFFFFF). The value is encoded via ASN.1 as 0x42 0x04 0xFF 0xFF 0xFF 0xFF, and I think it should show 4294967295. So my question is -> Is that value encoded in a wrong way and there should be leading zero () or Wireshark decode it poorly?

  • Does this answer your question? [Oddity when encoding large integers using asn.1](https://stackoverflow.com/questions/12860226/oddity-when-encoding-large-integers-using-asn-1) – TallChuck Aug 25 '22 at 16:39

1 Answers1

1

ASN.1 is very strict in saying that all integer representations use two's complement. The key to understand is that the definition of UNSIGNED32 or GAUGE32 is part of the SNMPv2-SMI, which is a higher abstraction layer than the ASN.1 specification. Even though it's perfectly obvious at the SNMP level that a number is unsigned, based on the MIB definition, it's still technically wrong to leave the leading 0 bit off of an unsigned integer.

For fun, here's a link to a (somewhat condescending) answer to basically the same question.

TallChuck
  • 1,725
  • 11
  • 28
  • Link shows coding of INTEGER, and that is clear. So when I have to add the byte to show the number signedness, UNSIGNED32 lacks of its 32bit definition (at least it has it in the name UNSIGNED32), becauce you have to use up to five bytes, not four. It is resource wasting, isn't it? Then, how the UNSIGNED32 value 0xFFFFFFFF should be understood? Is it fault of SNMP device to return it? And why would one use UNSIGNED32, when it is totaly same as INTEGER.. – Daniel Šebík Aug 31 '22 at 17:05
  • SMI-v2 defines UNSIGNED32 as "IMPLICIT INTEGER (0..4294967295)". Is this the line that tells me to keep the INTEGER format with leading zeros? – Daniel Šebík Aug 31 '22 at 17:14
  • I can find nothing in the SNMP standards that mentions whether unsigned integers require a leading sign bit, so I assume it must follow the ASN.1 standard, which is to always encode integers as signed values – TallChuck Aug 31 '22 at 17:49