From 9ae5e54fd41fdc4979167798290ce798ad784054 Mon Sep 17 00:00:00 2001 From: xqzr <34030394+xqzr@users.noreply.github.com> Date: Thu, 24 Jul 2025 05:48:44 +0800 Subject: [PATCH] Update dns.go --- app/dns/dns.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/dns/dns.go b/app/dns/dns.go index 1395231d..1367c2b0 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -190,13 +190,12 @@ func (s *DNS) LookupIP(domain string, option dns.IPOption) ([]net.IP, uint32, er return nil, 0, errors.New("empty domain name") } + option.IPv4Enable = option.IPv4Enable && s.ipOption.IPv4Enable + option.IPv6Enable = option.IPv6Enable && s.ipOption.IPv6Enable if s.checkSystem { supportIPv4, supportIPv6 := checkSystemNetwork() option.IPv4Enable = option.IPv4Enable && supportIPv4 option.IPv6Enable = option.IPv6Enable && supportIPv6 - } else { - option.IPv4Enable = option.IPv4Enable && s.ipOption.IPv4Enable - option.IPv6Enable = option.IPv6Enable && s.ipOption.IPv6Enable } if !option.IPv4Enable && !option.IPv6Enable { @@ -330,17 +329,15 @@ func init() { func checkSystemNetwork() (supportIPv4 bool, supportIPv6 bool) { conn4, err4 := net.Dial("udp4", "8.8.8.8:53") - if err4 != nil { - supportIPv4 = false - } else { + supportIPv4 = false + if err4 == nil { supportIPv4 = true conn4.Close() } conn6, err6 := net.Dial("udp6", "[2001:4860:4860::8888]:53") - if err6 != nil { - supportIPv6 = false - } else { + supportIPv6 = false + if err6 == nil { supportIPv6 = true conn6.Close() }