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 // 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 var pkt rcvdPacket
select { select {
case <-s.ctx.Done(): 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) decodedLayers := make([]gopacket.LayerType, 0, 3)
err = parser.DecodeLayers(pkt.buf, &decodedLayers) if err := parser.DecodeLayers(pkt.buf, &decodedLayers); err != nil {
if err != nil {
return 0, nil, err 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), Port: int(udp.SrcPort),
} }
copy(b, payload) n := copy(b, payload)
return int(udp.Length), remoteAddr, nil return n, remoteAddr, nil
} }
// WriteTo builds a UDP packet and writes it using the specific IP version writer // WriteTo builds a UDP packet and writes it using the specific IP version writer