From 17b8c264042fed11f7418f1a438e633ce8e3cb73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Wed, 3 Jul 2019 22:43:55 +0300 Subject: [PATCH] Add explanation for more common EtherTypes --- ethertype-dump.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ethertype-dump.c b/ethertype-dump.c index b999184..eb97788 100644 --- a/ethertype-dump.c +++ b/ethertype-dump.c @@ -54,11 +54,30 @@ int main(void) { if (frame_length < 14) { errx(1, "Very weird frame of only %zdB???", frame_length); } - uint16_t ethertype_length = (frame[12] << 8) | frame[13]; + uint16_t ethertype = (frame[12] << 8) | frame[13]; + + const char *ethertype_meaning = NULL; + if (ethertype <= 1500) { + ethertype_meaning = "packet length"; + } else if (ethertype < 0x0600) { + ethertype_meaning = "undefined"; + } else if (ethertype == 0x0800) { + ethertype_meaning = "IPv4"; + } else if (ethertype == 0x0806) { + ethertype_meaning = "ARP"; + } else if (ethertype == 0x86dd) { + ethertype_meaning = "IPv6"; + } errno = 0; - if(printf("ethertype: %02x%02x, length: %zd\n", ethertype_length >> 8, ethertype_length & 0xff, frame_length) == -1) { - err(1, "printf"); + if (ethertype_meaning == NULL) { + if (printf("ethertype: %02x%02x, length: %zd\n", ethertype >> 8, ethertype & 0xff, frame_length) == -1) { + err(1, "printf"); + } + } else { + if (printf("ethertype: %02x%02x (%s), length: %zd\n", ethertype >> 8, ethertype & 0xff, ethertype_meaning, frame_length) == -1) { + err(1, "printf"); + } } }