cmd/ctrld: use better approach for checking IPv6 available

Some operating systems may throw a confirmation dialog when attempting
to listen on any interface other than loopback. A better approach is
checking for any interface which is up and can be routed IP traffic.
This commit is contained in:
Cuong Manh Le
2022-12-23 01:49:01 +07:00
committed by Cuong Manh Le
parent e331a4113a
commit 9e7578fb29
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -3,6 +3,8 @@ package main
import (
"net"
"sync"
"golang.org/x/net/nettest"
)
var (
@@ -11,8 +13,8 @@ var (
)
func probeStack() {
if ln, err := net.Listen("tcp6", "[::]:0"); err == nil {
ln.Close()
// TODO(cuonglm): use nettest.SupportsIPv6 once https://github.com/golang/go/issues/57386 fixed.
if _, err := nettest.RoutedInterface("ip6", net.FlagUp); err == nil {
ipv6Enabled = true
}
}