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


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

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


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

def headers
  @headers
end

Instance Method Details

#==(other) ⇒ Boolean

equality if #to_s is equal

Returns:

  • (Boolean)

Since:

  • 3.2.0


69
70
71
# File 'lib/packetgen/unknown_packet.rb', line 69

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


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

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

#bodyTypes Also known as: to_s

Get packet body

Returns:

Since:

  • 3.2.0


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

def body
  @binary_str
end

#body=(str) ⇒ void

This method returns an undefined value.

Set packet body

Parameters:

  • str (String)

Since:

  • 3.2.0


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

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

#inspectString

Returns:

  • (String)

Since:

  • 3.2.0


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

def inspect
  # TODO
end

#is?(_protocol) ⇒ false

Unknown packet, so unknown protocol.

Returns:

  • (false)

Since:

  • 3.2.0


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

def is?(_protocol)
  false
end

#parse(binary_str, _first_header: nil) ⇒ self

Read binary string

Parameters:

  • binary_string (String)

Returns:

  • (self)

Since:

  • 3.2.0


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

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


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

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