Class: SNMP::IpAddress

### Home Classes Methods

### In Files

- lib/snmp/varbind.rb

### Parent

Object

### Methods

- ::decode
- ::new
- #==
- #asn1_type
- #encode
- #eql?
- #hash
- #to_oid
- #to_s
- #to_str

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- SNMP
- SNMP::BER
- SNMP::Counter32
- SNMP::Counter64
- SNMP::EndOfMibView
- SNMP::Gauge32
- SNMP::GetBulkRequest
- SNMP::GetNextRequest
- SNMP::GetRequest
- SNMP::InformRequest
- SNMP::Integer
- SNMP::Integer32
- SNMP::InvalidErrorStatus
- SNMP::InvalidGenericTrap
- SNMP::InvalidIpAddress
- SNMP::InvalidPduTag
- SNMP::InvalidTrapVarbind
- SNMP::IpAddress
- SNMP::MIB
- SNMP::MIB::ModuleNotLoadedError
- SNMP::Manager
- SNMP::Manager::Config
- SNMP::Message
- SNMP::NoSuchInstance
- SNMP::NoSuchObject
- SNMP::Null
- SNMP::ObjectId
- SNMP::ObjectName
- SNMP::OctetString
- SNMP::Opaque
- SNMP::PDU
- SNMP::ParseError
- SNMP::RequestId
- SNMP::RequestTimeout
- SNMP::Response
- SNMP::SNMPv1_Trap
- SNMP::SNMPv2_Trap
- SNMP::SetRequest
- SNMP::TimeTicks
- SNMP::TrapListener
- SNMP::TrapListener::Config
- SNMP::UDPServerTransport
- SNMP::UDPTransport
- SNMP::Unsigned32
- SNMP::UnsignedInteger
- SNMP::UnsupportedPduTag
- SNMP::UnsupportedValueTag
- SNMP::UnsupportedVersion
- SNMP::VarBind
- SNMP::VarBindList
- Fixnum
- Object

No matching classes.

# SNMP::IpAddress

### Public Class Methods

decode(value_data) click to toggle source

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

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 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

### Public Instance Methods

==(other) click to toggle source

    # 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() click to toggle source

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

encode() click to toggle source

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

eql?(other) click to toggle source

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

hash() click to toggle source

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

to_oid() click to toggle source

    # File lib/snmp/varbind.rb, line 292
    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 286
    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 279
    def to_str
      @value.dup
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.