Class: PacketGen::UnknownPacket
- Inherits:
-
Object
- Object
- PacketGen::UnknownPacket
- 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.
Instance Attribute Summary collapse
-
#headers ⇒ Array
readonly
List of headers.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
equality if #to_s is equal.
-
#===(other) ⇒ Boolean
True only if
other
is an UnknownPacket and other == self. -
#body ⇒ Types
(also: #to_s)
Get packet body.
-
#body=(str) ⇒ void
Set packet body.
-
#initialize ⇒ UnknownPacket
constructor
A new instance of UnknownPacket.
- #inspect ⇒ String
-
#is?(_protocol) ⇒ false
Unknown packet, so unknown protocol.
-
#parse(binary_str, _first_header: nil) ⇒ self
Read binary string.
-
#to_f(filename) ⇒ Array
(also: #write)
Write packet to a PCapNG file on disk.
Constructor Details
#initialize ⇒ UnknownPacket
Returns a new instance of UnknownPacket.
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
#headers ⇒ Array (readonly)
List of headers. Always empty
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
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
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 |
#body ⇒ Types Also known as: to_s
Get packet body
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
42 43 44 |
# File 'lib/packetgen/unknown_packet.rb', line 42 def body=(str) @binary_str = PacketGen.force_binary(str) end |
#inspect ⇒ String
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.
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
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.
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 |