libpnet icon indicating copy to clipboard operation
libpnet copied to clipboard

Stop sending entire backing buffer as ethernet frame

Open faern opened this issue 9 years ago • 2 comments
trafficstars

The library sends too many bytes in the ethernet frames.

When using EthernetDataLinkSender::build_and_send with packet_size set to 100 and you construct a 20 byte packet in the callback (14 bytes header + 6 bytes in the payload) then libpnet actually transmit all 100 bytes to the network when you would expect it to send only 20.

If the library would reuse the same buffer in a consecutive call to the callback func and the user would construct an even smaller packet this time then the remaining bytes would not just be zeroes, it would be data from the old packet. I didn't fully study the implementation, but this might be a possible scenario.

faern avatar Mar 02 '16 18:03 faern

True, the packet should be stripped down to packet.packet()[..packet.packet_size()]

berkus avatar May 05 '18 14:05 berkus

why not using the return value of func callback as the packet size so the user can send variable length packet with each build_and_send call.

ghost avatar Apr 16 '21 06:04 ghost