Class: PacketFu::EthPacket

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

Overview

EthPacket is used to construct Ethernet packets. They contain an Ethernet header, and that’s about it.

Example

require 'packetfu'
eth_pkt = PacketFu::EthPacket.new
eth_pkt.eth_saddr="00:1c:23:44:55:66"
eth_pkt.eth_daddr="00:1c:24:aa:bb:cc"

eth_pkt.to_w('eth0') # Inject on the wire. (require root)

Instance Attribute Summary collapse

Attributes inherited from Packet

#flavor, #headers, #iface, #inspect_style

Class Method Summary collapse

Instance Method Summary collapse

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, #peek_format, #proto, #read, #respond_to?, #size, #to_f, #to_pcap, #to_s, #to_w, #write

Constructor Details

#initialize(args = {}) ⇒ EthPacket

Returns a new instance of EthPacket.



38
39
40
41
42
# File 'lib/packetfu/protos/eth.rb', line 38

def initialize(args={})
  @eth_header = EthHeader.new(args).read(args[:eth])
  @headers = [@eth_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.



21
22
23
# File 'lib/packetfu/protos/eth.rb', line 21

def eth_header
  @eth_header
end

Class Method Details

.can_parse?(str) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/packetfu/protos/eth.rb', line 23

def self.can_parse?(str)
  # XXX Temporary fix. Need to extend the EthHeader class to handle more.
  valid_eth_types = [0x0800, 0x0806, 0x86dd, 0x88cc]
  return false unless str.size >= 14
  type = str[12,2].unpack("n").first rescue nil
  return false unless valid_eth_types.include? type
  true
end

Instance Method Details

#recalc(args = {}) ⇒ Object

Does nothing, really, since there’s no length or checksum to calculate for a straight Ethernet packet.



34
35
36
# File 'lib/packetfu/protos/eth.rb', line 34

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