Class: PacketGen::Header::ARP

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

Overview

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

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

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

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

#bodyTypes::String, Header::Base



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

define_field :body, Types::String

#hlnObject Also known as: hlen

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



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

define_field :hln, Types::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_field :hrd, Types::Int16, default: 1

#opObject Also known as: opcode

16-bit operation code # @return [Integer]



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

define_field :op, Types::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_field :pln, Types::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_field :pro, Types::Int16, default: 0x800

#shaEth::MacAddr Also known as: src_mac

source hardware address

Returns:



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

define_field :sha, Eth::MacAddr

#spaIP::Addr Also known as: src_ip

source protocol address

Returns:



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

define_field :spa, IP::Addr

#thaEth::MacAddr Also known as: dst_mac

target hardware address

Returns:



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

define_field :tha, Eth::MacAddr

#tpaIP::Addr Also known as: dst_ip

target protocol address

Returns:



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

define_field :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