// Pack the dns.Msg and write to available connections (multicast) func (c *client) sendQuery(msg *dns.Msg) error { buf, err := msg.Pack() if err != nil { return err } if c.ipv4conn != nil { c.ipv4conn.WriteTo(buf, ipv4Addr) } if c.ipv4conn != nil { c.ipv4conn.WriteTo(buf, ipv6Addr) } return nil }
// multicastResponse us used to send a multicast response packet func (c *server) multicastResponse(msg *dns.Msg) error { buf, err := msg.Pack() if err != nil { log.Println("Failed to pack message!") return err } if c.ipv4conn != nil { c.ipv4conn.WriteTo(buf, ipv4Addr) } if c.ipv4conn != nil { c.ipv4conn.WriteTo(buf, ipv6Addr) } return nil }
// sendResponse is used to send a unicast response packet func (s *server) sendResponse(resp *dns.Msg, from net.Addr) error { buf, err := resp.Pack() if err != nil { return err } addr := from.(*net.UDPAddr) if addr.IP.To4() != nil { _, err = s.ipv4conn.WriteToUDP(buf, addr) return err } else { _, err = s.ipv6conn.WriteToUDP(buf, addr) return err } }