diff --git a/pkg/mdns/client.go b/pkg/mdns/client.go index a9ea0f1a..890556ec 100644 --- a/pkg/mdns/client.go +++ b/pkg/mdns/client.go @@ -185,13 +185,21 @@ func (b *Browser) ListenMulticastUDP() error { for _, ip4 := range ip4s { conn, err := lc1.ListenPacket(ctx, "udp4", ip4.String()+":5353") // same port important if err != nil { + if strings.Contains(err.Error(), "address already in use") { + continue + } continue } b.Sends = append(b.Sends, conn) } if b.Sends == nil { - return errors.New("no interfaces for listen") + // Fall back to the system's default interface if no specific interfaces are available + conn, err := net.ListenMulticastUDP("udp4", nil, MulticastAddr) + if err != nil { + return errors.New("no interfaces for listen and fallback failed: " + err.Error()) + } + b.Sends = append(b.Sends, conn) } // 3. Create receiver @@ -388,6 +396,9 @@ loop: switch v := addr.(type) { case *net.IPNet: if ip := v.IP.To4(); ip != nil { + if ip.IsLinkLocalUnicast() { + continue + } ips = append(ips, ip) continue loop } @@ -395,5 +406,9 @@ loop: } } + if len(ips) == 0 { + return nil, errors.New("no IPv4 addresses found") + } + return ips, nil }