Class: PacketGen::Header::Eth
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::Eth
- Defined in:
- lib/packetgen/header/eth.rb
Overview
An Ethernet header consists of:
-
a destination MAC address (MacAddr),
-
a source MAC address (MacAddr),
-
a #ethertype (Types::Int16),
-
and a body (a Types::String or another Header class).
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"
Defined Under Namespace
Classes: MacAddr
Instance Attribute Summary collapse
- #body ⇒ Types::String, Header::Base
-
#dst ⇒ MacAddr
Destination MAC address.
-
#ethertype ⇒ Integer
16-bit integer to determine payload type.
-
#src ⇒ MacAddr
Source MAC address.
Instance Method Summary collapse
-
#reply! ⇒ self
Invert destination and source addresses.
-
#to_w(iface) ⇒ void
send Eth packet on wire.
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
#body ⇒ Types::String, Header::Base
96 |
# File 'lib/packetgen/header/eth.rb', line 96 define_field :body, Types::String |
#dst ⇒ MacAddr
Returns Destination MAC address.
87 |
# File 'lib/packetgen/header/eth.rb', line 87 define_field :dst, MacAddr, default: '00:00:00:00:00:00' |
Instance Method Details
#reply! ⇒ self
Invert destination and source addresses
108 109 110 111 |
# File 'lib/packetgen/header/eth.rb', line 108 def reply! self[:src], self[:dst] = self[:dst], self[:src] self end |