fix: tuic server return error udp address

This commit is contained in:
wwqgtxx 2023-05-11 22:45:27 +08:00
parent 534282839c
commit f1be9b3f4a
2 changed files with 12 additions and 4 deletions

View file

@ -465,6 +465,11 @@ func NewAddress(metadata *C.Metadata) Address {
} }
func NewAddressNetAddr(addr net.Addr) (Address, error) { 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() addrStr := addr.String()
if addrPort, err := netip.ParseAddrPort(addrStr); err == nil { if addrPort, err := netip.ParseAddrPort(addrStr); err == nil {
return NewAddressAddrPort(addrPort), nil return NewAddressAddrPort(addrPort), nil

View file

@ -44,10 +44,13 @@ func handleUDPToLocal(packet C.UDPPacket, pc N.EnhancePacketConn, key string, oA
_fromUDPAddr := *fromUDPAddr _fromUDPAddr := *fromUDPAddr
fromUDPAddr = &_fromUDPAddr // make a copy fromUDPAddr = &_fromUDPAddr // make a copy
if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok { if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok {
if fAddr.IsValid() && (oAddr.Unmap() == fromAddr.Unmap()) { fromAddr = fromAddr.Unmap()
fromUDPAddr.IP = fAddr.Unmap().AsSlice() if fAddr.IsValid() && (oAddr.Unmap() == fromAddr) {
} else { fromAddr = fAddr.Unmap()
fromUDPAddr.IP = fromAddr.Unmap().AsSlice() }
fromUDPAddr.IP = fromAddr.AsSlice()
if fromAddr.Is4() {
fromUDPAddr.Zone = "" // only ipv6 can have the zone
} }
} }