Class: PacketGen::Header::IGMP
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- 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 (Types::Int8Enum type),
-
a #max_resp_time field (Types::Int8 type),
-
a #checksum field (Types::Int16 type),
-
a #group_addr field (PacketGen::Header::IP::Addr type),
-
and a #body (unused for IGMPv2).
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'
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
-
#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
-
#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
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
#body ⇒ String, Base
74 |
# File 'lib/packetgen/header/igmp.rb', line 74 define_field :body, Types::String |
#checksum ⇒ Integer
16-bit IGMP Checksum
67 |
# File 'lib/packetgen/header/igmp.rb', line 67 define_field :checksum, Types::Int16 |
#group_addr ⇒ IP::Addr
IP Group address
71 |
# File 'lib/packetgen/header/igmp.rb', line 71 define_field :group_addr, IP::Addr, default: '0.0.0.0' |
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
79 80 81 82 |
# File 'lib/packetgen/header/igmp.rb', line 79 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
92 93 94 95 |
# File 'lib/packetgen/header/igmp.rb', line 92 def calc_checksum sum = IP.sum16(self) self.checksum = IP.reduce_checksum(sum) end |
#human_type ⇒ String
Get human readbale type
86 87 88 |
# File 'lib/packetgen/header/igmp.rb', line 86 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
107 108 109 110 111 112 |
# File 'lib/packetgen/header/igmp.rb', line 107 def igmpize iph = ip_header(self) iph.ttl = 1 iph. << IP::RA.new packet.calc end |