Class: PacketGen::Plugin::LLMNR

Inherits:
Header::DNS
  • Object
show all
Defined in:
lib/packetgen/plugin/llmnr.rb

Overview

Link-Local Multicast Name Resolution (LLMNR) header (RFC 4795).

Author:

  • Sylvain Daubert

Constant Summary collapse

UDP_PORT =

UDP port number

5355
MAC_IPV4_MCAST =

MAC address used with IPv4 multicast addresses

'01:00:5e:00:00:fc'

Instance Method Summary collapse

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



20
21
22
23
24
25
26
27
# File 'lib/packetgen/plugin/llmnr.rb', line 20

def added_to_packet(packet)
  packet.instance_eval <<-END_OF_DEFINITION
  def llmnrize(**kwargs)
    llmnr = headers.find { |hdr| hdr.is_a? PacketGen::Plugin::LLMNR }
    llmnr.llmnrize(**kwargs)
  end
  END_OF_DEFINITION
end

#llmnrize(dst: nil) ⇒ void

This method returns an undefined value.

Fixup IP header according to RFC 4795:

  • optionally set destination address,

  • set TTL to 1 if destination is a mcast address,

  • set MAC destination address to MAC_IPV4_MCAST if destination address is a mcast one.

This method may be called as:

# first way
pkt.llmnr.llmnrize
# second way
pkt.llmnrize

Parameters:

  • dst (String, nil) (defaults to: nil)

    destination address. May be a dotted IP address (by example ‘224.0.0.252’).



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/packetgen/plugin/llmnr.rb', line 41

def llmnrize(dst: nil)
  ip = ip_header(self)
  ip.dst = dst unless dst.nil?
  ip.ttl = 1 if ip[:dst].mcast?

  # rubocop:disable Lint/SuppressedException
  begin
    llh = ll_header(self)
    llh.dst = MAC_IPV4_MCAST if ip[:dst].mcast?
  rescue PacketGen::FormatError
  end
  # rubocop:enable Lint/SuppressedException
end