From c6d75aa8ab07e215beb8c1315155e55d3ca830c6 Mon Sep 17 00:00:00 2001 From: Matthias Hochgatterer Date: Wed, 5 Nov 2014 12:32:13 +0100 Subject: [PATCH] Send response to multicast address if requested --- server.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/server.go b/server.go index 1b88c69..fb53272 100644 --- a/server.go +++ b/server.go @@ -267,18 +267,29 @@ func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dn // sendResponse is used to send a response packet func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error { - // TODO(reddaly): Respect the unicast argument, and allow sending responses - // over multicast. buf, err := resp.Pack() if err != nil { return err } addr := from.(*net.UDPAddr) - if addr.IP.To4() != nil { - _, err = s.ipv4List.WriteToUDP(buf, addr) - return err - } else { - _, err = s.ipv6List.WriteToUDP(buf, addr) - return err + ipv4 := addr.IP.To4() != nil + conn := s.ipv4List + + switch ipv4 { + case true: // ipv4 + if unicast == false { + addr = ipv4Addr + } + case false: // ipv6 + if unicast == false { + addr = ipv6Addr + } + + conn = s.ipv6List + default: + break } + + _, err = conn.WriteToUDP(buf, addr) + return err }