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 } }