- register const struct ether_header *ep;
- u_int16_t ether_type;
-
- ep = (const struct ether_header *)bp;
-
- (void)ND_PRINT((ndo, "%s > %s",
- etheraddr_string(ESRC(ep)),
- etheraddr_string(EDST(ep))));
-
- ether_type = EXTRACT_16BITS(&ep->ether_type);
- if (!ndo->ndo_qflag) {
- if (ether_type <= ETHERMTU)
- (void)ND_PRINT((ndo, ", 802.3"));
- else
- (void)ND_PRINT((ndo, ", ethertype %s (0x%04x)",
- tok2str(ethertype_values,"Unknown", ether_type),
- ether_type));
- } else {
- if (ether_type <= ETHERMTU)
- (void)ND_PRINT((ndo, ", 802.3"));
- else
- (void)ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
- }
-
- (void)ND_PRINT((ndo, ", length %u: ", length));
+ const struct ether_header *ehp;
+ uint16_t length_type;
+
+ ehp = (const struct ether_header *)bp;
+
+ ND_PRINT("%s > %s",
+ etheraddr_string(ndo, ehp->ether_shost),
+ etheraddr_string(ndo, ehp->ether_dhost));
+
+ length_type = GET_BE_U_2(bp + (hdrlen - sizeof(ehp->ether_length_type)));
+ if (length_type <= MAX_ETHERNET_LENGTH_VAL) {
+ /*
+ * It's a length field.
+ */
+ ND_PRINT(", 802.3, length %u", length_type);
+ if (length_type > length - hdrlen)
+ ND_PRINT(" (too large, > %u)", length - hdrlen);
+ ND_PRINT(": ");
+ } else {
+ /*
+ * It's a type field.
+ */
+ if (!ndo->ndo_qflag)
+ ND_PRINT(", ethertype %s (0x%04x), length %u: ",
+ tok2str(ethertype_values,"Unknown", length_type),
+ length_type, length);
+ else
+ ND_PRINT(", %s, length %u: ",
+ tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type),
+ length);
+ }