Class: PacketFu::LLDPPacket

Inherits:
Packet
  • Object
show all
Includes:
EthHeaderMixin, LLDPHeaderMixin
Defined in:
lib/packetfu/protos/lldp.rb

Constant Summary collapse

MAGIC =
Regexp.new("^\x01\x80\xc2\x00\x00[\x0e\x03\x00]".force_encoding('ASCII-8BIT'), Regexp::NOENCODING)

Instance Attribute Summary collapse

Attributes inherited from Packet

#flavor, #headers, #iface, #inspect_style

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LLDPHeaderMixin

#lldp_address, #lldp_address=, #lldp_address_type, #lldp_address_type=, #lldp_capabilty, #lldp_capabilty=, #lldp_chassis_id, #lldp_chassis_id=, #lldp_chassis_id_type, #lldp_chassis_id_type=, #lldp_enabled_capability, #lldp_enabled_capability=, #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=, #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=

Methods included from EthHeaderMixin

#eth_daddr, #eth_daddr=, #eth_dst, #eth_dst=, #eth_dst_readable, #eth_proto, #eth_proto=, #eth_proto_readable, #eth_saddr, #eth_saddr=, #eth_src, #eth_src=, #eth_src_readable

Methods inherited from Packet

#==, #clone, #dissect, #dissection_table, force_binary, #handle_is_identity, #hexify, inherited, #inspect, #inspect_hex, #kind_of?, layer, #layer, #layer_symbol, layer_symbol, #method_missing, #orig_kind_of?, parse, #payload, #payload=, #peek, #proto, #read, #respond_to?, #size, #to_f, #to_pcap, #to_s, #to_w, #write

Constructor Details

#initialize(args = {}) ⇒ LLDPPacket

Returns a new instance of LLDPPacket.



25
26
27
28
29
30
31
32
33
# File 'lib/packetfu/protos/lldp.rb', line 25

def initialize(args={})
  @eth_header = EthHeader.new(args).read(args[:eth])
  @lldp_header = LLDPHeader.new(args).read(args[:lldp])
  @eth_header.eth_proto = "\x88\xCC"
  @eth_header.body=@lldp_header

  @headers = [@eth_header, @lldp_header]
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PacketFu::Packet

Instance Attribute Details

#eth_headerObject

Returns the value of attribute eth_header.



15
16
17
# File 'lib/packetfu/protos/lldp.rb', line 15

def eth_header
  @eth_header
end

#lldp_headerObject

Returns the value of attribute lldp_header.



15
16
17
# File 'lib/packetfu/protos/lldp.rb', line 15

def lldp_header
  @lldp_header
end

Class Method Details

.can_parse?(str) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/packetfu/protos/lldp.rb', line 17

def self.can_parse?(str)
  return false unless EthPacket.can_parse? str
  return false unless str.size >= 6
  return false unless str[12,2] == "\x88\xcc"
  return false unless str =~ MAGIC
  true
end

Instance Method Details

#peek_formatObject

Generates summary data for LLDP packets.



36
37
38
39
40
41
42
43
44
# File 'lib/packetfu/protos/lldp.rb', line 36

def peek_format
  peek_data = ["A  "]
  peek_data << "%-5d" % self.to_s.size
  peek_data << lldp_saddr_mac
  peek_data << "(#{lldp_saddr_mac})"
  peek_data << "->"
  peek_data << "01:80:c2:00:00:0e"
  peek_data.join
end

#recalc(args = {}) ⇒ Object

While there are lengths in LLDPPackets, there’s not much to do with them.



48
49
50
# File 'lib/packetfu/protos/lldp.rb', line 48

def recalc(args={})
  @headers[0].inspect
end