Class: SNMP::IpAddress
- Inherits:
-
Object
- Object
- SNMP::IpAddress
- Defined in:
- lib/snmp/varbind.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #asn1_type ⇒ Object
- #encode ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(value_data, validate = true) ⇒ IpAddress
constructor
Create an IpAddress object.
- #to_oid ⇒ Object
-
#to_s ⇒ Object
Returns a formatted, dot-separated string representing this IpAddress.
-
#to_str ⇒ Object
Returns a raw four-octet string representing this IpAddress.
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.
264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/snmp/varbind.rb', line 264 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
Instance Method Details
#==(other) ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/snmp/varbind.rb', line 298 def ==(other) if other.respond_to? :to_str return @value.eql?(other.to_str) else return false end end |
#asn1_type ⇒ Object
254 255 256 |
# File 'lib/snmp/varbind.rb', line 254 def asn1_type "IpAddress" end |
#encode ⇒ Object
314 315 316 |
# File 'lib/snmp/varbind.rb', line 314 def encode encode_tlv(IpAddress_TAG, @value) end |
#eql?(other) ⇒ Boolean
306 307 308 |
# File 'lib/snmp/varbind.rb', line 306 def eql?(other) self == other end |
#hash ⇒ Object
310 311 312 |
# File 'lib/snmp/varbind.rb', line 310 def hash @value.hash end |
#to_oid ⇒ Object
292 293 294 295 296 |
# File 'lib/snmp/varbind.rb', line 292 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.
286 287 288 289 290 |
# File 'lib/snmp/varbind.rb', line 286 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.
279 280 281 |
# File 'lib/snmp/varbind.rb', line 279 def to_str @value.dup end |