Class: SNMP::IpAddress
Class Method Summary
collapse
Instance Method Summary
collapse
#encode_exception, #encode_integer, #encode_length, #encode_null, #encode_object_id, #encode_octet_string, #encode_sequence, #encode_tagged_integer, #encode_tlv, #integer_to_octets
Constructor Details
#initialize(value_data, validate = true) ⇒ IpAddress
Create an IpAddress object. The constructor accepts either a raw four-octet string or a formatted string of integers separated by dots (i.e. “10.1.2.3”). Validation of the format can be disabled by setting the ‘validate’ flag to false.
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/snmp/varbind.rb', line 292
def initialize(value_data, validate=true)
ip = value_data.to_str
if (validate)
if ip.length > 4
ip = parse_string(ip)
elsif ip.length != 4
raise InvalidIpAddress, "Expected 4 octets or formatted string, got #{value_data.inspect}"
end
end
@value = ip
end
|
Class Method Details
.decode(value_data) ⇒ Object
277
278
279
|
# File 'lib/snmp/varbind.rb', line 277
def decode(value_data)
IpAddress.new(value_data, false)
end
|
Instance Method Details
#==(other) ⇒ Object
326
327
328
329
330
331
332
|
# File 'lib/snmp/varbind.rb', line 326
def ==(other)
if other.respond_to? :to_str
return @value.eql?(other.to_str)
else
return false
end
end
|
#asn1_type ⇒ Object
282
283
284
|
# File 'lib/snmp/varbind.rb', line 282
def asn1_type
"IpAddress"
end
|
#encode ⇒ Object
342
343
344
|
# File 'lib/snmp/varbind.rb', line 342
def encode
encode_tlv(BER::IpAddress_TAG, @value)
end
|
#eql?(other) ⇒ Boolean
334
335
336
|
# File 'lib/snmp/varbind.rb', line 334
def eql?(other)
self == other
end
|
#hash ⇒ Object
338
339
340
|
# File 'lib/snmp/varbind.rb', line 338
def hash
@value.hash
end
|
#to_oid ⇒ Object
320
321
322
323
324
|
# File 'lib/snmp/varbind.rb', line 320
def to_oid
oid = ObjectId.new
@value.each_byte { |b| oid << b }
oid
end
|
#to_s ⇒ Object
Returns a formatted, dot-separated string representing this IpAddress.
314
315
316
317
318
|
# File 'lib/snmp/varbind.rb', line 314
def to_s
octets = []
@value.each_byte { |b| octets << b.to_s }
octets.join('.')
end
|
#to_str ⇒ Object
Returns a raw four-octet string representing this IpAddress.
307
308
309
|
# File 'lib/snmp/varbind.rb', line 307
def to_str
@value.dup
end
|