mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-09 14:10:00 +00:00
parent
810bfd7022
commit
30e17a40c0
@ -216,6 +216,11 @@ func (c *socks5UDPConn) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func socks5AddrToUDPAddr(atyp byte, addr []byte, port []byte) (*net.UDPAddr, error) {
|
func socks5AddrToUDPAddr(atyp byte, addr []byte, port []byte) (*net.UDPAddr, error) {
|
||||||
|
clone := func(b []byte) []byte {
|
||||||
|
c := make([]byte, len(b))
|
||||||
|
copy(c, b)
|
||||||
|
return c
|
||||||
|
}
|
||||||
iPort := int(binary.BigEndian.Uint16(port))
|
iPort := int(binary.BigEndian.Uint16(port))
|
||||||
switch atyp {
|
switch atyp {
|
||||||
case socks5.ATYPIPv4:
|
case socks5.ATYPIPv4:
|
||||||
@ -223,7 +228,7 @@ func socks5AddrToUDPAddr(atyp byte, addr []byte, port []byte) (*net.UDPAddr, err
|
|||||||
return nil, errors.New("invalid ipv4 address")
|
return nil, errors.New("invalid ipv4 address")
|
||||||
}
|
}
|
||||||
return &net.UDPAddr{
|
return &net.UDPAddr{
|
||||||
IP: net.IPv4(addr[0], addr[1], addr[2], addr[3]),
|
IP: clone(addr),
|
||||||
Port: iPort,
|
Port: iPort,
|
||||||
}, nil
|
}, nil
|
||||||
case socks5.ATYPIPv6:
|
case socks5.ATYPIPv6:
|
||||||
@ -231,7 +236,7 @@ func socks5AddrToUDPAddr(atyp byte, addr []byte, port []byte) (*net.UDPAddr, err
|
|||||||
return nil, errors.New("invalid ipv6 address")
|
return nil, errors.New("invalid ipv6 address")
|
||||||
}
|
}
|
||||||
return &net.UDPAddr{
|
return &net.UDPAddr{
|
||||||
IP: addr,
|
IP: clone(addr),
|
||||||
Port: iPort,
|
Port: iPort,
|
||||||
}, nil
|
}, nil
|
||||||
case socks5.ATYPDomain:
|
case socks5.ATYPDomain:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user