Skip to content

Commit 40b5554

Browse files
author
blackhedd
committed
tweaked get-response parsing
1 parent 977f276 commit 40b5554

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/net/snmp.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ def parse_ber_object ber_object
163163
when 2
164164
send :pdu_type=, :get_response
165165
# This PDU is identical to get-request except for the type,
166+
# the error_status and error_index values are meaningful,
166167
# and the fact that the variable bindings will be non-null.
167-
parse_get_request data
168+
parse_get_response data
168169
else
169170
raise Error.new( "unknown snmp-pdu type: #{app_tag}" )
170171
end
@@ -175,8 +176,10 @@ def parse_ber_object ber_object
175176
# Defined in RFC1157, pgh 4.1.2.
176177
def parse_get_request data
177178
send :request_id=, data[0].to_i
178-
send :error_status=, data[1].to_i
179-
send :error_index=, data[2].to_i
179+
# data[1] is error_status, always zero.
180+
# data[2] is error_index, always zero.
181+
send :error_status=, 0
182+
send :error_index=, 0
180183
data[3].each {|n,v|
181184
# A variable-binding, of which there may be several,
182185
# consists of an OID and a BER null.
@@ -189,6 +192,21 @@ def parse_get_request data
189192
end
190193
private :parse_get_request
191194

195+
#--
196+
# Defined in RFC1157, pgh 4.1.4
197+
def parse_get_response data
198+
send :request_id=, data[0].to_i
199+
send :error_status=, data[1].to_i
200+
send :error_index=, data[2].to_i
201+
data[3].each {|n,v|
202+
# A variable-binding, of which there may be several,
203+
# consists of an OID and a BER null.
204+
# We're ignoring the null, we might want to verify it instead.
205+
add_variable_binding n, v
206+
}
207+
end
208+
private :parse_get_response
209+
192210

193211
def version= ver
194212
unless [0,2].include?(ver)

0 commit comments

Comments
 (0)