Class: PacketGen::Header::IP::LSRR

Inherits:
Option show all
Defined in:
lib/packetgen/header/ip/option.rb

Overview

Loose Source and Record Route IP option

Direct Known Subclasses

RR, SSRR

Constant Summary

Constants inherited from Option

Option::EOL_TYPE, Option::LSRR_TYPE, Option::NOP_TYPE, Option::RA_TYPE, Option::RR_TYPE, Option::SI_TYPE, Option::SSRR_TYPE

Instance Attribute Summary collapse

Attributes inherited from Option

#copied, #length, #option_class, #type

Instance Method Summary collapse

Methods inherited from Option

#initialize, #to_s, types

Methods inherited from Types::Fields

#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, #fields, #force_binary, inherited, #initialize, #inspect, #is_optional?, #is_present?, #optional_fields, #sz, #to_h, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Header::IP::Option

Instance Attribute Details

#dataTypes::Array<IP::Addr>

Array of IP addresses

Returns:



134
135
# File 'lib/packetgen/header/ip/option.rb', line 134

define_field :data, ArrayOfAddr,
builder: ->(h, t) { t.new(length_from: -> { h.length - 2 }) }

#pointerInteger

8-bit pointer on next address

Returns:

  • (Integer)


130
# File 'lib/packetgen/header/ip/option.rb', line 130

define_field :pointer, Types::Int8

Instance Method Details

#pointed_addrAddr

Get IP address pointer by #pointer

Returns:



152
153
154
# File 'lib/packetgen/header/ip/option.rb', line 152

def pointed_addr
  data[pointer / 4 - 1]
end

#read(str) ⇒ Fields

Populate object from a binary string

Parameters:

  • str (String)

Returns:

  • (Fields)

    self



140
141
142
143
144
145
146
147
148
# File 'lib/packetgen/header/ip/option.rb', line 140

def read(str)
  return self if str.nil?
  force_binary str
  self[:type].read str[0, 1]
  self[:length].read str[1, 1]
  self[:pointer].read str[2, 1]
  self[:data].read str[3, length - 3]
  self
end

#to_humanString

Get a human readable string

Returns:

  • (String)


158
159
160
161
# File 'lib/packetgen/header/ip/option.rb', line 158

def to_human
  str = self.class.to_s.sub(/.*::/, '')
  str << ':' << self[:data].to_human
end