libpnet
libpnet copied to clipboard
Stop sending entire backing buffer as ethernet frame
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.
True, the packet should be stripped down to packet.packet()[..packet.packet_size()]
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.