From 8343c3597edcbd84d5016049b579394f34a90e1e Mon Sep 17 00:00:00 2001 From: Skyxim Date: Mon, 6 Jun 2022 21:45:08 +0800 Subject: [PATCH] fix: doq maybe crash when use adapter --- dns/doq.go | 4 ++-- dns/util.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dns/doq.go b/dns/doq.go index ffcb001c..04d80d13 100644 --- a/dns/doq.go +++ b/dns/doq.go @@ -7,13 +7,13 @@ import ( "fmt" "github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/resolver" + "github.com/lucas-clemente/quic-go" "net" "strconv" "sync" "time" "github.com/Dreamacro/clash/log" - "github.com/lucas-clemente/quic-go" D "github.com/miekg/dns" ) @@ -174,7 +174,7 @@ func (dc *quicClient) openSession() (quic.Connection, error) { wrapConn, ok := conn.(*wrapPacketConn) if !ok { - return nil, fmt.Errorf("quio create packet failed") + return nil, fmt.Errorf("quic create packet failed") } udp = wrapConn diff --git a/dns/util.go b/dns/util.go index 3c9c07df..4ea511a9 100644 --- a/dns/util.go +++ b/dns/util.go @@ -143,6 +143,14 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr { return wpc.rAddr } +func (wpc *wrapPacketConn) LocalAddr() net.Addr { + if wpc.PacketConn.LocalAddr() == nil { + return &net.UDPAddr{IP: net.IPv4zero, Port: 0} + } else { + return wpc.PacketConn.LocalAddr() + } +} + func dialContextExtra(ctx context.Context, adapterName string, network string, dstIP netip.Addr, port string, opts ...dialer.Option) (net.Conn, error) { adapter, ok := tunnel.Proxies()[adapterName] if !ok {