Module: PacketGen::Header::HeaderMethods
- Defined in:
- lib/packetgen/header/header_methods.rb
Overview
Mixin for various headers
Instance Method Summary collapse
-
#header_id(header) ⇒ Integer
private
Get
headerid in packet headers array. -
#inspect ⇒ String
Common inspect method for headers.
-
#ip_header(header) ⇒ Header
private
Get IP or IPv6 previous header from
header. -
#packet ⇒ Packet
private
Get rference on packet which owns this header.
-
#packet=(packet) ⇒ void
private
Set reference of packet which owns this header.
-
#protocol_name ⇒ String
Return header protocol name.
Instance Method Details
#header_id(header) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get header id in packet headers array
33 34 35 36 37 38 39 40 |
# File 'lib/packetgen/header/header_methods.rb', line 33 def header_id(header) raise FormatError, "header of type #{header.class} not in a packet" if packet.nil? id = packet.headers.index(header) if id.nil? raise FormatError, "header of type #{header.class} not in packet #{packet}" end id end |
#inspect ⇒ String
Common inspect method for headers
63 64 65 66 67 68 69 70 |
# File 'lib/packetgen/header/header_methods.rb', line 63 def inspect str = Inspect.dashed_line(self.class, 2) to_h.each do |attr, value| next if attr == :body str << Inspect.inspect_attribute(attr, value, 2) end str end |
#ip_header(header) ⇒ Header
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get IP or IPv6 previous header from header
48 49 50 51 52 53 |
# File 'lib/packetgen/header/header_methods.rb', line 48 def ip_header(header) hid = header_id(header) iph = packet.headers[0...hid].reverse.find { |h| h.is_a? IP or h.is_a? IPv6 } raise FormatError, 'no IP or IPv6 header in packet' if iph.nil? iph end |
#packet ⇒ Packet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get rference on packet which owns this header
24 25 26 |
# File 'lib/packetgen/header/header_methods.rb', line 24 def packet @packet end |
#packet=(packet) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Set reference of packet which owns this header
17 18 19 |
# File 'lib/packetgen/header/header_methods.rb', line 17 def packet=(packet) @packet = packet end |
#protocol_name ⇒ String
Return header protocol name
57 58 59 |
# File 'lib/packetgen/header/header_methods.rb', line 57 def protocol_name self.class.to_s.sub(/.*::/, '') end |