From 7db07630a7fceb8161f00f916070dd1e16949f55 Mon Sep 17 00:00:00 2001 From: adlyq <2833154405@qq.com> Date: Mon, 2 May 2022 22:24:14 +0800 Subject: [PATCH] fix: DNS mapping error when sniffing result is ip, Discard sniffs that result in ip --- component/sniffer/dispatcher.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index 909bccff..41df40ac 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/Dreamacro/clash/constant/sniffer" "net" + "net/netip" "strconv" "time" @@ -94,14 +95,14 @@ func (sd *SnifferDispatcher) Enable() bool { func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Metadata) (string, error) { for _, sniffer := range sd.sniffers { if sniffer.SupportNetwork() == C.TCP { - conn.SetReadDeadline(time.Now().Add(3 * time.Second)) + _ = conn.SetReadDeadline(time.Now().Add(3 * time.Second)) _, err := conn.Peek(1) - conn.SetReadDeadline(time.Time{}) + _ = conn.SetReadDeadline(time.Time{}) if err != nil { _, ok := err.(*net.OpError) if ok { log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String()) - conn.Close() + _ = conn.Close() } log.Errorln("[Sniffer] %v", err) return "", err @@ -120,6 +121,12 @@ func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Meta continue } + _, err = netip.ParseAddr(host) + if err == nil { + log.Debugln("[Sniffer] [%s] Sniff data failed %s", sniffer.Protocol(), metadata.DstIP) + continue + } + return host, nil } }