Class: PacketGen::Header::Eth

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

Overview

An Ethernet header consists of:

Examples:

Create a Ethernet header

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

Access to Ethernet attributes

eth = PacketGen::Header::Eth.new(src: '00:01:01:01:01:01', ethertype: 0x1234)
# Set destination MAC address
eth.dst = "00:01:02:03:04:05"
# Access source MAC address, human-redable
eth.src            # => "00:01:01:01:01:01"
# Access to MacAddr object
eth[:src].class    # => PacketGen::Header::Eth::MacAddr
eth.ethertype      # => 0x1234
# Set Ethernet body
eth.body = "This is a body"

Author:

  • Sylvain Daubert

  • LemonTree55

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, #to_s

Constructor Details

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

Instance Attribute Details

#bodyBinStruct::String, Headerable

Returns:



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

define_attr :body, BinStruct::String

#dst::String

Destination MAC address

Returns:

  • (::String)


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

define_attr :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



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

define_attr :ethertype, BinStruct::Int16, default: 0

#src::String

Source MAC address

Returns:

  • (::String)


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

define_attr :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



122
123
124
125
# File 'lib/packetgen/header/eth.rb', line 122

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



115
116
117
# File 'lib/packetgen/header/eth.rb', line 115

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