From 7166db2ac9b9a01d406e4cb2c74e0c7cf3bde4c3 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 10 Apr 2022 20:01:35 +0800 Subject: [PATCH] fix: code logic error --- component/sniffer/dispatcher.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index 60c52015..a3204deb 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -46,9 +46,13 @@ func (sd *SnifferDispatcher) Enable() bool { func (sd *SnifferDispatcher) cover(conn *CN.BufferedConn, metadata *C.Metadata) { for _, sniffer := range sd.sniffers { if sniffer.SupportNetwork() == C.TCP { - conn.Peek(1) - len := conn.Buffered() - bytes, err := conn.Peek(len) + _, err := conn.Peek(1) + if err != nil { + return + } + + bufferedLen := conn.Buffered() + bytes, err := conn.Peek(bufferedLen) if err != nil { log.Warnln("the data lenght not enough") continue @@ -61,7 +65,6 @@ func (sd *SnifferDispatcher) cover(conn *CN.BufferedConn, metadata *C.Metadata) } metadata.Host = host - metadata.DstIP = nil metadata.AddrType = C.AtypDomainName if resolver.FakeIPEnabled() { metadata.DNSMode = C.DNSFakeIP @@ -70,6 +73,8 @@ func (sd *SnifferDispatcher) cover(conn *CN.BufferedConn, metadata *C.Metadata) } resolver.InsertHostByIP(metadata.DstIP, host) + metadata.DstIP = nil + break } }