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


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

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

Instance Attribute Details

#bodyTypes::String, Header::Base


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

define_field :body, Types::String

#hlnObject Also known as: hlen

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


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

define_field :hln, Types::Int8, default: 6

#hrdObject Also known as: htype

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


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

define_field :hrd, Types::Int16, default: 1

#opObject Also known as: opcode

16-bit operation code # @return [Integer]


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

define_field :op, Types::Int16Enum, enum: { 'request' => 1, 'reply' => 2 }

#plnObject Also known as: plen

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


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

define_field :pln, Types::Int8, default: 4

#proObject Also known as: ptype

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


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

define_field :pro, Types::Int16, default: 0x800

#shaEth::MacAddr Also known as: src_mac

source hardware address

Returns:


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

define_field :sha, Eth::MacAddr

#spaIP::Addr Also known as: src_ip

source protocol address

Returns:


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

define_field :spa, IP::Addr

#thaEth::MacAddr Also known as: dst_mac

target hardware address

Returns:


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

define_field :tha, Eth::MacAddr

#tpaIP::Addr Also known as: dst_ip

target protocol address

Returns:


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

define_field :tpa, IP::Addr

Instance Method Details

#reply!self

Invert data to create a reply.

Returns:

  • (self)

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

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