diff --git a/client.go b/client.go index d2c278c..f5d2fe7 100644 --- a/client.go +++ b/client.go @@ -211,16 +211,12 @@ func newClient() (*client, error) { return nil, fmt.Errorf("failed to bind to any multicast udp port") } - if mconn4 == nil { - mconn4 = &net.UDPConn{} - } - if mconn6 == nil { - mconn6 = &net.UDPConn{} - } - p1 := ipv4.NewPacketConn(mconn4) p2 := ipv6.NewPacketConn(mconn6) + p1.SetMulticastLoopback(true) + p2.SetMulticastLoopback(true) + ifaces, err := net.Interfaces() if err != nil { return nil, err diff --git a/server.go b/server.go index 3eaa07d..dbbe276 100644 --- a/server.go +++ b/server.go @@ -358,7 +358,7 @@ func (s *Server) probe() { randomizer := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < 3; i++ { - if err := s.multicastResponse(q); err != nil { + if err := s.SendMulticast(q); err != nil { log.Println("[ERR] mdns: failed to send probe:", err.Error()) } time.Sleep(time.Duration(randomizer.Intn(250)) * time.Millisecond) @@ -384,7 +384,7 @@ func (s *Server) probe() { timeout := 1 * time.Second timer := time.NewTimer(timeout) for i := 0; i < 3; i++ { - if err := s.multicastResponse(resp); err != nil { + if err := s.SendMulticast(resp); err != nil { log.Println("[ERR] mdns: failed to send announcement:", err.Error()) } select { @@ -399,7 +399,7 @@ func (s *Server) probe() { } // multicastResponse us used to send a multicast response packet -func (s *Server) multicastResponse(msg *dns.Msg) error { +func (s *Server) SendMulticast(msg *dns.Msg) error { buf, err := msg.Pack() if err != nil { return err @@ -449,5 +449,5 @@ func (s *Server) unregister() error { resp.MsgHdr.Response = true resp.Answer = append(resp.Answer, s.config.Zone.Records(q.Question[0])...) - return s.multicastResponse(resp) + return s.SendMulticast(resp) }