Pad the frame to the required length.

If we don't do that, the NIC will generate padding that contains
non-zero bytes. EtherMess excepts all-zero padding, so this will break.
This commit is contained in:
Juhani Krekelä 2019-07-24 20:45:12 +03:00
parent 2410a28947
commit 9513911377
1 changed files with 13 additions and 2 deletions

View File

@ -256,8 +256,19 @@ void drop_privileges(void) {
}
void send_frame(const unsigned char *frame, size_t frame_length) {
if (write(packet_socket, frame, frame_length) == -1) {
err(1, "write");
// 64B is the minimum frame side
// We check for 60B, since kernel handles the FCS (4B)
if (frame_length < 60) {
unsigned char padded_frame[60];
memset(padded_frame, 0, sizeof(padded_frame));
memcpy(padded_frame, frame, frame_length);
if (write(packet_socket, padded_frame, sizeof(padded_frame)) == -1) {
err(1, "write");
}
} else {
if (write(packet_socket, frame, frame_length) == -1) {
err(1, "write");
}
}
}