Return with the correct copied length (#3804)

This commit is contained in:
Zoltan Papp 2025-05-09 13:56:27 +02:00 committed by GitHub
parent fcd2c15a37
commit cad2fe1f39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -234,7 +234,7 @@ func (s *SharedSocket) read(receiver receiver) {
}
// ReadFrom reads packets received in the packetDemux channel
func (s *SharedSocket) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
func (s *SharedSocket) ReadFrom(b []byte) (int, net.Addr, error) {
var pkt rcvdPacket
select {
case <-s.ctx.Done():
@ -263,8 +263,7 @@ func (s *SharedSocket) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
decodedLayers := make([]gopacket.LayerType, 0, 3)
err = parser.DecodeLayers(pkt.buf, &decodedLayers)
if err != nil {
if err := parser.DecodeLayers(pkt.buf, &decodedLayers); err != nil {
return 0, nil, err
}
@ -273,8 +272,8 @@ func (s *SharedSocket) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
Port: int(udp.SrcPort),
}
copy(b, payload)
return int(udp.Length), remoteAddr, nil
n := copy(b, payload)
return n, remoteAddr, nil
}
// WriteTo builds a UDP packet and writes it using the specific IP version writer