Class: PacketGen::Header::ARP
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::ARP
- Defined in:
- lib/packetgen/header/arp.rb
Overview
An ARP header consists of:
-
a hardware type (#hrd or #htype) field (Types::Int16),
-
a hardware address length (#hln or #hlen) field (Types::Int8),
-
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
Instance Attribute Summary collapse
- #body ⇒ Types::String, Header::Base
-
#hln ⇒ Object
(also: #hlen)
8-bit hardware address length # @return [Integer].
-
#hrd ⇒ Object
(also: #htype)
16-bit hardware protocol type # @return [Integer].
-
#op ⇒ Object
(also: #opcode)
16-bit operation code # @return [Integer].
-
#pln ⇒ Object
(also: #plen)
8-bit internet address length # @return [Integer].
-
#pro ⇒ Object
(also: #ptype)
16-bit internet protocol type # @return [Integer].
-
#sha ⇒ Eth::MacAddr
(also: #src_mac)
source hardware address.
-
#spa ⇒ IP::Addr
(also: #src_ip)
source protocol address.
-
#tha ⇒ Eth::MacAddr
(also: #dst_mac)
target hardware address.
-
#tpa ⇒ IP::Addr
(also: #dst_ip)
target protocol address.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ARP
constructor
A new instance of ARP.
-
#reply! ⇒ self
Invert data to create a reply.
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.
84 85 86 87 |
# File 'lib/packetgen/header/arp.rb', line 84 def initialize(={}) () super end |
Instance Attribute Details
#body ⇒ Types::String, Header::Base
71 |
# File 'lib/packetgen/header/arp.rb', line 71 define_field :body, Types::String |
#hln ⇒ Object 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 |
#hrd ⇒ Object 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 |
#op ⇒ Object 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 } |
#pln ⇒ Object 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 |
#pro ⇒ Object 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 |
#sha ⇒ Eth::MacAddr Also known as: src_mac
source hardware address
56 |
# File 'lib/packetgen/header/arp.rb', line 56 define_field :sha, Eth::MacAddr |
#spa ⇒ IP::Addr Also known as: src_ip
source protocol address
60 |
# File 'lib/packetgen/header/arp.rb', line 60 define_field :spa, IP::Addr |
#tha ⇒ Eth::MacAddr Also known as: dst_mac
target hardware address
64 |
# File 'lib/packetgen/header/arp.rb', line 64 define_field :tha, Eth::MacAddr |
Instance Method Details
#reply! ⇒ self
Invert data to create a reply.
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 |