Class SNMP::IpAddress
In: lib/snmp/varbind.rb
Parent: Object

Methods

==   asn1_type   decode   encode   eql?   hash   new   to_oid   to_s   to_str  

Public Class methods

[Source]

# File lib/snmp/varbind.rb, line 232
        def decode(value_data)
            IpAddress.new(value_data)
        end

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").

[Source]

# File lib/snmp/varbind.rb, line 246
    def initialize(value_data)
        ip = value_data.to_str
        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
        @value = ip
    end

Public Instance methods

[Source]

# File lib/snmp/varbind.rb, line 278
    def ==(other)
        if other.respond_to? :to_str
            return @value.eql?(other.to_str)
        else
            return false
        end
    end

[Source]

# File lib/snmp/varbind.rb, line 237
    def asn1_type
        "IpAddress"
    end

[Source]

# File lib/snmp/varbind.rb, line 294
    def encode
        encode_tlv(IpAddress_TAG, @value)
    end

[Source]

# File lib/snmp/varbind.rb, line 286
    def eql?(other)
        self == other
    end

[Source]

# File lib/snmp/varbind.rb, line 290
    def hash
        @value.hash
    end

[Source]

# File lib/snmp/varbind.rb, line 272
    def to_oid
        oid = ObjectId.new
        @value.each_byte { |b| oid << b }
        oid
    end

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

[Source]

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

Returns a raw four-octet string representing this IpAddress.

[Source]

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

[Validate]