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) {