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.
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
#headers ⇒ Array (readonly)
List of headers. Always empty
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
70 71 72 |
# File 'lib/packetgen/unknown_packet.rb', line 70 def ==(other) to_s == other.to_s end |
#===(other) ⇒ Boolean
True only if other
is an PacketGen::UnknownPacket and other == self
76 77 78 79 80 81 82 83 |
# File 'lib/packetgen/unknown_packet.rb', line 76 def ===(other) case other when UnknownPacket self == other else false end end |
#body ⇒ Types Also known as: to_s
Get packet body
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
41 42 43 |
# File 'lib/packetgen/unknown_packet.rb', line 41 def body=(str) @binary_str = PacketGen.force_binary(str) end |
#inspect ⇒ String
63 64 65 66 |
# File 'lib/packetgen/unknown_packet.rb', line 63 def inspect str = Inspect.dashed_line(self.class) str << Inspect.inspect_body(body) end |
#is?(_protocol) ⇒ false
Unknown packet, so unknown protocol.
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
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.
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 |