Discussion:
Sending signed values problem
Bill Fenner
2017-06-27 14:51:46 UTC
Permalink
On Thu, Jun 22, 2017 at 10:37 AM, corvace.fabrizio--- via Net-snmp-users <
Hello,
I'm currently struggling with a data problem.
I have a system where i have to SET a value, the value is of type Integer
(-32768.32767).
When sending a value over 255 i have no problem with sign, if i scan with
wireshark i see a transmission of ASN type 2(Integer) with 2 bytes of data,
and the data is correctly sent with sign.
But whenever i try to send a value that is less that 256, therefore fits
in a byte, the transmission is still of type 2, but it sends out one single
byte of data, thus cutting out the range from -129 to -255 and from +128 to
+255.
I would have thought that since the OID is of type Integer (explicitly
16bit) the data would still have been sent as 2bytes.
BER encoding is variable length, no matter what the restrictions on the
range of the integer - restrictions like that are managed at a higher layer.

As you surmise, the BER encoding of values from -129 to -255 and +128 to
+255 are two bytes long.
I tried looking for a way of forcing 2 byte data send, but with no luck.
Am i missing something?
How are you sending your data? I do not know of a way to force net-snmp to
behave in this incorrect way.

Bill
Bill Fenner
2017-06-27 16:35:54 UTC
Permalink
snmpset -v 2c -c public "IP" "OID" = -100
Watching the data over wireshark tho, the data length for that command is
1.
But if i send for example -130 i get a data length of 2.
Yes, that is correct behavior. What is the problem?

Bill
On Thu, Jun 22, 2017 at 10:37 AM, corvace.fabrizio--- via Net-snmp-users <
Hello,
I'm currently struggling with a data problem.
I have a system where i have to SET a value, the value is of type Integer
(-32768.32767).
When sending a value over 255 i have no problem with sign, if i scan with
wireshark i see a transmission of ASN type 2(Integer) with 2 bytes of data,
and the data is correctly sent with sign.
But whenever i try to send a value that is less that 256, therefore fits
in a byte, the transmission is still of type 2, but it sends out one single
byte of data, thus cutting out the range from -129 to -255 and from +128 to
+255.
I would have thought that since the OID is of type Integer (explicitly
16bit) the data would still have been sent as 2bytes.
BER encoding is variable length, no matter what the restrictions on the
range of the integer - restrictions like that are managed at a higher layer.
As you surmise, the BER encoding of values from -129 to -255 and +128 to
+255 are two bytes long.
I tried looking for a way of forcing 2 byte data send, but with no luck.
Am i missing something?
How are you sending your data? I do not know of a way to force net-snmp
to behave in this incorrect way.
Bill
Bill Fenner
2017-06-28 14:41:41 UTC
Permalink
If you send a value between 0 and -128 you get a one byte value. If you
send a value between -129 and -32768 you get a two byte value. This is BER
encoding.

You showed -130 being encoded properly, which is between -128 and -256
which is what you say doesn't work. I don't understand why you say both of
those things.

Bill
The problem is that the OID is a 16bit Integer, if i send -256 i get a
2byte signed value, but if i send any value between 0 and -128 i get a
1byte signed value, thus losing the range from -128 to -256, same thing for
the positive range.
I'm sorry, in the last mail i gave the wrong example reporting -130.
snmpset -v 2c -c public "IP" "OID" = -100
Watching the data over wireshark tho, the data length for that command is
1.
But if i send for example -130 i get a data length of 2.
Yes, that is correct behavior. What is the problem?
Bill
On Thu, Jun 22, 2017 at 10:37 AM, corvace.fabrizio--- via Net-snmp-users <
Hello,
I'm currently struggling with a data problem.
I have a system where i have to SET a value, the value is of type Integer
(-32768.32767).
When sending a value over 255 i have no problem with sign, if i scan with
wireshark i see a transmission of ASN type 2(Integer) with 2 bytes of data,
and the data is correctly sent with sign.
But whenever i try to send a value that is less that 256, therefore fits
in a byte, the transmission is still of type 2, but it sends out one single
byte of data, thus cutting out the range from -129 to -255 and from +128 to
+255.
I would have thought that since the OID is of type Integer (explicitly
16bit) the data would still have been sent as 2bytes.
BER encoding is variable length, no matter what the restrictions on the
range of the integer - restrictions like that are managed at a higher layer.
As you surmise, the BER encoding of values from -129 to -255 and +128 to
+255 are two bytes long.
I tried looking for a way of forcing 2 byte data send, but with no luck.
Am i missing something?
How are you sending your data? I do not know of a way to force net-snmp
to behave in this incorrect way.
Bill
Loading...