class PacketGen::Header::IGMP

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

Constants

IP_PROTOCOL

IGMP internet protocol number

TYPES

Known types

Public Instance Methods

added_to_packet(packet) click to toggle source

@api private @note This method is used internally by PacketGen and should not be

directly called
# 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"
end
calc_checksum() click to toggle source

Compute checksum and set checksum field @return [Integer]

# File lib/packetgen/header/igmp.rb, line 91
def calc_checksum
  sum = IP.sum16(self)
  self.checksum = IP.reduce_checksum(sum)
end
human_type() click to toggle source

Get human readbale type @return [String]

# File lib/packetgen/header/igmp.rb, line 85
def human_type
  self[:type].to_human
end
igmpize() click to toggle source

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

@return [void]

# 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