diff --git a/transport/tuic/protocol.go b/transport/tuic/protocol.go index a460eecc..472bb980 100644 --- a/transport/tuic/protocol.go +++ b/transport/tuic/protocol.go @@ -465,6 +465,11 @@ func NewAddress(metadata *C.Metadata) Address { } func NewAddressNetAddr(addr net.Addr) (Address, error) { + if addr, ok := addr.(interface{ AddrPort() netip.AddrPort }); ok { + if addrPort := addr.AddrPort(); addrPort.IsValid() { // sing's M.Socksaddr maybe return an invalid AddrPort if it's a DomainName + return NewAddressAddrPort(addrPort), nil + } + } addrStr := addr.String() if addrPort, err := netip.ParseAddrPort(addrStr); err == nil { return NewAddressAddrPort(addrPort), nil diff --git a/tunnel/connection.go b/tunnel/connection.go index c95e33f2..73c3e499 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -44,10 +44,13 @@ func handleUDPToLocal(packet C.UDPPacket, pc N.EnhancePacketConn, key string, oA _fromUDPAddr := *fromUDPAddr fromUDPAddr = &_fromUDPAddr // make a copy if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok { - if fAddr.IsValid() && (oAddr.Unmap() == fromAddr.Unmap()) { - fromUDPAddr.IP = fAddr.Unmap().AsSlice() - } else { - fromUDPAddr.IP = fromAddr.Unmap().AsSlice() + fromAddr = fromAddr.Unmap() + if fAddr.IsValid() && (oAddr.Unmap() == fromAddr) { + fromAddr = fAddr.Unmap() + } + fromUDPAddr.IP = fromAddr.AsSlice() + if fromAddr.Is4() { + fromUDPAddr.Zone = "" // only ipv6 can have the zone } }