From 66fc78695a303c486fe17e05afc9c23d9c94874f Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Thu, 20 Jan 2022 05:01:38 +0300 Subject: [PATCH] Fix UDPConn read length --- udp.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/udp.go b/udp.go index 02dbfda..375a068 100644 --- a/udp.go +++ b/udp.go @@ -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) {