Class: SNMP::IpAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp/varbind.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_data) ⇒ 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”).



202
203
204
205
206
207
208
209
# File 'lib/snmp/varbind.rb', line 202

def initialize(value_data)
    if value_data.length > 4
        value_data = parse_string(value_data)
    elsif value_data.length != 4
        raise InvalidIpAddress, "Expected 4 octets or formatted string, got #{value_data.inspect}"
    end
    @value = value_data
end

Class Method Details

.decode(value_data) ⇒ Object



188
189
190
# File 'lib/snmp/varbind.rb', line 188

def decode(value_data)
    IpAddress.new(value_data)
end

Instance Method Details

#==(other) ⇒ Object



227
228
229
230
231
232
233
# File 'lib/snmp/varbind.rb', line 227

def ==(other)
    if other.respond_to? :to_str
        return @value.eql?(other.to_str)
    else
        return false
    end
end

#asn1_typeObject



193
194
195
# File 'lib/snmp/varbind.rb', line 193

def asn1_type
    "IpAddress"
end

#encodeObject



243
244
245
# File 'lib/snmp/varbind.rb', line 243

def encode
    encode_tlv(IpAddress_TAG, @value)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/snmp/varbind.rb', line 235

def eql?(other)
    self == other
end

#hashObject



239
240
241
# File 'lib/snmp/varbind.rb', line 239

def hash
    @value.hash
end

#to_sObject

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



221
222
223
224
225
# File 'lib/snmp/varbind.rb', line 221

def to_s
    octets = []
    @value.each_byte { |b| octets << b.to_s }
    octets.join('.')    
end

#to_strObject

Returns a raw four-octet string representing this IpAddress.



214
215
216
# File 'lib/snmp/varbind.rb', line 214

def to_str
    @value.dup
end