Class: PacketGen::UnknownPacket

Inherits:
Object
  • Object
show all
Defined in:
lib/packetgen/unknown_packet.rb

Overview

Unknown packet, minimaly mimicking a Packet.

An unknown packet is generated when capturing packets, and a packet cannot be parsed.

Since:

  • 3.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnknownPacket

Returns a new instance of UnknownPacket.

Since:

  • 3.2.0



21
22
23
24
# File 'lib/packetgen/unknown_packet.rb', line 21

def initialize
  @headers = [].freeze
  @binary_str = PacketGen.force_binary('')
end

Instance Attribute Details

#headersArray (readonly)

List of headers. Always empty

Returns:

  • (Array)

Since:

  • 3.2.0



19
20
21
# File 'lib/packetgen/unknown_packet.rb', line 19

def headers
  @headers
end

Instance Method Details

#==(other) ⇒ Boolean

equality if #to_s is equal

Returns:

  • (Boolean)

Since:

  • 3.2.0



71
72
73
# File 'lib/packetgen/unknown_packet.rb', line 71

def ==(other)
  to_s == other.to_s
end

#===(other) ⇒ Boolean

True only if other is an PacketGen::UnknownPacket and other == self

Returns:

  • (Boolean)

Since:

  • 3.2.0



77
78
79
80
81
82
83
84
# File 'lib/packetgen/unknown_packet.rb', line 77

def ===(other)
  case other
  when UnknownPacket
    self == other
  else
    false
  end
end

#bodyTypes Also known as: to_s

Get packet body

Returns:

Since:

  • 3.2.0



34
35
36
# File 'lib/packetgen/unknown_packet.rb', line 34

def body
  @binary_str
end

#body=(str) ⇒ void

This method returns an undefined value.

Set packet body

Parameters:

  • str (String)

Since:

  • 3.2.0



42
43
44
# File 'lib/packetgen/unknown_packet.rb', line 42

def body=(str)
  @binary_str = PacketGen.force_binary(str)
end

#inspectString

Returns:

  • (String)

Since:

  • 3.2.0



64
65
66
67
# File 'lib/packetgen/unknown_packet.rb', line 64

def inspect
  str = Inspect.dashed_line(self.class)
  str << Inspect.inspect_body(body)
end

#is?(_protocol) ⇒ false

Unknown packet, so unknown protocol.

Returns:

  • (false)

Since:

  • 3.2.0



28
29
30
# File 'lib/packetgen/unknown_packet.rb', line 28

def is?(_protocol)
  false
end

#parse(binary_str, _first_header: nil) ⇒ self

Read binary string

Parameters:

  • binary_str (String)

Returns:

  • (self)

Since:

  • 3.2.0



58
59
60
61
# File 'lib/packetgen/unknown_packet.rb', line 58

def parse(binary_str, _first_header: nil)
  @binary_str = PacketGen.force_binary(binary_str)
  self
end

#to_f(filename) ⇒ Array Also known as: write

Write packet to a PCapNG file on disk.

Parameters:

  • filename (String)

Returns:

See Also:

  • File

Since:

  • 3.2.0



50
51
52
# File 'lib/packetgen/unknown_packet.rb', line 50

def to_f(filename)
  PcapNG::File.new.read_array([self]).to_f(filename)
end