class SNMP::IpAddress

Public Class Methods

new(value_data, validate=true) click to toggle source

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.

# File lib/snmp/varbind.rb, line 277
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

Public Instance Methods

==(other) click to toggle source
# File lib/snmp/varbind.rb, line 311
def ==(other)
  if other.respond_to? :to_str
    return @value.eql?(other.to_str)
  else
    return false
  end
end
asn1_type() click to toggle source
# File lib/snmp/varbind.rb, line 267
def asn1_type
  "IpAddress"
end
decode(value_data) click to toggle source
# File lib/snmp/varbind.rb, line 262
def decode(value_data)
  IpAddress.new(value_data, false)
end
encode() click to toggle source
# File lib/snmp/varbind.rb, line 327
def encode
  encode_tlv(IpAddress_TAG, @value)
end
eql?(other) click to toggle source
# File lib/snmp/varbind.rb, line 319
def eql?(other)
  self == other
end
hash() click to toggle source
# File lib/snmp/varbind.rb, line 323
def hash
  @value.hash
end
to_oid() click to toggle source
# File lib/snmp/varbind.rb, line 305
def to_oid
  oid = ObjectId.new
  @value.each_byte { |b| oid << b }
  oid
end
to_s() click to toggle source

Returns a formatted, dot-separated string representing this IpAddress.

# File lib/snmp/varbind.rb, line 299
def to_s
  octets = []
  @value.each_byte { |b| octets << b.to_s }
  octets.join('.')
end
to_str() click to toggle source

Returns a raw four-octet string representing this IpAddress.

# File lib/snmp/varbind.rb, line 292
def to_str
  @value.dup
end