cmd/ctrld: check for ipv6 listen local

Since when the machine may not have external ipv6 capability, but still
can do ipv6 network on local network.
This commit is contained in:
Cuong Manh Le
2023-03-02 09:16:51 +07:00
committed by Cuong Manh Le
parent 8b08cc8a6e
commit 262dcb1dff

View File

@@ -57,14 +57,16 @@ func (p *prog) serveUDP(listenerNum string) error {
// On Windows, there's no easy way for disabling/removing IPv6 DNS resolver, so we check whether we can
// listen on ::1, then spawn a listener for receiving DNS requests.
if runtime.GOOS == "windows" && ctrldnet.SupportsIPv6() {
if runtime.GOOS == "windows" && ctrldnet.SupportsIPv6ListenLocal() {
go func() {
s := &dns.Server{
Addr: net.JoinHostPort("::1", strconv.Itoa(listenerConfig.Port)),
Net: "udp",
Handler: handler,
}
_ = s.ListenAndServe()
if err := s.ListenAndServe(); err != nil {
mainLog.Error().Err(err).Msg("could not serving on ::1")
}
}()
}