Class: PacketGen::Header::Eth

Inherits:
Base show all
Defined in:
lib/packetgen/header/eth.rb

Overview

An Ethernet header consists of:

Create a Ethernet header

# standalone
eth = PacketGen::Header::Eth.new
# in a packet
pkt = PacketGen.gen('Eth')
# access to Ethernet header
pkt.eth   # => PacketGen::Header::Eth

Ethernet attributes

eth.dst = "00:01:02:03:04:05"
eth.src        # => "00:01:01:01:01:01"
eth[:src]      # => PacketGen::Header::Eth::MacAddr
eth.ethertype  # => 16-bit Integer
eth.body = "This is a body"

Author:

  • Sylvain Daubert

Defined Under Namespace

Classes: MacAddr

Instance Attribute Summary collapse

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Base

bind_header, #header_id, inherited, #ip_header, known_headers, #parse?, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, #force_binary, inherited, #initialize, #inspect, #read, #sz, #to_h, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Types::Fields

Instance Attribute Details

#bodyTypes::String, Header::Base



91
# File 'lib/packetgen/header/eth.rb', line 91

define_field :body, Types::String

#dstMacAddr

Returns Destination MAC address.

Returns:

  • (MacAddr)

    Destination MAC address



82
# File 'lib/packetgen/header/eth.rb', line 82

define_field :dst, MacAddr, default: '00:00:00:00:00:00'

#ethertypeInteger

Returns 16-bit integer to determine payload type.

Returns:

  • (Integer)

    16-bit integer to determine payload type



88
# File 'lib/packetgen/header/eth.rb', line 88

define_field :ethertype, Types::Int16, default: 0

#srcMacAddr

Returns Source MAC address.

Returns:



85
# File 'lib/packetgen/header/eth.rb', line 85

define_field :src, MacAddr, default: '00:00:00:00:00:00'

Instance Method Details

#to_w(iface) ⇒ void

This method returns an undefined value.

send Eth packet on wire.

Parameters:

  • iface (String)

    interface name



96
97
98
99
# File 'lib/packetgen/header/eth.rb', line 96

def to_w(iface)
  pcap = PCAPRUB::Pcap.open_live(iface, PCAP_SNAPLEN, PCAP_PROMISC, PCAP_TIMEOUT)
  pcap.inject self.to_s
end