diff --git a/client.go b/client.go index b9e4840..3d745ca 100644 --- a/client.go +++ b/client.go @@ -287,7 +287,7 @@ func (c *Client) mainloop(ctx context.Context, params *lookupParams) { } if _, ok := entries[rr.Ptr]; !ok { entries[rr.Ptr] = newServiceEntry( - trimDot(strings.Replace(rr.Ptr, rr.Hdr.Name, "", -1)), + trimDot(strings.ReplaceAll(rr.Ptr, rr.Hdr.Name, "")), params.Service, params.Domain) } @@ -368,7 +368,7 @@ func (c *Client) mainloop(ctx context.Context, params *lookupParams) { // If this is an DNS-SD query do not throw PTR away. // It is expected to have only PTR for enumeration - if params.ServiceRecord.ServiceTypeName() != params.ServiceRecord.ServiceName() { + if params.ServiceTypeName() != params.ServiceName() { // Require at least one resolved IP address for ServiceEntry // TODO: wait some more time as chances are high both will arrive. if len(e.AddrIPv4) == 0 && len(e.AddrIPv6) == 0 { @@ -391,10 +391,16 @@ func (c *Client) mainloop(ctx context.Context, params *lookupParams) { // Shutdown client will close currently open connections and channel implicitly. func (c *Client) shutdown() { if c.ipv4conn != nil { - c.ipv4conn.Close() + err := c.ipv4conn.Close() + if err != nil { + log.Printf("[zeroconf] unable to cleanly close client IPv4 connection: %s", err.Error()) + } } if c.ipv6conn != nil { - c.ipv6conn.Close() + err := c.ipv6conn.Close() + if err != nil { + log.Printf("[zeroconf] unable to cleanly close client IPv6 connection: %s", err.Error()) + } } } diff --git a/conn_factory.go b/conn_factory.go index a706b60..8cabc23 100644 --- a/conn_factory.go +++ b/conn_factory.go @@ -37,7 +37,7 @@ func (f *defaultConnectionFactory) CreateIPv4Conn(ifaces []net.Interface) (api.P } } if failedJoins == len(ifaces) { - pkConn.Close() + _ = pkConn.Close() return nil, fmt.Errorf("udp4: failed to join any of these interfaces: %v", ifaces) } @@ -62,7 +62,7 @@ func (f *defaultConnectionFactory) CreateIPv6Conn(ifaces []net.Interface) (api.P } } if failedJoins == len(ifaces) { - pkConn.Close() + _ = pkConn.Close() return nil, fmt.Errorf("udp6: failed to join any of these interfaces: %v", ifaces) } diff --git a/interface_manager_test.go b/interface_manager_test.go index 217da9a..14f11c7 100644 --- a/interface_manager_test.go +++ b/interface_manager_test.go @@ -18,14 +18,6 @@ func mockInterface(index int, name string) net.Interface { } } -func mockInterfaces(specs ...struct{ idx int; name string }) []net.Interface { - result := make([]net.Interface, len(specs)) - for i, s := range specs { - result[i] = mockInterface(s.idx, s.name) - } - return result -} - // ============================================================================ // NewInterfaceManager Tests // ============================================================================ diff --git a/server.go b/server.go index bd74262..5e09726 100644 --- a/server.go +++ b/server.go @@ -291,10 +291,16 @@ func (s *Server) Shutdown() { close(s.shouldShutdown) if s.ipv4conn != nil { - s.ipv4conn.Close() + err := s.ipv4conn.Close() + if err != nil { + log.Printf("[zeroconf] unable to cleanly close server IPv4 connection: %s", err.Error()) + } } if s.ipv6conn != nil { - s.ipv6conn.Close() + err := s.ipv6conn.Close() + if err != nil { + log.Printf("[zeroconf] unable to cleanly close server IPv6 connection: %s", err.Error()) + } } // Wait for connection and routines to be closed @@ -637,7 +643,7 @@ func (s *Server) probe() { activeIfaces := mergeInterfaces(ipv4ActiveIfaces, ipv6ActiveIfaces) for _, intf := range activeIfaces { resp := new(dns.Msg) - resp.MsgHdr.Response = true + resp.Response = true // TODO: make response authoritative if we are the publisher resp.Compress = true resp.Answer = []dns.RR{} @@ -660,7 +666,7 @@ func (s *Server) probe() { // announceText sends a Text announcement with cache flush enabled func (s *Server) announceText() { resp := new(dns.Msg) - resp.MsgHdr.Response = true + resp.Response = true txt := &dns.TXT{ Hdr: dns.RR_Header{ @@ -678,7 +684,7 @@ func (s *Server) announceText() { func (s *Server) unregister() error { resp := new(dns.Msg) - resp.MsgHdr.Response = true + resp.Response = true resp.Answer = []dns.RR{} resp.Extra = []dns.RR{} s.composeLookupAnswers(resp, 0, 0, true)