Class: PacketGen::Header::IGMP

Inherits:
Base show all
Defined in:
lib/packetgen/header/igmp.rb

Overview

This class supports IGMPv2 (RFC 2236).

From RFC 2236, a IGMP header has the following format:

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      Type     | Max Resp Time |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Group Address                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

A IGMP header consists of:

Create a IGMP header

# standalone
igmp = PacketGen::Header::IGMP.new
# in a packet
pkt = PacketGen.gen('IP').add('IGMP')
# access to IGMP header
pkt.igmp    # => PacketGen::Header::IGMP

IGMP attributes

icmp.type = 'MembershipQuery'   # or 0x11
icmp.max_resp_time = 20
icmp.checksum = 0x248a
icmp.group_addr = '224.0.0.1'

Author:

  • Sylvain Daubert

Since:

  • 2.4.0

Direct Known Subclasses

IGMPv3

Constant Summary collapse

IP_PROTOCOL =

IGMP internet protocol number

Since:

  • 2.4.0

2
TYPES =

Known types

Since:

  • 2.4.0

{
  'MembershipQuery' => 0x11,
  'MembershipReportv1' => 0x12,
  'MembershipReportv2' => 0x16,
  'LeaveGroup' => 0x17,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#bodyString, Base

Returns:


73
# File 'lib/packetgen/header/igmp.rb', line 73

define_field :body, Types::String

#checksumInteger

16-bit IGMP Checksum

Returns:

  • (Integer)

66
# File 'lib/packetgen/header/igmp.rb', line 66

define_field :checksum, Types::Int16

#group_addrIP::Addr

IP Group address

Returns:


70
# File 'lib/packetgen/header/igmp.rb', line 70

define_field :group_addr, IP::Addr, default: '0.0.0.0'

#max_resp_timeInteger

8-bit IGMP Max Response Time

Returns:

  • (Integer)

62
# File 'lib/packetgen/header/igmp.rb', line 62

define_field :max_resp_time, Types::Int8

#typeInteger

8-bit IGMP Type

Returns:

  • (Integer)

58
# File 'lib/packetgen/header/igmp.rb', line 58

define_field :type, Types::Int8Enum, enum: TYPES

Instance Method Details

#added_to_packet(packet) ⇒ Object

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.

Note:

This method is used internally by PacketGen and should not be directly called

Since:

  • 2.4.0


78
79
80
81
# File 'lib/packetgen/header/igmp.rb', line 78

def added_to_packet(packet)
  igmp_idx = packet.headers.size
  packet.instance_eval "def igmpize() @headers[#{igmp_idx}].igmpize; end" # def igmpize() @headers[2].igmpize; end
end

#calc_checksumInteger

Compute checksum and set checksum field

Returns:

  • (Integer)

Since:

  • 2.4.0


91
92
93
94
# File 'lib/packetgen/header/igmp.rb', line 91

def calc_checksum
  sum = IP.sum16(self)
  self.checksum = IP.reduce_checksum(sum)
end

#human_typeString

Get human readbale type

Returns:

  • (String)

Since:

  • 2.4.0


85
86
87
# File 'lib/packetgen/header/igmp.rb', line 85

def human_type
  self[:type].to_human
end

#igmpizevoid

This method returns an undefined value.

Fixup IP header according to RFC 2236:

  • set TTL to 1,

  • add Router Alert option,

  • recalculate checksum and length.

This method may be called as:

# first method
pkt.igmp.igmpize
# second method
pkt.igmpize

Since:

  • 2.4.0


106
107
108
109
110
111
# File 'lib/packetgen/header/igmp.rb', line 106

def igmpize
  iph = ip_header(self)
  iph.ttl = 1
  iph.options << IP::RA.new
  packet.calc
end