Fix UDPConn read length
This commit is contained in:
parent
83bfd6b807
commit
66fc78695a
8
udp.go
8
udp.go
@ -20,18 +20,18 @@ type UDPConn struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *UDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
func (s *UDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||||
_, _, err := s.PacketConn.ReadFrom(b)
|
nr, _, err := s.PacketConn.ReadFrom(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
datagram, err := NewDatagramFrom(bytes.NewReader(b))
|
datagram, err := NewDatagramFrom(bytes.NewReader(b[:nr]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
n := copy(b, datagram.Data)
|
nc := copy(b, datagram.Data)
|
||||||
return n, AddrFromSocks(datagram.ATYP, datagram.DstAddr, datagram.DstPort), nil
|
return nc, AddrFromSocks(datagram.ATYP, datagram.DstAddr, datagram.DstPort), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UDPConn) Read(b []byte) (int, error) {
|
func (s *UDPConn) Read(b []byte) (int, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user