Class: PacketGen::Header::ARP
- Extended by:
- HeaderClassMethods
- Includes:
- HeaderMethods, StructFu
- Defined in:
- lib/packetgen/header/arp.rb
Overview
An ARP header consists of:
-
a hardware type (#hrd or #htype) field (StructFu::Int16),
-
a hardware address length (#hln or #hlen) field (StructFu::Int8),
-
a source hardware address (#sha or #src_mac) field (Eth::MacAddr),
-
a source protocol address (#spa or #src_ip) field (IP::Addr),
-
a target hardware address (#tha or #dst_mac) field (
Eth::MacAddr), -
a target protocol address (#tpa or #dst_ip) field (
IP::Addr), -
and a #body.
Create a ARP header
# standalone
arp = PacketGen::Header::ARP.new
# in a packet
pkt = PacketGen.gen('Eth').add('ARP')
# access to ARP header
pkt.arp # => PacketGen::Header::ARP
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
- #hln ⇒ Integer (also: #hlen)
- #hrd ⇒ Integer (also: #htype)
- #op ⇒ Integer (also: #opcode)
- #pln ⇒ Integer (also: #plen)
- #pro ⇒ Integer (also: #ptype)
- #sha ⇒ String (also: #src_mac)
- #spa ⇒ String (also: #src_ip)
- #tha ⇒ String (also: #dst_mac)
- #tpa ⇒ String (also: #dst_ip)
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
bind_header, define_bit_fields_on, known_headers
Methods included from HeaderMethods
#header_id, #inspect, #ip_header, #packet, #packet=, #protocol_name
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.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/packetgen/header/arp.rb', line 47 def initialize(={}) super Int16.new([:hrd] || [:htype] || 1), Int16.new([:pro] || [:ptype] || 0x800), Int8.new([:hln] || [:hlen] || 6), Int8.new([:pln] || [:plen] || 4), Int16.new([:op] || [:opcode] || 1), Eth::MacAddr.new.from_human([:sha] || [:src_mac]), IP::Addr.new.from_human([:spa] || [:src_ip]), Eth::MacAddr.new.from_human([:tha] || [:dst_mac]), IP::Addr.new.from_human([:tpa] || [:dst_ip]), StructFu::String.new.read([:body]) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def body @body end |
#hln ⇒ Integer Also known as: hlen
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def hln @hln end |
#hrd ⇒ Integer Also known as: htype
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def hrd @hrd end |
#op ⇒ Integer Also known as: opcode
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def op @op end |
#pln ⇒ Integer Also known as: plen
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def pln @pln end |
#pro ⇒ Integer Also known as: ptype
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def pro @pro end |
#sha ⇒ String Also known as: src_mac
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def sha @sha end |
#spa ⇒ String Also known as: src_ip
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def spa @spa end |
#tha ⇒ String Also known as: dst_mac
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def tha @tha end |
#tpa ⇒ String Also known as: dst_ip
30 31 32 |
# File 'lib/packetgen/header/arp.rb', line 30 def tpa @tpa end |
Instance Method Details
#read(str) ⇒ self
Read a ARP header from a string
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/packetgen/header/arp.rb', line 63 def read(str) force_binary str raise ParseError, 'string too short for ARP' if str.size < self.sz self[:hrd].read str[0, 2] self[:pro].read str[2, 2] self[:hln].read str[4, 1] self[:pln].read str[5, 1] self[:op].read str[6, 2] self[:sha].read str[8, 6] self[:spa].read str[14, 4] self[:tha].read str[18, 6] self[:tpa].read str[24, 4] self[:body].read str[28..-1] end |