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

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#bodyTypes::String, Header::Base



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

define_field :body, Types::String

#dstMacAddr

Returns Destination MAC address.

Returns:

  • (MacAddr)

    Destination MAC address



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

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



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

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

#srcMacAddr

Returns Source MAC address.

Returns:



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

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

Instance Method Details

#reply!self

Invert destination and source addresses

Returns:

  • (self)

Since:

  • 2.7.0



107
108
109
110
# File 'lib/packetgen/header/eth.rb', line 107

def reply!
  self[:src], self[:dst] = self[:dst], self[:src]
  self
end

#to_w(iface) ⇒ void

This method returns an undefined value.

send Eth packet on wire.

Parameters:

  • iface (String)

    interface name



100
101
102
# File 'lib/packetgen/header/eth.rb', line 100

def to_w(iface)
  Inject.inject(iface: iface, data: self)
end