Process runt frames too, as long as they're long enough to contain full header

This commit is contained in:
Juhani Krekelä 2019-07-05 14:58:33 +03:00
parent a9fea6fee3
commit fd277d5ec7
1 changed files with 10 additions and 4 deletions

View File

@ -80,7 +80,7 @@ int main(int argc, char **argv) {
}
for(;;) {
unsigned char frame[1522]; // 1522 is the largest a 802.3 frame can be
unsigned char frame[1518]; // 1518 is the largest a 802.3 frame can be without FCS (which we apparently don't get)
if (fflush(stdout) == -1) {
err(1, "fflush");
@ -91,10 +91,12 @@ int main(int argc, char **argv) {
if (frame_length == -1) {
err(1, "recv");
}
size_t frame_data_length = (size_t)frame_length < sizeof(frame) ? (size_t)frame_length : sizeof(frame);
frame_length += 4; // Include the FCS in the true length
if (frame_length < 64) {
if (frame_data_length < 14) {
errno = 0;
if (printf("Runt frame (%zdB)\n", frame_length) == -1) {
if (printf("Frame too short to contain header (%zdB)\n", frame_length) == -1) {
err(1, "printf");
}
continue;
@ -143,10 +145,14 @@ int main(int argc, char **argv) {
}
errno = 0;
if (frame_length > 1522) {
if ((size_t)frame_length > sizeof(frame) + 4) { // +4 for the FCS
if (printf(" (overlong)\n") == -1) {
err(1, "printf");
}
} else if(frame_length < 64) {
if (printf(" (runt)\n") == -1) {
err(1, "printf");
}
} else {
if (printf("\n") == -1) {
err(1, "printf");