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



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

define_field :body, Types::String

#dstMacAddr

Returns Destination MAC address.

Returns:

  • (MacAddr)

    Destination MAC address



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

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



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

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

#srcMacAddr

Returns Source MAC address.

Returns:



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

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



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

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



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

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