Module: PacketGen::Header::HeaderMethods

Included in:
ARP, Eth, ICMP, IP, IPv6, UDP
Defined in:
lib/packetgen/header/header_methods.rb

Overview

Mixin for various headers

Author:

  • Sylvain Daubert

Instance Method Summary collapse

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

Parameters:

Returns:

  • (Integer)

Raises:

  • FormatError header not in a packet



28
29
30
31
32
33
34
35
# File 'lib/packetgen/header/header_methods.rb', line 28

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

#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

Parameters:

Returns:

Raises:

  • FormatError no IP or IPv6 header previous header in packet

  • FormatError header not in a packet



43
44
45
46
47
48
# File 'lib/packetgen/header/header_methods.rb', line 43

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

#packetPacket

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

Returns:



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

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

Parameters:



12
13
14
# File 'lib/packetgen/header/header_methods.rb', line 12

def packet=(packet)
  @packet = packet
end