Class: PacketGen::Header::ARP

Inherits:
Base
  • Object
show all
Defined in:
lib/packetgen/header/arp.rb

Overview

An ARP header consists of:

Examples:

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.protocol_name   # => "ARP"

Author:

  • Sylvain Daubert

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s

Constructor Details

#initialize(options = {}) ⇒ ARP

Returns a new instance of ARP.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :hrd (Integer)

    network protocol type (default: 1)

  • :pro (Integer)

    internet protocol type (default: 0x800)

  • :hln (Integer)

    length of hardware addresses (default: 6)

  • :pln (Integer)

    length of internet addresses (default: 4)

  • :op (Integer)

    operation performing by sender (default: 1). known values are request (1) and reply (2)

  • :sha (String)

    sender hardware address

  • :spa (String)

    sender internet address

  • :tha (String)

    target hardware address

  • :tpa (String)

    targetr internet address


84
85
86
87
# File 'lib/packetgen/header/arp.rb', line 84

def initialize(options={})
  handle_options(options)
  super
end

Instance Attribute Details

#bodyBinStruct::String, Header::Base

Returns:


71
# File 'lib/packetgen/header/arp.rb', line 71

define_attr :body, BinStruct::String

#hlnObject Also known as: hlen

8-bit hardware address length # @return [Integer]


44
# File 'lib/packetgen/header/arp.rb', line 44

define_attr :hln, BinStruct::Int8, default: 6

#hrdObject Also known as: htype

16-bit hardware protocol type # @return [Integer]


36
# File 'lib/packetgen/header/arp.rb', line 36

define_attr :hrd, BinStruct::Int16, default: 1

#opObject Also known as: opcode

16-bit operation code # @return [Integer]


52
# File 'lib/packetgen/header/arp.rb', line 52

define_attr :op, BinStruct::Int16Enum, enum: { 'request' => 1, 'reply' => 2 }

#plnObject Also known as: plen

8-bit internet address length # @return [Integer]


48
# File 'lib/packetgen/header/arp.rb', line 48

define_attr :pln, BinStruct::Int8, default: 4

#proObject Also known as: ptype

16-bit internet protocol type # @return [Integer]


40
# File 'lib/packetgen/header/arp.rb', line 40

define_attr :pro, BinStruct::Int16, default: 0x800

#shaEth::MacAddr Also known as: src_mac

source hardware address

Returns:


56
# File 'lib/packetgen/header/arp.rb', line 56

define_attr :sha, Eth::MacAddr

#spaIP::Addr Also known as: src_ip

source protocol address

Returns:


60
# File 'lib/packetgen/header/arp.rb', line 60

define_attr :spa, IP::Addr

#thaEth::MacAddr Also known as: dst_mac

target hardware address

Returns:


64
# File 'lib/packetgen/header/arp.rb', line 64

define_attr :tha, Eth::MacAddr

#tpaIP::Addr Also known as: dst_ip

target protocol address

Returns:


68
# File 'lib/packetgen/header/arp.rb', line 68

define_attr :tpa, IP::Addr

Instance Method Details

#reply!self

Invert data to create a reply.

Returns:

  • (self)

110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/packetgen/header/arp.rb', line 110

def reply!
  case opcode.to_i
  when 1
    self.opcode = 2
    invert_addresses
  when 2
    self.opcode = 1
    invert_addresses
    self[:tha].from_human('00:00:00:00:00:00')
  end
  self
end