diff --git a/net/connUDP_internal_test.go b/net/connUDP_internal_test.go index 5e1cf901..6d7b160d 100644 --- a/net/connUDP_internal_test.go +++ b/net/connUDP_internal_test.go @@ -284,21 +284,29 @@ func TestControlMessageString(t *testing.T) { func getIfaceAddr(t *testing.T, iface net.Interface, ipv4 bool) net.IP { addrs, err := iface.Addrs() require.NoError(t, err) + require.NotEmpty(t, addrs) + var ipOut net.IP for _, addr := range addrs { ip, _, err := net.ParseCIDR(addr.String()) require.NoError(t, err) if !ip.IsPrivate() { continue } - if ipv4 { - if ip.To4() != nil { - return ip - } + if ipv4 && ip.To4() == nil { continue } - return ip + ipOut = ip + break + } + require.NotEmpty(t, ipOut) + return ipOut +} + +func isActiveMulticastInterface(iface net.Interface) bool { + if iface.Name == "anpi0" || iface.Name == "anpi1" { // special debugging interfaces on macOS + return false } - return nil + return iface.Flags&net.FlagUp == net.FlagUp && iface.Flags&net.FlagMulticast == net.FlagMulticast && iface.Flags&net.FlagLoopback != net.FlagLoopback } func TestUDPConnWriteToAddr(t *testing.T) { @@ -306,7 +314,8 @@ func TestUDPConnWriteToAddr(t *testing.T) { require.NoError(t, err) var iface net.Interface for _, i := range ifaces { - if i.Flags&net.FlagUp == net.FlagUp && i.Flags&net.FlagMulticast == net.FlagMulticast && i.Flags&net.FlagLoopback != net.FlagLoopback { + t.Logf("interface name:%v, flags: %v", i.Name, i.Flags) + if isActiveMulticastInterface(i) { iface = i break }