Class: PacketGen::Header::MDNS

Inherits:
DNS
  • Object
show all
Defined in:
lib/packetgen/header/mdns.rb

Overview

Multicast DNS.

See DNS for header format.

Author:

  • Sylvain Daubert

Since:

  • 2.6.0

Constant Summary collapse

UDP_PORT =

Port number for mDNS over UDP

Since:

  • 2.6.0

5353

Constants inherited from DNS

DNS::OPCODES, DNS::RCODES, DNS::TCP_PORT

Instance Attribute Summary

Attributes inherited from DNS

#aa, #ad, #an, #ancount, #ar, #arcount, #cd, #id, #ns, #nscount, #opcode, #qd, #qdcount, #qr, #ra, #rcode, #rd, #tc, #u16

Instance Method Summary collapse

Methods inherited from DNS

#inspect, #query?, #response?

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 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

Add #mdnsize method to packet. This method calls #mdnsize.

Since:

  • 2.7.0 Set UDP sport according to bindings, only if sport is 0. Needed by new bind API.



54
55
56
57
58
59
60
61
# File 'lib/packetgen/header/mdns.rb', line 54

def added_to_packet(packet)
  mdns_idx = packet.headers.size
  packet.instance_eval "def mdnsize() @headers[#{mdns_idx}].mdnsize; end" # def mdnsize() @headers[4].mdnsize; end
  return unless packet.is?('UDP')
  return unless packet.udp.sport.zero?

  packet.udp.sport = UDP_PORT
end

#mdnsizevoid

This method returns an undefined value.

Fixup IP header according to RFC 6762:

  • set ethernet multicast address to 01:00:5E:00:00:FB (for IPv4) or 33:33:00:00:00:FB (for IPv6),

  • set IPv4 address to 224.0.0.251 or IPv6 address to ff02::fb.

This method may be called as:

# first way
pkt.mdns.mdnsize
# second way
pkt.

Examples:

pkt = PacketGen.gen('Eth').add('IP').add('UDP').add('MDNS')
pkt.mdnsize
pkt.eth.dst   #=> "01:00:5e:00:00:fb"
pkt.ip.dst    #=> "224.0.0.251"

Since:

  • 2.6.0



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/packetgen/header/mdns.rb', line 36

def mdnsize
  iph = ip_header(self)
  case iph
  when IP
    iph.dst = '224.0.0.251'
    dst_mac.from_human('01:00:5E:00:00:FB')
  when IPv6
    iph.dst = 'ff02::fb'
    dst_mac.from_human('33:33:00:00:00:FB')
  end
end