From: Francois-Xavier Le Bail Date: Wed, 16 Dec 2015 14:48:14 +0000 (+0100) Subject: Ethernet: Print the Length/Type field as length when needed X-Git-Tag: tcpdump-4.8.0~57 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/b713410ff2fc96e181987be1556a8198f6ceabb7 Ethernet: Print the Length/Type field as length when needed Reference: IEEE Std 802.3-2012 "If the value of this field is less than or equal to 1500 decimal (05DC hexadecimal), then the Length/Type field indicates the number of MAC client data octets contained in the subsequent MAC Client Data field of the basic frame (Length interpretation)." Update the output of a test accordingly. --- diff --git a/print-ether.c b/print-ether.c index 1e3cbfbc..342da54e 100644 --- a/print-ether.c +++ b/print-ether.c @@ -101,17 +101,19 @@ ether_hdr_print(netdissect_options *ndo, ether_type = EXTRACT_16BITS(&ep->ether_type); if (!ndo->ndo_qflag) { - if (ether_type <= ETHERMTU) - ND_PRINT((ndo, ", 802.3")); - else - ND_PRINT((ndo, ", ethertype %s (0x%04x)", + if (ether_type <= ETHERMTU) { + ND_PRINT((ndo, ", 802.3")); + length = ether_type; + } else + ND_PRINT((ndo, ", ethertype %s (0x%04x)", tok2str(ethertype_values,"Unknown", ether_type), ether_type)); } else { - if (ether_type <= ETHERMTU) - ND_PRINT((ndo, ", 802.3")); - else - ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type))); + if (ether_type <= ETHERMTU) { + ND_PRINT((ndo, ", 802.3")); + length = ether_type; + } else + ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type))); } ND_PRINT((ndo, ", length %u: ", length)); diff --git a/tests/lldp_cdp-ev.out b/tests/lldp_cdp-ev.out index 5743b466..0029a75f 100644 --- a/tests/lldp_cdp-ev.out +++ b/tests/lldp_cdp-ev.out @@ -1,4 +1,4 @@ -00:18:ba:98:68:8f > 01:00:0c:cc:cc:cc, 802.3, length 388: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 366: CDPv2, ttl: 180s, checksum: 0x0bea (unverified), length 366 +00:18:ba:98:68:8f > 01:00:0c:cc:cc:cc, 802.3, length 374: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 366: CDPv2, ttl: 180s, checksum: 0x0bea (unverified), length 366 Device-ID (0x01), value length: 2 bytes: 'S1' Version String (0x05), value length: 190 bytes: Cisco IOS Software, C3560 Software (C3560-ADVIPSERVICESK9-M), Version 12.2(44)SE, RELEASE SOFTWARE (fc1) @@ -17,7 +17,7 @@ Management Addresses (0x16), value length: 13 bytes: IPv4 (1) 0.0.0.0 unknown field type (0x1a), value length: 12 bytes: 0x0000: 0000 0001 0000 0000 ffff ffff -00:19:2f:a7:b2:8d > 01:00:0c:cc:cc:cc, 802.3, length 392: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 370: CDPv2, ttl: 180s, checksum: 0x971d (unverified), length 370 +00:19:2f:a7:b2:8d > 01:00:0c:cc:cc:cc, 802.3, length 378: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 370: CDPv2, ttl: 180s, checksum: 0x971d (unverified), length 370 Device-ID (0x01), value length: 2 bytes: 'S2' Version String (0x05), value length: 190 bytes: Cisco IOS Software, C3560 Software (C3560-ADVIPSERVICESK9-M), Version 12.2(44)SE, RELEASE SOFTWARE (fc1) @@ -124,7 +124,7 @@ PMD autoneg capability [Sym PAUSE for fdx, Asym and Sym PAUSE for fdx, 1000BASE-{X LX SX CX} fdx, 1000BASE-T hdx] (0x0036) MAU type 100BASETX fdx (0x0010) End TLV (0), length 0 -00:18:ba:98:68:8f > 01:00:0c:cc:cc:cc, 802.3, length 388: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 366: CDPv2, ttl: 180s, checksum: 0x0be9 (unverified), length 366 +00:18:ba:98:68:8f > 01:00:0c:cc:cc:cc, 802.3, length 374: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 366: CDPv2, ttl: 180s, checksum: 0x0be9 (unverified), length 366 Device-ID (0x01), value length: 2 bytes: 'S1' Version String (0x05), value length: 190 bytes: Cisco IOS Software, C3560 Software (C3560-ADVIPSERVICESK9-M), Version 12.2(44)SE, RELEASE SOFTWARE (fc1) @@ -143,7 +143,7 @@ Management Addresses (0x16), value length: 13 bytes: IPv4 (1) 0.0.0.0 unknown field type (0x1a), value length: 12 bytes: 0x0000: 0000 0001 0000 0000 ffff ffff -00:19:2f:a7:b2:8d > 01:00:0c:cc:cc:cc, 802.3, length 392: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 370: CDPv2, ttl: 180s, checksum: 0x971c (unverified), length 370 +00:19:2f:a7:b2:8d > 01:00:0c:cc:cc:cc, 802.3, length 378: LLC, dsap SNAP (0xaa) Individual, ssap SNAP (0xaa) Command, ctrl 0x03: oui Cisco (0x00000c), pid CDP (0x2000), length 370: CDPv2, ttl: 180s, checksum: 0x971c (unverified), length 370 Device-ID (0x01), value length: 2 bytes: 'S2' Version String (0x05), value length: 190 bytes: Cisco IOS Software, C3560 Software (C3560-ADVIPSERVICESK9-M), Version 12.2(44)SE, RELEASE SOFTWARE (fc1)