Class: PacketGen::Header::MLD
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::MLD
- Defined in:
- lib/packetgen/header/mld.rb
Overview
This class supports MLDv1 (RFC 2710).
From RFC 2710, a MLD 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum Response delay | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Multicast Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A MLD header consists of:
-
a #max_resp_delay field (Types::Int16 type),
-
a #reserved field (Types::Int16 type),
-
a #mcast_addr field (IPv6::Addr type),
-
and a #body (unused for MLDv1).
Create a MLD header
# standalone
mld = PacketGen::Header::MLD.new
# in a packet
pkt = PacketGen.gen('IPv6').add('ICMPv6').add('MLD')
# access to MLD header
pkt.mld # => PacketGen::Header::MLD
MLD attributes
pkt.icmpv6.type = 130 # ICMPv6 type 130 is MLD Multicast Listener Query
pkt.mld.max_resp_delay = 20
pkt.mld.group_addr = '::'
Direct Known Subclasses
Instance Attribute Summary collapse
- #body ⇒ String, Base
-
#max_resp_delay ⇒ Integer
(also: #max_resp_code)
16-bit MLD Max Response Delay.
-
#mcast_addr ⇒ IPv6::Addr
IPv6 Multicast address.
-
#reserved ⇒ Integer
16-bit Reserved field.
Instance Method Summary collapse
- #added_to_packet(packet) ⇒ Object private
-
#mldize ⇒ void
Fixup IP header according to RFC 2710: * set Hop limit 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
64 |
# File 'lib/packetgen/header/mld.rb', line 64 define_field :body, Types::String |
#max_resp_delay ⇒ Integer Also known as: max_resp_code
16-bit MLD Max Response Delay
51 |
# File 'lib/packetgen/header/mld.rb', line 51 define_field :max_resp_delay, Types::Int16 |
#mcast_addr ⇒ IPv6::Addr
IPv6 Multicast address
61 |
# File 'lib/packetgen/header/mld.rb', line 61 define_field :mcast_addr, IPv6::Addr, default: '::' |
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
69 70 71 72 |
# File 'lib/packetgen/header/mld.rb', line 69 def added_to_packet(packet) mld_idx = packet.headers.size packet.instance_eval "def mldize() @headers[#{mld_idx}].mldize; end" # def mldize() @headers[3].mldize; end end |
#mldize ⇒ void
This method returns an undefined value.
Fixup IP header according to RFC 2710:
-
set Hop limit to 1,
-
add Router Alert option,
-
recalculate checksum and length.
This method may be called as:
# first method
pkt.mld.mldize
# second method
pkt.mldize
84 85 86 87 88 89 90 91 |
# File 'lib/packetgen/header/mld.rb', line 84 def mldize ipv6 = ip_header(self) ipv6.hop = 1 ipv6.next = 0 packet.insert(ipv6, 'IPv6::HopByHop', next: ICMPv6::IP_PROTOCOL) packet.ipv6_hopbyhop. << { type: 'router_alert', value: [0].pack('n') } packet.calc end |