Class: PacketGen::Header::IGMP
- 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:
-
a #type field (
BinStruct::Int8Enum
type), -
a #max_resp_time field (
BinStruct::Int8
type), -
a #checksum field (
BinStruct::Int16
type), -
a #group_addr field (PacketGen::Header::IP::Addr type),
-
and a #body (unused for IGMPv2).
After adding a IGMP header to a packet, you have to call #igmpize to ensure resulting packet conforms to RFC 2236.
Direct Known Subclasses
Constant Summary collapse
- IP_PROTOCOL =
IGMP internet protocol number
2
- TYPES =
Known types
{ 'MembershipQuery' => 0x11, 'MembershipReportv1' => 0x12, 'MembershipReportv2' => 0x16, 'LeaveGroup' => 0x17, }.freeze
Instance Attribute Summary collapse
-
#body ⇒ String, Base
IGMP body (not used in IGMPv2).
-
#checksum ⇒ Integer
16-bit IGMP Checksum.
-
#group_addr ⇒ IP::Addr
IP Group address.
-
#max_resp_time ⇒ Integer
8-bit IGMP Max Response Time.
-
#type ⇒ Integer
8-bit IGMP Type.
Instance Method Summary collapse
-
#added_to_packet(packet) ⇒ Object
private
Define
#igmpize
method ontopacket
. -
#calc_checksum ⇒ Integer
Compute checksum and set
checksum
field. -
#human_type ⇒ String
Get human readbale type.
-
#igmpize ⇒ void
Fixup IP header according to RFC 2236: * set TTL to 1, * add Router Alert option, * recalculate checksum and length.
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, #to_s
Constructor Details
This class inherits a constructor from PacketGen::Header::Base
Instance Attribute Details
#body ⇒ String, Base
IGMP body (not used in IGMPv2)
79 |
# File 'lib/packetgen/header/igmp.rb', line 79 define_attr :body, BinStruct::String |
#checksum ⇒ Integer
16-bit IGMP Checksum
71 |
# File 'lib/packetgen/header/igmp.rb', line 71 define_attr :checksum, BinStruct::Int16 |
#group_addr ⇒ IP::Addr
IP Group address
75 |
# File 'lib/packetgen/header/igmp.rb', line 75 define_attr :group_addr, IP::Addr, default: '0.0.0.0' |
#max_resp_time ⇒ Integer
8-bit IGMP Max Response Time
67 |
# File 'lib/packetgen/header/igmp.rb', line 67 define_attr :max_resp_time, BinStruct::Int8 |
#type ⇒ Integer
8-bit IGMP Type
63 |
# File 'lib/packetgen/header/igmp.rb', line 63 define_attr :type, BinStruct::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.
This method is used internally by PacketGen and should not be directly called
Define #igmpize
method onto packet
. This method calls #igmpize.
85 86 87 88 |
# File 'lib/packetgen/header/igmp.rb', line 85 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_checksum ⇒ Integer
Compute checksum and set checksum
field
98 99 100 101 |
# File 'lib/packetgen/header/igmp.rb', line 98 def calc_checksum sum = IP.sum16(self) self.checksum = IP.reduce_checksum(sum) end |
#human_type ⇒ String
Get human readbale type
92 93 94 |
# File 'lib/packetgen/header/igmp.rb', line 92 def human_type self[:type].to_human end |
#igmpize ⇒ void
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
118 119 120 121 122 123 |
# File 'lib/packetgen/header/igmp.rb', line 118 def igmpize iph = ip_header(self) iph.ttl = 1 iph. << IP::RA.new packet.calc end |