Fix UDPConn read length

This commit is contained in:
Anton Zadvorny 2022-01-20 05:01:38 +03:00
parent 83bfd6b807
commit 66fc78695a

8
udp.go
View File

@ -20,18 +20,18 @@ type UDPConn struct {
}
func (s *UDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
_, _, err := s.PacketConn.ReadFrom(b)
nr, _, err := s.PacketConn.ReadFrom(b)
if err != nil {
return 0, nil, err
}
datagram, err := NewDatagramFrom(bytes.NewReader(b))
datagram, err := NewDatagramFrom(bytes.NewReader(b[:nr]))
if err != nil {
return 0, nil, err
}
n := copy(b, datagram.Data)
return n, AddrFromSocks(datagram.ATYP, datagram.DstAddr, datagram.DstPort), nil
nc := copy(b, datagram.Data)
return nc, AddrFromSocks(datagram.ATYP, datagram.DstAddr, datagram.DstPort), nil
}
func (s *UDPConn) Read(b []byte) (int, error) {