Skip to content

Conversation

@N1IOX
Copy link
Contributor

@N1IOX N1IOX commented Jan 16, 2026

Fixes #61

add ByteType (derived from IntegerType), and use this for protocol fields (SNMP version, error status / non-repeaters, error index / repeaters).
add _knownLen to IntegerType: defaults to 4 (1 for ByteType), and is set to the decoded _length in fromBuffer().
this is then used in serialise(), where it selectively outputs extra bytes only when needed.

with all that, the resultant outgoing packet will be at least 9 bytes shorter.

for certain packets, it could be 10 bytes shorter, if the decrease by 9 forces a containing struct's length to drop from requiring 2 bytes to encode its length down to 1, etc.

that is the case for the test packet returned by the test.cpp GenerateTestSNMPRequestPacket() function.
it was generating a 133 byte packet, but now is only 123.

update the unit tests to now use a const (const int expected_length = 123;) throughout.

0neblock and others added 5 commits August 9, 2024 07:13
a length of exactly 256 should be encoded as:
0x82 0x01 0x00

without this change, I was seeing the encoded length of a get response (that happened to be exactly 256 bytes long) encoded as:
0x81 0x00

that was causing snmpbulkwalk to fail, since it was reading the encoded length as 0.
…elds (SNMP version, error status / non-repeaters, error index / repeaters).

add _knownLen to IntegerType: defaults to 4 (1 for ByteType), and is set to the decoded _length in fromBuffer().
this is then used in serialise(), where it selectively outputs extra bytes only when needed.

with all that, the resultant outgoing packet will be at least 9 bytes shorter.

for certain packets, it could be 10 bytes shorter, if the decrease by 9 forces a containing struct's length to drop from requiring 2 bytes to encode its length down to 1, etc.

that is the case for the test packet returned by the test.cpp GenerateTestSNMPRequestPacket() function.
it was generating a 133 byte packet, but now is only 123.

update the unit tests to now use a const (const int expected_length = 123;) throughout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Certain int fields in generated packets are longer than needed

2 participants