class PacketGen::Header::ARP

An ARP header consists of:

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

@author Sylvain Daubert

Public Class Methods

new(options={}) click to toggle source

@param [Hash] options @option options [Integer] :hrd network protocol type (default: 1) @option options [Integer] :pro internet protocol type (default: 0x800) @option options [Integer] :hln length of hardware addresses (default: 6) @option options [Integer] :pln length of internet addresses (default: 4) @option options [Integer] :op operation performing by sender (default: 1).

known values are +request+ (1) and +reply+ (2)

@option options [String] :sha sender hardware address @option options [String] :spa sender internet address @option options [String] :tha target hardware address @option options [String] :tpa targetr internet address

Calls superclass method
# File lib/packetgen/header/arp.rb, line 83
def initialize(options={})
  options[:hrd] ||= options[:htype]
  options[:pro] ||= options[:ptype]
  options[:hln] ||= options[:hlen]
  options[:pln] ||= options[:plen]
  options[:op]  ||= options[:opcode]
  options[:sha] ||= options[:src_mac]
  options[:spa] ||= options[:src_ip]
  options[:tha] ||= options[:dst_mac]
  options[:tpa] ||= options[:dst_ip]
  super
end

Public Instance Methods

reply!() click to toggle source

Invert data to create a reply. @return [self]

# File lib/packetgen/header/arp.rb, line 117
def reply!
  case opcode.to_i
  when 1
    self.opcode = 2
    self.spa, self.tpa = self.tpa, self.spa
    self.sha, self.tha = self.tha, self.sha
  when 2
    self.opcode = 1
    self.spa, self.tpa = self.tpa, self.spa
    self.sha = self.tha
    self[:tha].from_human('00:00:00:00:00:00')
  end
  self
end