### Home Classes Methods

### In Files

- lib/packetfu/protos/lldp/header.rb

### Parent

Struct.new(:lldp_chassis_id_type, :lldp_chassis_id, :lldp_port_id_type, :lldp_port_id, :lldp_ttl, :lldp_port_description, :lldp_system_name, :lldp_system_description, :lldp_capabilty, :lldp_enabled_capability, :lldp_address_type, :lldp_address, :lldp_interface_type, :lldp_interface, :lldp_oid)

### Methods

- ::new
- #lldp_address
- #lldp_address_type
- #lldp_address_type=
- #lldp_address_type_readable
- #lldp_capabilty=
- #lldp_capabilty_readable
- #lldp_chassis_id
- #lldp_chassis_id=
- #lldp_chassis_id_readable
- #lldp_chassis_id_type
- #lldp_chassis_id_type=
- #lldp_enabled_capability=
- #lldp_enabled_capability_readable
- #lldp_interface
- #lldp_interface=
- #lldp_interface_type
- #lldp_interface_type=
- #lldp_oid
- #lldp_oid=
- #lldp_port_description
- #lldp_port_description=
- #lldp_port_id=
- #lldp_port_id_readable
- #lldp_port_id_type
- #lldp_port_id_type=
- #lldp_saddr_ip
- #lldp_saddr_ip=
- #lldp_saddr_mac
- #lldp_saddr_mac=
- #lldp_system_description
- #lldp_system_description=
- #lldp_system_name
- #lldp_system_name=
- #lldp_ttl
- #lldp_ttl=
- #read
- #to_s

### Included Modules

- StructFu

### Files

- .document
- README.rdoc

### Class/Module Index

Quicksearch

- PacketFu
- PacketFu::ARPHeader
- PacketFu::ARPHeaderMixin
- PacketFu::ARPPacket
- PacketFu::AddrIpv6
- PacketFu::Capture
- PacketFu::Config
- PacketFu::EthHeader
- PacketFu::EthHeaderMixin
- PacketFu::EthMac
- PacketFu::EthNic
- PacketFu::EthOui
- PacketFu::EthPacket
- PacketFu::HSRPHeader
- PacketFu::HSRPHeaderMixin
- PacketFu::HSRPPacket
- PacketFu::ICMPHeader
- PacketFu::ICMPHeaderMixin
- PacketFu::ICMPPacket
- PacketFu::IPHeader
- PacketFu::IPHeaderMixin
- PacketFu::IPPacket
- PacketFu::IPv6Header
- PacketFu::IPv6HeaderMixin
- PacketFu::IPv6Packet
- PacketFu::Inject
- PacketFu::InvalidHeader
- PacketFu::InvalidPacket
- PacketFu::LLDPHeader
- PacketFu::LLDPHeaderMixin
- PacketFu::LLDPPacket
- PacketFu::Octets
- PacketFu::Packet
- PacketFu::PcapFile
- PacketFu::PcapHeader
- PacketFu::PcapPacket
- PacketFu::PcapPackets
- PacketFu::Read
- PacketFu::TCPHeader
- PacketFu::TCPHeaderMixin
- PacketFu::TCPPacket
- PacketFu::TcpEcn
- PacketFu::TcpFlags
- PacketFu::TcpHlen
- PacketFu::TcpOption
- PacketFu::TcpOption::ECHO
- PacketFu::TcpOption::ECHOREPLY
- PacketFu::TcpOption::EOL
- PacketFu::TcpOption::MSS
- PacketFu::TcpOption::NOP
- PacketFu::TcpOption::SACK
- PacketFu::TcpOption::SACKOK
- PacketFu::TcpOption::TS
- PacketFu::TcpOption::WS
- PacketFu::TcpOptions
- PacketFu::TcpReserved
- PacketFu::Timestamp
- PacketFu::UDPHeader
- PacketFu::UDPHeaderMixin
- PacketFu::UDPPacket
- PacketFu::Utils
- PacketFu::Write
- StructFu
- StructFu::Int
- StructFu::Int16
- StructFu::Int16be
- StructFu::Int16le
- StructFu::Int32
- StructFu::Int32be
- StructFu::Int32le
- StructFu::Int8
- StructFu::IntString
- StructFu::String
- Struct

No matching classes.

# PacketFu::LLDPHeader

LLDPHeader is a complete LLDP struct, used in LLDPPacket.

### Public Class Methods

new(args={}) click to toggle source

    # File lib/packetfu/protos/lldp/header.rb, line 7
    def initialize(args={})
      src_mac = (args[:lldp_port_id] if :lldp_port_id_type == 3) || (args[:config][:eth_src] if args[:config])
      src_ip_bin = (args[:lldp_address] if :lldp_address_type == 1) || (args[:config][:ip_src_bin] if args[:config])

      super(Int8.new(args[:lldp_chassis_id_type] || 4),
      StructFu::String.new.read(:lldp_chassis_id),
      Int8.new(args[:lldp_port_id_type] || 3),
      EthMac.new.read(src_mac),
      Int16.new(args[:lldp_ttl] || 120),
      StructFu::String.new.read(:lldp_port_description) || "",
      StructFu::String.new.read(:lldp_system_name) || "",
      StructFu::String.new.read(:lldp_system_description) || "",
      Int16.new(args[:lldp_capabilty] || 0x0080),
      Int16.new(args[:lldp_enabled_capability] || 0x0080),
      Int8.new(args[:lldp_address_type] || 1),
      StructFu::String.new.read(:lldp_address) || src_ip_bin,
      Int8.new(args[:lldp_interface_type] || 2),
      Int32.new(args[:lldp_interface]),
      StructFu::String.new.read(:lldp_oid) || ""
      )
    end

### Public Instance Methods

lldp_address() click to toggle source
Alias for: lldp_saddr_ip
lldp_address_type() click to toggle source

Getter for the LLDP address type.

    # File lib/packetfu/protos/lldp/header.rb, line 181
    def lldp_address_type; self[:lldp_address_type].to_i; end

lldp_address_type=(i) click to toggle source

Setter for the LLDP address type.

    # File lib/packetfu/protos/lldp/header.rb, line 179
    def lldp_address_type=(i); typecast i; end

lldp_address_type_readable() click to toggle source

    # File lib/packetfu/protos/lldp/header.rb, line 222
    def lldp_address_type_readable
      case lldp_address_type
      when 1
        "IPv4"
      when 2
        "IPv6"
      when 6
        "MAC"
      else
        lldp_address_type
      end
    end

lldp_capabilty=(i) click to toggle source

Setter for the LLDP capability.

    # File lib/packetfu/protos/lldp/header.rb, line 174
    def lldp_capabilty=(i); typecast i; end

lldp_capabilty_readable() click to toggle source

    # File lib/packetfu/protos/lldp/header.rb, line 235
    def lldp_capabilty_readable
      "0x%04x" % lldp_capabilty
    end

lldp_chassis_id() click to toggle source

Readability aliases

Alias for: lldp_saddr_mac
lldp_chassis_id=(i) click to toggle source

Setter for the LLDP chassis id.

    # File lib/packetfu/protos/lldp/header.rb, line 124
    def lldp_chassis_id=(i); typecast i; end

lldp_chassis_id_readable() click to toggle source

Getter for the LLDP chassis id .

    # File lib/packetfu/protos/lldp/header.rb, line 126
    def lldp_chassis_id_readable()
      if self[:lldp_chassis_id_type].to_i == 4
        return EthHeader.str2mac(self[:lldp_chassis_id].to_s)
      else
        return self[:lldp_chassis_id].to_s
      end
    end

lldp_chassis_id_type() click to toggle source

Getter for the LLDP chassis id type.

    # File lib/packetfu/protos/lldp/header.rb, line 122
    def lldp_chassis_id_type; self[:lldp_chassis_id_type].to_i; end

lldp_chassis_id_type=(i) click to toggle source

Setter for the LLDP chassis id type.

    # File lib/packetfu/protos/lldp/header.rb, line 120
    def lldp_chassis_id_type=(i); typecast i; end

lldp_enabled_capability=(i) click to toggle source

Setter for the LLDP enabled capability.

    # File lib/packetfu/protos/lldp/header.rb, line 176
    def lldp_enabled_capability=(i); typecast i; end

lldp_enabled_capability_readable() click to toggle source

    # File lib/packetfu/protos/lldp/header.rb, line 239
    def lldp_enabled_capability_readable
      "0x%04x" % lldp_enabled_capability
    end

lldp_interface() click to toggle source

Getter for the LLDP interface type.

    # File lib/packetfu/protos/lldp/header.rb, line 189
    def lldp_interface; self[:lldp_interface].to_i; end

lldp_interface=(i) click to toggle source

Setter for the LLDP interface.

    # File lib/packetfu/protos/lldp/header.rb, line 187
    def lldp_interface=(i); typecast i; end

lldp_interface_type() click to toggle source

Getter for the LLDP interface type.

    # File lib/packetfu/protos/lldp/header.rb, line 185
    def lldp_interface_type; self[:lldp_interface_type].to_i; end

lldp_interface_type=(i) click to toggle source

Setter for the LLDP interface type.

    # File lib/packetfu/protos/lldp/header.rb, line 183
    def lldp_interface_type=(i); typecast i; end

lldp_oid() click to toggle source

Getter for the LLDP oid type.

    # File lib/packetfu/protos/lldp/header.rb, line 193
    def lldp_oid; self[:lldp_oid].to_i; end

lldp_oid=(i) click to toggle source

Setter for the LLDP oid.

    # File lib/packetfu/protos/lldp/header.rb, line 191
    def lldp_oid=(i); typecast i; end

lldp_port_description() click to toggle source

Getter for the LLDP port description.

    # File lib/packetfu/protos/lldp/header.rb, line 164
    def lldp_port_description; self[:lldp_port_description].to_s; end

lldp_port_description=(i) click to toggle source

Setter for the LLDP port description.

    # File lib/packetfu/protos/lldp/header.rb, line 162
    def lldp_port_description=(i); typecast i; end

lldp_port_id=(i) click to toggle source

Setter for the LLDP port id .

    # File lib/packetfu/protos/lldp/header.rb, line 138
    def lldp_port_id=(i); typecast i; end

lldp_port_id_readable() click to toggle source

Getter for the LLDP port id.

    # File lib/packetfu/protos/lldp/header.rb, line 140
    def lldp_port_id_readable()
      #if mac addr
      if self[:lldp_port_id_type].to_i == 3
        return EthHeader.str2mac(self[:lldp_port_id].to_s)
      else
        return self[:lldp_port_id].to_s
      end
    end

lldp_port_id_type() click to toggle source

Getter for the LLDP port id type.

    # File lib/packetfu/protos/lldp/header.rb, line 136
    def lldp_port_id_type; self[:lldp_port_id_type].to_i; end

lldp_port_id_type=(i) click to toggle source

Setter for the LLDP port id type.

    # File lib/packetfu/protos/lldp/header.rb, line 134
    def lldp_port_id_type=(i); typecast i; end

lldp_saddr_ip() click to toggle source

Get a more readable source IP address.

    # File lib/packetfu/protos/lldp/header.rb, line 208
    def lldp_saddr_ip
      #ipv4 or ipv6
      if (self[:lldp_address_type].to_i == 1) or (self[:lldp_address_type].to_i == 2)
        begin
          IPAddr::ntop(self[:lldp_address])
        rescue
          self[:lldp_address]
        end
      elsif  self[:lldp_address_type].to_i == 6
        #mac
        EthHeader.str2mac(self[:lldp_address].to_s)
      end
    end

Also aliased as: lldp_address
lldp_saddr_ip=(addr) click to toggle source

Set a more readable source IP address.

    # File lib/packetfu/protos/lldp/header.rb, line 202
    def lldp_saddr_ip=(addr)
      self[:lldp_address_type] = 1
      self[:lldp_address].read_quad(addr)
    end

lldp_saddr_mac() click to toggle source

Get a more readable source MAC address.

    # File lib/packetfu/protos/lldp/header.rb, line 197
    def lldp_saddr_mac
      EthHeader.str2mac(self[:lldp_port_id].to_s)
    end

Also aliased as: lldp_chassis_id
lldp_saddr_mac=(mac) click to toggle source

Set the source MAC address in a more readable way.

    # File lib/packetfu/protos/lldp/header.rb, line 150
    def lldp_saddr_mac=(mac)
      mac = EthHeader.mac2str(mac)
      self[:lldp_port_id_type] = 3
      self[:lldp_port_id].read(mac)
      self.lldp_port_id
    end

lldp_system_description() click to toggle source

Getter for the LLDP system description.

    # File lib/packetfu/protos/lldp/header.rb, line 172
    def lldp_system_description; self[:lldp_system_description].to_s; end

lldp_system_description=(i) click to toggle source

Setter for the LLDP system description.

    # File lib/packetfu/protos/lldp/header.rb, line 170
    def lldp_system_description=(i); typecast i; end

lldp_system_name() click to toggle source

Getter for the LLDP system name.

    # File lib/packetfu/protos/lldp/header.rb, line 168
    def lldp_system_name; self[:lldp_system_name].to_s; end

lldp_system_name=(i) click to toggle source

Setter for the LLDP system name.

    # File lib/packetfu/protos/lldp/header.rb, line 166
    def lldp_system_name=(i); typecast i; end

lldp_ttl() click to toggle source

Getter for the LLDP ttl.

    # File lib/packetfu/protos/lldp/header.rb, line 160
    def lldp_ttl; self[:lldp_ttl].to_i; end

lldp_ttl=(i) click to toggle source

Setter for the LLDP ttl.

    # File lib/packetfu/protos/lldp/header.rb, line 158
    def lldp_ttl=(i); typecast i; end

read(str) click to toggle source

Reads a string to populate the object.

    # File lib/packetfu/protos/lldp/header.rb, line 35
    def read(str)
      force_binary(str)
      return self if str.nil?
      index = 0
      #check for lldp pdu end
      while (str[index,2] != "\x00\x00") && (index+2 < str.size)
        tlv_known = false
        #chassis subtype
        if str[index,1] == "\x02"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_chassis_id_type].read(str[index+2,1])
          self[:lldp_chassis_id].read(str[index+3, tlv_length - 1])
          index += tlv_length + 2
        end
        #port subtype
        if str[index,1] == "\x04"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_port_id_type].read(str[index+2,1])
          self[:lldp_port_id].read(str[index+3, tlv_length - 1])
          index += tlv_length + 2
        end
        #ttl subtype
        if str[index,1] == "\x06"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_ttl].read(str[index+2, tlv_length])
          index += tlv_length + 2
        end
        #port description
        if str[index,1] == "\x08"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_port_description].read(str[index+2, tlv_length])
          index += tlv_length + 2
        end
        #system name
        if str[index,1] == "\x0a"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_system_name].read(str[index+2, tlv_length])
          index += tlv_length + 2
        end
        #system description
        if str[index,1] == "\x0c"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_system_description].read(str[index+2, tlv_length])
          index += tlv_length + 2
        end
        #system capabilities
        if str[index,1] == "\x0e"
          tlv_known = true
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          self[:lldp_capabilty].read(str[index+2, 2])
          self[:lldp_enabled_capability].read(str[index+4, 2])
          index += tlv_length + 2
        end
        #management address
        if str[index,1] == "\x10"
          tlv_known = true
          tlv_length = str[index + 1,1].unpack("U*").join.to_i
          addr_length = str[index + 2, 1].unpack("U*").join.to_i
          self[:lldp_address_type].read(str[index + 3, 1])
          self[:lldp_address].read(str[index + 4,addr_length - 1])
          self[:lldp_interface_type].read(str[index + addr_length + 3, 1].unpack("U*").join.to_i)
          self[:lldp_interface].read(str[index + addr_length + 4, 4])
          oid_string_length = str[index + addr_length + 8, 1].unpack("U*").join.to_i
          if oid_string_length > 0
            self[:lldp_oid].read(str[index + addr_length + 9, oid_string_length])
          end
          index += tlv_length + 2
        end

        #if tlv type is unknown jump over it
        unless tlv_known
          tlv_length = str[index+1,1].unpack("U*").join.to_i
          index += tlv_length + 2
        end
      end
      self
    end

to_s() click to toggle source

Returns the object in string form.

    # File lib/packetfu/protos/lldp/header.rb, line 30
    def to_s
      self.to_a.map {|x| x.to_s}.join
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.