Class: PacketGen::Header::Eth
- Extended by:
- HeaderClassMethods
- Includes:
- HeaderMethods, StructFu
- Defined in:
- lib/packetgen/header/eth.rb
Overview
Ethernet header class
Defined Under Namespace
Classes: MacAddr
Constant Summary collapse
- PCAP_SNAPLEN =
0xffff- PCAP_PROMISC =
false- PCAP_TIMEOUT =
1
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#dst ⇒ String
Get MAC destination address.
-
#proto ⇒ Integer
Get protocol field.
-
#src ⇒ String
Get MAC source address.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Eth
constructor
A new instance of Eth.
-
#read(str) ⇒ self
Read a Eth header from a string.
-
#to_w(iface) ⇒ void
send Eth packet on wire.
Methods included from HeaderClassMethods
Methods included from HeaderMethods
#header_id, #ip_header, #packet, #packet=
Methods included from StructFu
#clone, #set_endianness, #sz, #to_s, #typecast
Methods inherited from Struct
Constructor Details
#initialize(options = {}) ⇒ Eth
Returns a new instance of Eth.
86 87 88 89 90 91 |
# File 'lib/packetgen/header/eth.rb', line 86 def initialize(={}) super MacAddr.new.parse([:dst] || '00:00:00:00:00:00'), MacAddr.new.parse([:src] || '00:00:00:00:00:00'), Int16.new([:proto] || 0), StructFu::String.new.read([:body]) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
6 7 8 |
# File 'lib/packetgen/header/eth.rb', line 6 def body @body end |
#dst ⇒ String
Get MAC destination address
6 7 8 |
# File 'lib/packetgen/header/eth.rb', line 6 def dst @dst end |
#proto ⇒ Integer
Get protocol field
6 7 8 |
# File 'lib/packetgen/header/eth.rb', line 6 def proto @proto end |
#src ⇒ String
Get MAC source address
6 7 8 |
# File 'lib/packetgen/header/eth.rb', line 6 def src @src end |
Instance Method Details
#read(str) ⇒ self
Read a Eth header from a string
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/packetgen/header/eth.rb', line 96 def read(str) return self if str.nil? raise ParseError, 'string too short for Eth' if str.size < self.sz force_binary str self[:dst].read str[0, 6] self[:src].read str[6, 6] self[:proto].read str[12, 2] self[:body].read str[14..-1] self end |
#to_w(iface) ⇒ void
This method returns an undefined value.
send Eth packet on wire.
149 150 151 152 |
# File 'lib/packetgen/header/eth.rb', line 149 def to_w(iface) pcap = PCAPRUB::Pcap.open_live(iface, PCAP_SNAPLEN, PCAP_PROMISC, PCAP_TIMEOUT) pcap.inject self.to_s end |