Class: PacketGen::Header::MDNS

Inherits:
DNS 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

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

Since:

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



47
48
49
50
51
52
53
54
# File 'lib/packetgen/header/mdns.rb', line 47

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

#mdnsizeObject

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

Since:

  • 2.6.0



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/packetgen/header/mdns.rb', line 30

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