Method: Net::DNS::MDNS::Responder#send

Defined in:
lib/net/dns/mdns.rb

#send(msg, qid = nil, qaddr = nil, qport = nil) ⇒ Object



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/net/dns/mdns.rb', line 743

def send(msg, qid = nil, qaddr = nil, qport = nil)
  begin
    msg.answer.each do |an|
      debug( "-> an #{an[0]} (#{an[1]}) #{an[2].to_s} #{an[3].inspect}" )
    end
    msg.additional.each do |an|
      debug( "-> ad #{an[0]} (#{an[1]}) #{an[2].to_s} #{an[3].inspect}" )
    end
    # Unicast response directly to questioner if source port is not 5353.
    if qport && qport != Port
      debug( "unicast for qid #{qid} to #{qaddr}:#{qport}" )
      msg.id = qid
      @sock.send(msg.encode, 0, qaddr, qport)
    end
    # ID is always zero for mcast, don't repeat questions for mcast
    msg.id = 0
    msg.question.clear unless msg.query?
    @sock.send(msg.encode, 0, Addr, Port)
  rescue
    error( "send msg failed: #{$!}" )
    raise
  end
end