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.
Attributes inherited from Base
Instance Method Summary collapse
-
#reply! ⇒ self
Invert destination and source addresses.
-
#to_w(iface) ⇒ void
send Eth packet on wire.
Methods inherited from Base
#added_to_packet, bind, bind_header, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, known_headers, #ll_header, #method_name, #parse?, #protocol_name, protocol_name
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #initialize, #inspect, #is_optional?, #is_present?, #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
89 |
# File 'lib/packetgen/header/eth.rb', line 89 define_field :body, Types::String |
#dst ⇒ MacAddr
80 |
# File 'lib/packetgen/header/eth.rb', line 80 define_field :dst, MacAddr, default: '00:00:00:00:00:00' |
#ethertype ⇒ Integer
86 |
# File 'lib/packetgen/header/eth.rb', line 86 define_field :ethertype, Types::Int16, default: 0 |
#src ⇒ MacAddr
83 |
# File 'lib/packetgen/header/eth.rb', line 83 define_field :src, MacAddr, default: '00:00:00:00:00:00' |
Instance Method Details
#reply! ⇒ self
Invert destination and source addresses
103 104 105 106 |
# File 'lib/packetgen/header/eth.rb', line 103 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.
94 95 96 97 98 |
# File 'lib/packetgen/header/eth.rb', line 94 def to_w(iface) pcap = PCAPRUB::Pcap.open_live(iface, PCAP_SNAPLEN, PCAP_PROMISC, PCAP_TIMEOUT) pcap.inject self.to_s pcap.close end |