extern void hex_print_with_offset(const char *, const u_char *, u_int, u_int);
extern void hex_print(const char *, const u_char *, u_int);
extern void telnet_print(const u_char *, u_int);
-extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *);
+extern int ethertype_print(u_short, const u_char *, u_int, u_int);
extern int llc_print(const u_char *, u_int, u_int, const u_char *,
const u_char *, u_short *);
-extern int snap_print(const u_char *, u_int, u_int, u_short *, u_int);
+extern int snap_print(const u_char *, u_int, u_int, u_int);
extern void aarp_print(const u_char *, u_int);
extern void aodv_print(const u_char *, u_int, int);
extern void atalk_print(const u_char *, u_int);
extern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *);
extern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *);
extern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *);
-extern void ether_print(const u_char *, u_int, u_int);
+extern void ether_print(const u_char *, u_int, u_int,
+ void (*)(const u_char *), const u_char *);
extern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *);
extern u_int token_print(const u_char *, u_int, u_int);
extern u_int token_if_print(const struct pcap_pkthdr *, const u_char *);
u_int, u_int);
extern void hex_print(netdissect_options *,const char *, u_int);
extern void telnet_print(netdissect_options *,const u_char *, u_int);
-extern int ether_encap_print(netdissect_options *,u_short, const u_char *,
- u_int, u_int, u_short *);
+extern int ethertype_print(netdissect_options *,u_short, const u_char *,
+ u_int, u_int);
extern int llc_print(netdissect_options *,
const u_char *, u_int, u_int, const u_char *,
const u_char *, u_short *);
u_int caplen = h->caplen;
struct firewire_header *fp;
u_short ether_type;
- u_short extracted_ether_type;
if (caplen < FIREWIRE_HDRLEN) {
printf("[|ap1394]");
p += FIREWIRE_HDRLEN;
ether_type = EXTRACT_16BITS(&fp->firewire_type);
-
- extracted_ether_type = 0;
- if (ether_encap_print(ether_type, p, length, caplen,
- &extracted_ether_type) == 0) {
+ if (ethertype_print(ether_type, p, length, caplen) == 0) {
/* ether_type not known, print raw packet */
if (!eflag)
ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN);
(void)printf(", length %u: ", length);
}
+/*
+ * Print an Ethernet frame.
+ * This might be encapsulated within another frame; we might be passed
+ * a pointer to a function that can print header information for that
+ * frame's protocol, and an argument to pass to that function.
+ */
void
-ether_print(const u_char *p, u_int length, u_int caplen)
+ether_print(const u_char *p, u_int length, u_int caplen,
+ void (*print_encap_header)(const u_char *), const u_char *encap_header_arg)
{
struct ether_header *ep;
+ u_int orig_length;
u_short ether_type;
u_short extracted_ether_type;
- if (caplen < ETHER_HDRLEN) {
+ if (caplen < ETHER_HDRLEN || length < ETHER_HDRLEN) {
printf("[|ether]");
return;
}
- if (eflag)
+ if (eflag) {
+ if (print_encap_header != NULL)
+ (*print_encap_header)(encap_header_arg);
ether_hdr_print(p, length);
+ }
+ orig_length = length;
length -= ETHER_HDRLEN;
caplen -= ETHER_HDRLEN;
ether_type = EXTRACT_16BITS(&ep->ether_type);
+recurse:
/*
* Is it (gag) an 802.3 encapsulation?
*/
if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
&extracted_ether_type) == 0) {
/* ether_type not known, print raw packet */
- if (!eflag)
- ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN);
+ if (!eflag) {
+ if (print_encap_header != NULL)
+ (*print_encap_header)(encap_header_arg);
+ ether_hdr_print((u_char *)ep, orig_length);
+ }
+
+ if (!suppress_default_print)
+ default_print(p, caplen);
+ }
+ } else if (ether_type == ETHERTYPE_8021Q) {
+ /*
+ * Print VLAN information, and then go back and process
+ * the enclosed type field.
+ */
+ if (caplen < 4 || length < 4) {
+ printf("[|vlan]");
+ return;
+ }
+ if (eflag) {
+ u_int16_t tag = EXTRACT_16BITS(p);
+
+ printf("vlan %u, p %u%s, ",
+ tag & 0xfff,
+ tag >> 13,
+ (tag & 0x1000) ? ", CFI" : "");
+ }
+
+ ether_type = EXTRACT_16BITS(p + 2);
+ if (eflag && ether_type > ETHERMTU)
+ printf("ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type));
+ p += 4;
+ length -= 4;
+ caplen -= 4;
+ goto recurse;
+ } else if (ether_type == ETHERTYPE_JUMBO) {
+ /*
+ * Alteon jumbo frames.
+ * See
+ *
+ * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
+ *
+ * which indicates that, following the type field,
+ * there's an LLC header and payload.
+ */
+ /* Try to print the LLC-layer header & higher layers */
+ if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
+ &extracted_ether_type) == 0) {
+ /* ether_type not known, print raw packet */
+ if (!eflag) {
+ if (print_encap_header != NULL)
+ (*print_encap_header)(encap_header_arg);
+ ether_hdr_print((u_char *)ep, orig_length);
+ }
+
+ if (!suppress_default_print)
+ default_print(p, caplen);
+ }
+ } else {
+ if (ethertype_print(ether_type, p, length, caplen) == 0) {
+ /* ether_type not known, print raw packet */
+ if (!eflag) {
+ if (print_encap_header != NULL)
+ (*print_encap_header)(encap_header_arg);
+ ether_hdr_print((u_char *)ep, orig_length);
+ }
if (!suppress_default_print)
default_print(p, caplen);
}
- } else if (ether_encap_print(ether_type, p, length, caplen,
- &extracted_ether_type) == 0) {
- /* ether_type not known, print raw packet */
- if (!eflag)
- ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN);
-
- if (!suppress_default_print)
- default_print(p, caplen);
- }
+ }
}
/*
u_int
ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
{
- ether_print(p, h->len, h->caplen);
+ ether_print(p, h->len, h->caplen, NULL, NULL);
return (ETHER_HDRLEN);
}
/*
- * Prints the packet encapsulated in an Ethernet data segment
- * (or an equivalent encapsulation), given the Ethernet type code.
+ * Prints the packet payload, given an Ethernet type code for the payload's
+ * protocol.
*
* Returns non-zero if it can do so, zero if the ethertype is unknown.
- *
- * The Ethernet type code is passed through a pointer; if it was
- * ETHERTYPE_8021Q, it gets updated to be the Ethernet type of
- * the 802.1Q payload, for the benefit of lower layers that might
- * want to know what it is.
*/
int
-ether_encap_print(u_short ether_type, const u_char *p,
- u_int length, u_int caplen, u_short *extracted_ether_type)
+ethertype_print(u_short ether_type, const u_char *p, u_int length, u_int caplen)
{
- recurse:
- *extracted_ether_type = ether_type;
-
switch (ether_type) {
case ETHERTYPE_IP:
ipx_print(p, length);
return (1);
- case ETHERTYPE_8021Q:
- if (eflag) {
- u_int16_t tag = EXTRACT_16BITS(p);
-
- printf("vlan %u, p %u%s, ",
- tag & 0xfff,
- tag >> 13,
- (tag & 0x1000) ? ", CFI" : "");
- }
-
- ether_type = EXTRACT_16BITS(p + 2);
- p += 4;
- length -= 4;
- caplen -= 4;
-
- if (ether_type > ETHERMTU) {
- if (eflag)
- printf("ethertype %s, ",
- tok2str(ethertype_values,"0x%04x", ether_type));
- goto recurse;
- }
-
- *extracted_ether_type = 0;
-
- if (llc_print(p, length, caplen, p - 18, p - 12,
- extracted_ether_type) == 0) {
- ether_hdr_print(p - 18, length + 4);
-
- if (!suppress_default_print) {
- default_print(p - 18, caplen + 4);
- }
- }
-
-
- return (1);
-
- case ETHERTYPE_JUMBO:
- ether_type = EXTRACT_16BITS(p);
- p += 2;
- length -= 2;
- caplen -= 2;
-
- if (ether_type > ETHERMTU) {
- if (eflag)
- printf("ethertype %s, ",
- tok2str(ethertype_values,"0x%04x", ether_type));
- goto recurse;
- }
-
- *extracted_ether_type = 0;
-
- if (llc_print(p, length, caplen, p - 16, p - 10,
- extracted_ether_type) == 0) {
- ether_hdr_print(p - 16, length + 2);
-
- if (!suppress_default_print) {
- default_print(p - 16, caplen + 2);
- }
- }
-
- return (1);
-
case ETHERTYPE_ISO:
isoclns_print(p+1, length-1, length-1);
return(1);
if (eflag)
fr_hdr_print(length, addr_len, dlci, flags, extracted_ethertype);
- if (ether_encap_print(extracted_ethertype,
+ if (ethertype_print(extracted_ethertype,
p+addr_len+ETHERTYPE_LEN,
length-addr_len-ETHERTYPE_LEN,
- length-addr_len-ETHERTYPE_LEN,
- &extracted_ethertype) == 0)
+ length-addr_len-ETHERTYPE_LEN) == 0)
/* ether_type not known, probably it wasn't one */
printf("UI %02x! ", p[addr_len]);
else
break;
case NLPID_SNAP:
- if (snap_print(p, length, length, &extracted_ethertype, 0) == 0) {
+ if (snap_print(p, length, length, 0) == 0) {
/* ether_type not known, print raw packet */
if (!eflag)
fr_hdr_print(length + hdr_len, hdr_len,
isoclns_print(bp, len, len);
break;
case ETHERTYPE_TEB:
- ether_print(bp, len, len);
+ ether_print(bp, len, len, NULL, NULL);
break;
default:
printf("gre-proto-0x%x", prot);
p+=l2info.header_len;
/* this DLT contains nothing but raw ethernet frames */
- ether_print(p, l2info.length, l2info.caplen);
+ ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
return l2info.header_len;
}
#endif
p+=l2info.header_len;
/* this DLT contains nothing but raw Ethernet frames */
- ether_print(p, l2info.length, l2info.caplen);
+ ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
return l2info.header_len;
}
#endif
extracted_ethertype = EXTRACT_16BITS(p);
/* this DLT contains nothing but raw PPPoE frames,
* prepended with a type field*/
- if (ether_encap_print(extracted_ethertype,
+ if (ethertype_print(extracted_ethertype,
p+ETHERTYPE_LEN,
l2info.length-ETHERTYPE_LEN,
- l2info.caplen-ETHERTYPE_LEN,
- &extracted_ethertype) == 0)
+ l2info.caplen-ETHERTYPE_LEN) == 0)
/* ether_type not known, probably it wasn't one */
printf("unknown ethertype 0x%04x", extracted_ethertype);
if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
(EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) {
- ether_print(p, l2info.length, l2info.caplen);
+ ether_print(p, l2info.length, l2info.caplen, NULL, NULL);
return l2info.header_len;
}
{ 0, NULL }
};
-static inline void
-lane_hdr_print(register const u_char *bp, int length)
+static void
+lane_hdr_print(const u_char *bp)
{
- register const struct lecdatahdr_8023 *ep;
-
- ep = (const struct lecdatahdr_8023 *)bp;
- if (qflag)
- (void)printf("lecid:%x %s %s %d: ",
- EXTRACT_16BITS(&ep->le_header),
- etheraddr_string(ep->h_source),
- etheraddr_string(ep->h_dest),
- length);
- else
- (void)printf("lecid:%x %s %s %s %d: ",
- EXTRACT_16BITS(&ep->le_header),
- etheraddr_string(ep->h_source),
- etheraddr_string(ep->h_dest),
- etherproto_string(ep->h_type),
- length);
+ (void)printf("lecid:%x ", EXTRACT_16BITS(bp));
}
/*
lane_print(const u_char *p, u_int length, u_int caplen)
{
struct lane_controlhdr *lec;
- struct lecdatahdr_8023 *ep;
- u_short ether_type;
- u_short extracted_ethertype;
if (caplen < sizeof(struct lane_controlhdr)) {
printf("[|lane]");
return;
}
- if (caplen < sizeof(struct lecdatahdr_8023)) {
- printf("[|lane]");
- return;
- }
-
- if (eflag)
- lane_hdr_print(p, length);
-
/*
- * Go past the LANE header.
+ * Go past the LE header.
*/
- length -= sizeof(struct lecdatahdr_8023);
- caplen -= sizeof(struct lecdatahdr_8023);
- ep = (struct lecdatahdr_8023 *)p;
- p += sizeof(struct lecdatahdr_8023);
-
- ether_type = EXTRACT_16BITS(&ep->h_type);
+ length -= 2;
+ caplen -= 2;
+ p += 2;
/*
- * Is it (gag) an 802.3 encapsulation?
+ * Now print the encapsulated frame, under the assumption
+ * that it's an Ethernet frame.
*/
- if (ether_type <= ETHERMTU) {
- /* Try to print the LLC-layer header & higher layers */
- if (llc_print(p, length, caplen, ep->h_source, ep->h_dest,
- &extracted_ethertype) == 0) {
- /* ether_type not known, print raw packet */
- if (!eflag)
- lane_hdr_print((u_char *)ep, length + sizeof(*ep));
- if (extracted_ethertype) {
- printf("(LLC %s) ",
- etherproto_string(htons(extracted_ethertype)));
- }
- if (!suppress_default_print)
- default_print(p, caplen);
- }
- } else if (ether_encap_print(ether_type, p, length, caplen,
- &extracted_ethertype) == 0) {
- /* ether_type not known, print raw packet */
- if (!eflag)
- lane_hdr_print((u_char *)ep, length + sizeof(*ep));
- if (!suppress_default_print)
- default_print(p, caplen);
- }
+ ether_print(p, length, caplen, lane_hdr_print, p - 2);
}
u_int
* Does anybody ever bridge one form of LAN traffic
* over a networking type that uses 802.2 LLC?
*/
- ret = snap_print(p+3, length-3, caplen-3, extracted_ethertype,
- 2);
+ ret = snap_print(p+3, length-3, caplen-3, 2);
if (ret)
return (ret);
}
}
int
-snap_print(const u_char *p, u_int length, u_int caplen,
- u_short *extracted_ethertype, u_int bridge_pad)
+snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
{
u_int32_t orgcode;
register u_short et;
* Cisco hardware; the protocol ID is
* an Ethernet protocol type.
*/
- ret = ether_encap_print(et, p, length, caplen,
- extracted_ethertype);
+ ret = ethertype_print(et, p, length, caplen);
if (ret)
return (ret);
break;
* but used 0x000000 and an Ethernet
* packet type for AARP packets.
*/
- ret = ether_encap_print(et, p, length, caplen,
- extracted_ethertype);
+ ret = ethertype_print(et, p, length, caplen);
if (ret)
return (ret);
}
/*
* What remains is an Ethernet packet.
*/
- ether_print(p, length, caplen);
+ ether_print(p, length, caplen, NULL, NULL);
return (1);
case PID_RFC2684_802_5_FCS:
ether_type = EXTRACT_16BITS(&sllp->sll_protocol);
+recurse:
/*
* Is it (gag) an 802.3 encapsulation, or some non-Ethernet
* packet type?
default_print(p, caplen);
break;
}
- } else if (ether_encap_print(ether_type, p, length, caplen,
- &extracted_ethertype) == 0) {
- /* ether_type not known, print raw packet */
- if (!eflag)
- sll_print(sllp, length + SLL_HDR_LEN);
- if (!suppress_default_print)
- default_print(p, caplen);
+ } else if (ether_type == ETHERTYPE_8021Q) {
+ /*
+ * Print VLAN information, and then go back and process
+ * the enclosed type field.
+ */
+ if (caplen < 4 || length < 4) {
+ printf("[|vlan]");
+ return (SLL_HDR_LEN);
+ }
+ if (eflag) {
+ u_int16_t tag = EXTRACT_16BITS(p);
+
+ printf("vlan %u, p %u%s, ",
+ tag & 0xfff,
+ tag >> 13,
+ (tag & 0x1000) ? ", CFI" : "");
+ }
+
+ ether_type = EXTRACT_16BITS(p + 2);
+ if (ether_type <= ETHERMTU)
+ ether_type = LINUX_SLL_P_802_2;
+ if (!qflag) {
+ (void)printf("ethertype %s, ",
+ tok2str(ethertype_values, "Unknown", ether_type));
+ }
+ p += 4;
+ length -= 4;
+ caplen -= 4;
+ goto recurse;
+ } else {
+ if (ethertype_print(ether_type, p, length, caplen) == 0) {
+ /* ether_type not known, print raw packet */
+ if (!eflag)
+ sll_print(sllp, length + SLL_HDR_LEN);
+ if (!suppress_default_print)
+ default_print(p, caplen);
+ }
}
return (SLL_HDR_LEN);
u_int caplen = h->caplen;
struct symantec_header *sp;
u_short ether_type;
- u_short extracted_ether_type;
if (caplen < sizeof (struct symantec_header)) {
printf("[|symantec]");
if (!suppress_default_print)
default_print(p, caplen);
- } else if (ether_encap_print(ether_type, p, length, caplen,
- &extracted_ether_type) == 0) {
+ } else if (ethertype_print(ether_type, p, length, caplen) == 0) {
/* ether_type not known, print raw packet */
if (!eflag)
symantec_hdr_print((u_char *)sp, length + sizeof (struct symantec_header));