Class: SNMP::Message

### Home Classes Methods

### In Files

- lib/snmp/pdu.rb

### Parent

Object

### Methods

- ::decode
- ::decode_pdu
- ::decode_version
- ::new
- #encode
- #encode_version
- #response

### 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::Message

### Attributes

community[R]
pdu[R]
version[R]

### Public Class Methods

decode(data, mib=nil) click to toggle source

    # File lib/snmp/pdu.rb, line 35
    def decode(data, mib=nil)
      message_data, remainder = decode_sequence(data)
      assert_no_remainder(remainder)
      version, remainder = decode_version(message_data)
      community, remainder = decode_octet_string(remainder)
      pdu, remainder = decode_pdu(version, remainder, mib)
      assert_no_remainder(remainder)
      Message.new(version, community, pdu)
    end

decode_pdu(version, data, mib=nil) click to toggle source

    # File lib/snmp/pdu.rb, line 57
    def decode_pdu(version, data, mib=nil)
      pdu_tag, pdu_data, remainder = decode_tlv(data)
      case pdu_tag
      when GetRequest_PDU_TAG
        pdu = PDU.decode(GetRequest, pdu_data, mib)
      when GetNextRequest_PDU_TAG
        pdu = PDU.decode(GetNextRequest, pdu_data, mib)
      when Response_PDU_TAG
        pdu = PDU.decode(Response, pdu_data, mib)
      when SetRequest_PDU_TAG
        pdu = PDU.decode(SetRequest, pdu_data, mib)
      when SNMPv1_Trap_PDU_TAG
        raise InvalidPduTag, "SNMPv1-trap not valid for #{version.to_s}" if version != :SNMPv1
        pdu = SNMPv1_Trap.decode(pdu_data, mib)
      when GetBulkRequest_PDU_TAG
        raise InvalidPduTag, "get-bulk not valid for #{version.to_s}" if version != :SNMPv2c
        pdu = PDU.decode(GetBulkRequest, pdu_data, mib)
      when InformRequest_PDU_TAG
        raise InvalidPduTag, "inform not valid for #{version.to_s}" if version != :SNMPv2c
        pdu = PDU.decode(InformRequest, pdu_data, mib)
      when SNMPv2_Trap_PDU_TAG
        raise InvalidPduTag, "SNMPv2c-trap not valid for #{version.to_s}" if version != :SNMPv2c
        pdu = PDU.decode(SNMPv2_Trap, pdu_data, mib)
      else
        raise UnsupportedPduTag, pdu_tag.to_s
      end
      return pdu, remainder
    end

decode_version(data) click to toggle source

    # File lib/snmp/pdu.rb, line 45
    def decode_version(data)
      version_data, remainder = decode_integer(data)
      if version_data == SNMP_V1
        version = :SNMPv1
      elsif version_data == SNMP_V2C
        version = :SNMPv2c
      else
        raise UnsupportedVersion, version_data.to_s
      end
      return version, remainder
    end

new(version, community, pdu) click to toggle source

    # File lib/snmp/pdu.rb, line 87
    def initialize(version, community, pdu)
      @version = version
      @community = community
      @pdu = pdu
    end

### Public Instance Methods

encode() click to toggle source

    # File lib/snmp/pdu.rb, line 107
    def encode
      data = encode_version(@version)
      data << encode_octet_string(@community)
      data << @pdu.encode
      encode_sequence(data)
    end

encode_version(version) click to toggle source

    # File lib/snmp/pdu.rb, line 97
    def encode_version(version)
      if version == :SNMPv1
        encode_integer(SNMP_V1)
      elsif version == :SNMPv2c
        encode_integer(SNMP_V2C)
      else
        raise UnsupportedVersion, version.to_s
      end
    end

response() click to toggle source

    # File lib/snmp/pdu.rb, line 93
    def response
      Message.new(@version, @community, Response.from_pdu(@pdu))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.