Merge pull request #24 from brutella/multicast-response

Send response to multicast address if requested
This commit is contained in:
Armon Dadgar 2014-11-06 16:31:26 -08:00
commit a26b69e7bc

View File

@ -267,18 +267,29 @@ func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dn
// sendResponse is used to send a response packet // sendResponse is used to send a response packet
func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error { 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() buf, err := resp.Pack()
if err != nil { if err != nil {
return err return err
} }
addr := from.(*net.UDPAddr) addr := from.(*net.UDPAddr)
if addr.IP.To4() != nil { ipv4 := addr.IP.To4() != nil
_, err = s.ipv4List.WriteToUDP(buf, addr) conn := s.ipv4List
return err
} else { switch ipv4 {
_, err = s.ipv6List.WriteToUDP(buf, addr) 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 return err
} }
}