class PacketGen::Header::ARP
An ARP
header consists of:
-
a hardware type ({#hrd} or {#htype}) field ({Types::Int16}),
-
a protocol type ({#pro} or {#ptype}) field (
Int16
), -
a hardware address length ({#hln} or {#hlen}) field ({Types::Int8}),
-
a protocol address length ({#pln} or {#plen}) field (
Int8
), -
a {#opcode} (or {#op}) field (
Int16
), -
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
@author Sylvain Daubert
Public Class Methods
@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
# 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
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