diff --git a/server.go b/server.go index 4f2799d..55988c4 100644 --- a/server.go +++ b/server.go @@ -267,6 +267,8 @@ 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 @@ -274,27 +276,11 @@ func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error // Determine the socket to send from addr := from.(*net.UDPAddr) - var conn *net.UDPConn if addr.IP.To4() != nil { - conn = s.ipv4List + _, err = s.ipv4List.WriteToUDP(buf, addr) + return err } else { - conn = s.ipv6List + _, err = s.ipv6List.WriteToUDP(buf, addr) + return err } - - // Determine the address to send to if not unicast - if !unicast { - if addr.IP.To4() != nil { - addr = ipv4Addr - } else { - addr = ipv6Addr - } - } - - // Guard against a missing connection or address - if conn == nil || addr == nil { - return fmt.Errorf("Unable to respond, missing connection (%v) or address (%v)", - conn, addr) - } - _, err = conn.WriteToUDP(buf, addr) - return err }