Class: PacketGen::Header::ARP
- Extended by:
- HeaderClassMethods
- Includes:
- HeaderMethods, StructFu
- Defined in:
- lib/packetgen/header/arp.rb
Overview
ARP header class
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
- #dst_ip ⇒ String
- #dst_mac ⇒ String
- #hw_len ⇒ Integer
- #hw_type ⇒ Integer
- #opcode ⇒ Integer
- #proto ⇒ Integer
- #proto_len ⇒ Integer
- #src_ip ⇒ String
- #src_mac ⇒ String
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ARP
constructor
A new instance of ARP.
-
#read(str) ⇒ self
Read a ARP header from a string.
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 = {}) ⇒ ARP
Returns a new instance of ARP.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/packetgen/header/arp.rb', line 23 def initialize(={}) super Int16.new([:hw_type] || 1), Int16.new([:proto] || 0x800), Int8.new([:hw_len] || 6), Int8.new([:proto_len] || 4), Int16.new([:opcode] || 1), Eth::MacAddr.new.parse([:src_mac]), IP::Addr.new.parse([:src_ip]), Eth::MacAddr.new.parse([:dst_mac]), IP::Addr.new.parse([:dst_ip]), StructFu::String.new.read([:body]) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def body @body end |
#hw_len ⇒ Integer
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def hw_len @hw_len end |
#hw_type ⇒ Integer
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def hw_type @hw_type end |
#opcode ⇒ Integer
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def opcode @opcode end |
#proto ⇒ Integer
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def proto @proto end |
#proto_len ⇒ Integer
6 7 8 |
# File 'lib/packetgen/header/arp.rb', line 6 def proto_len @proto_len end |
Instance Method Details
#read(str) ⇒ self
Read a ARP header from a string
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/packetgen/header/arp.rb', line 39 def read(str) force_binary str raise ParseError, 'string too short for ARP' if str.size < self.sz self[:hw_type].read str[0, 2] self[:proto].read str[2, 2] self[:hw_len].read str[4, 1] self[:proto_len].read str[5, 1] self[:opcode].read str[6, 2] self[:src_mac].read str[8, 6] self[:src_ip].read str[14, 4] self[:dst_mac].read str[18, 6] self[:dst_ip].read str[24, 4] self[:body].read str[28..-1] end |