From: guy Date: Wed, 18 Dec 2002 09:41:13 +0000 (+0000) Subject: Add a new routine "default_print_packet()", which takes a pointer to the X-Git-Tag: tcpdump-3.8-bp~256 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/cfabfb053b4bf5b50f4d98d59053e1cc97ff5014 Add a new routine "default_print_packet()", which takes a pointer to the beginning of the raw packet data, the captured length of the raw packet data, and the length of the link-layer header, and: if "-e" was specified, prints all the raw packet data; if "-e" was not specified, prints all the raw packet data past the link-layer header, if there is any. Use that routine in all the "xxx_if_print()" routines if "-x" was specified. Make "arcnet_encap_print()" static - it's not used outside "print-arcnet.c". Add missing info printing code to "atm_if_print()". Print the packet data in "lane_if_print()", not in "lane_print()", as "lane_print()" can be called from other "xxx_if_print()" routines, and those routines will also print the packet data if "-x" was specified - no need to print it twice. --- diff --git a/interface.h b/interface.h index 36e9229c..b42dac2d 100644 --- a/interface.h +++ b/interface.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.201 2002-12-18 08:53:18 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.202 2002-12-18 09:41:13 guy Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -213,6 +213,7 @@ extern void cnfp_print(const u_char *, const u_char *); extern void decnet_print(const u_char *, u_int, u_int); extern void default_print(const u_char *, u_int); extern void default_print_unaligned(const u_char *, u_int); +extern void default_print_packet(const u_char *, u_int, u_int); extern void dvmrp_print(const u_char *, u_int); extern void egp_print(const u_char *); extern void pflog_if_print(u_char *, const struct pcap_pkthdr *, diff --git a/print-802_11.c b/print-802_11.c index 1650912d..b54b27f3 100644 --- a/print-802_11.c +++ b/print-802_11.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.17 2002-12-18 08:53:19 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.18 2002-12-18 09:41:14 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -800,6 +800,8 @@ ieee802_11_print(const u_char *p, u_int length, u_int caplen) { u_int16_t fc; u_int HEADER_LENGTH; + const u_char *orig_p; + u_int orig_caplen; const u_int8_t *src, *dst; u_short extracted_ethertype; @@ -825,6 +827,16 @@ ieee802_11_print(const u_char *p, u_int length, u_int caplen) */ snapend = p + caplen; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + + /* + * Go past the 802.11 header. + */ length -= HEADER_LENGTH; caplen -= HEADER_LENGTH; p += HEADER_LENGTH; @@ -879,7 +891,7 @@ ieee802_11_print(const u_char *p, u_int length, u_int caplen) } if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, HEADER_LENGTH); } /* diff --git a/print-arcnet.c b/print-arcnet.c index 30e42a81..7f1db3e3 100644 --- a/print-arcnet.c +++ b/print-arcnet.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.11 2002-12-18 08:53:19 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.12 2002-12-18 09:41:14 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -37,7 +37,7 @@ static const char rcsid[] = #include "interface.h" #include "arcnet.h" -int arcnet_encap_print(u_char arctype, const u_char *p, +static int arcnet_encap_print(u_char arctype, const u_char *p, u_int length, u_int caplen); struct tok arctypemap[] = { @@ -111,6 +111,8 @@ arcnet_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; + const u_char *orig_p; + u_int orig_caplen; const struct arc_header *ap; int phds, flag = 0, archdrlen = 0; @@ -174,6 +176,16 @@ arcnet_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) */ snapend = p + caplen; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + + /* + * Go past the ARCNET header. + */ length -= archdrlen; caplen -= archdrlen; p += archdrlen; @@ -188,7 +200,7 @@ arcnet_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) out2: if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, archdrlen); out: putchar('\n'); @@ -205,7 +217,7 @@ arcnet_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) */ -int +static int arcnet_encap_print(u_char arctype, const u_char *p, u_int length, u_int caplen) { diff --git a/print-atm.c b/print-atm.c index 77977b25..5b41cc78 100644 --- a/print-atm.c +++ b/print-atm.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.31 2002-12-18 08:53:19 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.32 2002-12-18 09:41:14 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -139,6 +139,9 @@ atm_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } /* diff --git a/print-chdlc.c b/print-chdlc.c index 41a4d521..5bd4bdb0 100644 --- a/print-chdlc.c +++ b/print-chdlc.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.25 2002-12-18 08:53:20 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.26 2002-12-18 09:41:15 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -132,7 +132,7 @@ chdlc_print(register const u_char *p, u_int length, u_int caplen) break; } if (xflag) - default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); + default_print_packet(p, caplen, CHDLC_HDRLEN); } struct cisco_slarp { diff --git a/print-ether.c b/print-ether.c index 2d392730..fdd79642 100644 --- a/print-ether.c +++ b/print-ether.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.74 2002-12-18 08:53:21 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.75 2002-12-18 09:41:15 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -134,11 +134,10 @@ ether_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) ether_print(p, length, caplen); /* - * If "-x" was specified, print stuff past the Ethernet header, - * if there's anything to print. + * If "-x" was specified, print packet data in hex. */ - if (xflag && caplen > ETHER_HDRLEN) - default_print(p + ETHER_HDRLEN, caplen - ETHER_HDRLEN); + if (xflag) + default_print_packet(p, caplen, ETHER_HDRLEN); putchar('\n'); diff --git a/print-fddi.c b/print-fddi.c index 762feaca..0bd439ac 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.59 2002-12-18 08:53:21 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.60 2002-12-18 09:41:15 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -321,11 +321,10 @@ fddi_if_print(u_char *pcap _U_, const struct pcap_pkthdr *h, fddi_print(p, length, caplen); /* - * If "-x" was specified, print stuff past the FDDI header, - * if there's anything to print. + * If "-x" was specified, print packet data in hex. */ - if (xflag && caplen > FDDI_HDRLEN) - default_print(p + FDDI_HDRLEN, caplen - FDDI_HDRLEN); + if (xflag) + default_print_packet(p, caplen, FDDI_HDRLEN); putchar('\n'); diff --git a/print-fr.c b/print-fr.c index f639dc62..8c27fc21 100644 --- a/print-fr.c +++ b/print-fr.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.9 2002-12-18 08:53:21 guy Exp $ (LBL)"; + "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.10 2002-12-18 09:41:16 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -217,6 +217,8 @@ fr_if_print(u_char *user _U_, const struct pcap_pkthdr *h, { register u_int length = h->len; register u_int caplen = h->caplen; + const u_char *orig_p; + u_int orig_caplen; u_char protocol; int layer2_len; u_short extracted_ethertype; @@ -240,6 +242,13 @@ fr_if_print(u_char *user _U_, const struct pcap_pkthdr *h, if (eflag) fr_hdr_print(p, length); + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + protocol = FR_PROTOCOL(p); layer2_len = LAYER2_LEN(p); p += layer2_len; @@ -288,7 +297,7 @@ fr_if_print(u_char *user _U_, const struct pcap_pkthdr *h, } if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, layer2_len); out: putchar('\n'); } diff --git a/print-ipfc.c b/print-ipfc.c index a33cfbdf..3da01d65 100644 --- a/print-ipfc.c +++ b/print-ipfc.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ipfc.c,v 1.2 2002-12-18 08:53:21 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ipfc.c,v 1.3 2002-12-18 09:41:16 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -148,11 +148,10 @@ ipfc_if_print(u_char *pcap _U_, const struct pcap_pkthdr *h, ipfc_print(p, length, caplen); /* - * If "-x" was specified, print stuff past the Network_Header, - * if there's anything to print. + * If "-x" was specified, print packet data in hex. */ - if (xflag && caplen > IPFC_HDRLEN) - default_print(p + IPFC_HDRLEN, caplen - IPFC_HDRLEN); + if (xflag) + default_print_packet(p, caplen, IPFC_HDRLEN); putchar('\n'); diff --git a/print-lane.c b/print-lane.c index fe0afb4b..c727b9ff 100644 --- a/print-lane.c +++ b/print-lane.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.18 2002-12-18 08:53:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.19 2002-12-18 09:41:16 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -128,6 +128,9 @@ lane_print(const u_char *p, u_int length, u_int caplen) */ snapend = p + caplen; + /* + * Go past the LANE header. + */ length -= sizeof(struct lecdatahdr_8023); caplen -= sizeof(struct lecdatahdr_8023); ep = (struct lecdatahdr_8023 *)p; @@ -161,8 +164,6 @@ lane_print(const u_char *p, u_int length, u_int caplen) if (!xflag && !qflag) default_print(p, caplen); } - if (xflag) - default_print(p, caplen); } void @@ -176,6 +177,13 @@ lane_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) lane_print(p, length, caplen); + /* + * If "-x" was specified, print packet data in hex. + */ + if (xflag) + default_print_packet(p, caplen, + sizeof(struct lecdatahdr_8023)); + putchar('\n'); --infodelay; if (infoprint) diff --git a/print-null.c b/print-null.c index cdbb3734..064408a0 100644 --- a/print-null.c +++ b/print-null.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.45 2002-12-18 08:53:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.46 2002-12-18 09:41:16 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -149,7 +149,7 @@ null_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) } if (xflag) - default_print((const u_char *)ip, caplen - NULL_HDRLEN); + default_print_packet(p, caplen, NULL_HDRLEN); putchar('\n'); --infodelay; if (infoprint) diff --git a/print-pflog.c b/print-pflog.c index f122a5a3..61d5dc92 100644 --- a/print-pflog.c +++ b/print-pflog.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.5 2002-12-18 08:53:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.6 2002-12-18 09:41:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -102,6 +102,8 @@ pflog_if_print(u_char *user _U_, const struct pcap_pkthdr *h, { u_int length = h->len; u_int caplen = h->caplen; + const u_char *orig_p; + u_int orig_caplen; const struct pfloghdr *hdr; u_int8_t af; @@ -119,6 +121,13 @@ pflog_if_print(u_char *user _U_, const struct pcap_pkthdr *h, */ snapend = p + caplen; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + hdr = (const struct pfloghdr *)p; if (eflag) pflog_print(hdr); @@ -147,7 +156,7 @@ pflog_if_print(u_char *user _U_, const struct pcap_pkthdr *h, } if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, PFLOG_HDRLEN); out: putchar('\n'); --infodelay; diff --git a/print-ppp.c b/print-ppp.c index 6103be4b..f7be51d5 100644 --- a/print-ppp.c +++ b/print-ppp.c @@ -31,7 +31,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.78 2002-12-18 08:53:23 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.79 2002-12-18 09:41:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -1129,6 +1129,8 @@ ppp_hdlc_if_print(u_char *user _U_, const struct pcap_pkthdr *h, { register u_int length = h->len; register u_int caplen = h->caplen; + const u_char *orig_p; + u_int orig_caplen; u_int proto; ++infodelay; @@ -1146,6 +1148,13 @@ ppp_hdlc_if_print(u_char *user _U_, const struct pcap_pkthdr *h, */ snapend = p + caplen; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + switch (p[0]) { case PPP_ADDRESS: @@ -1188,7 +1197,7 @@ ppp_hdlc_if_print(u_char *user _U_, const struct pcap_pkthdr *h, } if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, p - orig_p); out: putchar('\n'); --infodelay; @@ -1206,6 +1215,7 @@ ppp_bsdos_if_print(u_char *user _U_, const struct pcap_pkthdr *h _U_, #ifdef __bsdi__ register u_int length = h->len; register u_int caplen = h->caplen; + const u_char *orig_p; register int hdrlength; u_int16_t ptype; const u_char *q; @@ -1227,6 +1237,12 @@ ppp_bsdos_if_print(u_char *user _U_, const struct pcap_pkthdr *h _U_, snapend = p + caplen; hdrlength = 0; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + #if 0 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) { if (eflag) @@ -1361,7 +1377,7 @@ ppp_bsdos_if_print(u_char *user _U_, const struct pcap_pkthdr *h _U_, printx: if (xflag) - default_print((const u_char *)p, caplen - hdrlength); + default_print_packet(orig_p, caplen, hdrlength); out: putchar('\n'); --infodelay; diff --git a/print-pppoe.c b/print-pppoe.c index 3d78f4ce..d6bafcf6 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = -"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.19 2002-12-18 08:53:23 guy Exp $ (LBL)"; +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.20 2002-12-18 09:41:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -110,11 +110,10 @@ pppoe_if_print(u_char *user _U_, const struct pcap_pkthdr *h, hdr_len = pppoe_print(p, length); /* - * If "-x" was specified, print stuff past the PPPoE and PPP headers, - * if there's anything to print. + * If "-x" was specified, print packet data in hex. */ - if (xflag && caplen > hdr_len) - default_print(p + hdr_len, caplen - hdr_len); + if (xflag) + default_print_packet(p, caplen, hdr_len); putchar('\n'); diff --git a/print-sl.c b/print-sl.c index 75056462..fa6fa0f1 100644 --- a/print-sl.c +++ b/print-sl.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.60 2002-12-18 08:53:24 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.61 2002-12-18 09:41:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -91,7 +91,7 @@ sl_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) } if (xflag) - default_print((u_char *)ip, caplen - SLIP_HDRLEN); + default_print_packet(p, caplen, SLIP_HDRLEN); out: putchar('\n'); --infodelay; @@ -134,7 +134,7 @@ sl_bsdos_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p ip_print((u_char *)ip, length); if (xflag) - default_print((u_char *)ip, caplen - SLIP_HDRLEN); + default_print_packet(p, caplen, SLIP_HDRLEN); out: putchar('\n'); --infodelay; diff --git a/print-sll.c b/print-sll.c index 2cd90f72..ccb94fb5 100644 --- a/print-sll.c +++ b/print-sll.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.10 2002-12-18 08:53:24 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.11 2002-12-18 09:41:18 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -97,6 +97,8 @@ sll_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; + const u_char *orig_p; + u_int orig_caplen; register const struct sll_header *sllp; u_short ether_type; u_short extracted_ethertype; @@ -126,6 +128,16 @@ sll_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) */ snapend = p + caplen; + /* + * Save the information for the full packet, so we can print + * everything if "-e" and "-x" are both specified. + */ + orig_p = p; + orig_caplen = caplen; + + /* + * Go past the cooked-mode header. + */ length -= SLL_HDR_LEN; caplen -= SLL_HDR_LEN; p += SLL_HDR_LEN; @@ -182,7 +194,7 @@ sll_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); } if (xflag) - default_print(p, caplen); + default_print_packet(orig_p, orig_caplen, SLL_HDR_LEN); out: putchar('\n'); --infodelay; diff --git a/print-token.c b/print-token.c index 5070e5b9..74dc536b 100644 --- a/print-token.c +++ b/print-token.c @@ -25,7 +25,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.20 2002-12-18 08:53:24 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.21 2002-12-18 09:41:18 guy Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -208,11 +208,10 @@ token_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p) hdr_len = token_print(p, length, caplen); /* - * If "-x" was specified, print stuff past the Token Ring header, - * if there's anything to print. + * If "-x" was specified, print packet data in hex. */ - if (xflag && caplen > hdr_len) - default_print(p + hdr_len, caplen - hdr_len); + if (xflag) + default_print_packet(p, caplen, hdr_len); putchar('\n'); diff --git a/tcpdump.1 b/tcpdump.1 index ed8c2da7..af1b1e45 100644 --- a/tcpdump.1 +++ b/tcpdump.1 @@ -1,4 +1,4 @@ -.\" @(#) $Header: /tcpdump/master/tcpdump/Attic/tcpdump.1,v 1.131 2002-12-05 23:59:42 hannes Exp $ (LBL) +.\" @(#) $Header: /tcpdump/master/tcpdump/Attic/tcpdump.1,v 1.132 2002-12-18 09:41:18 guy Exp $ (LBL) .\" .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -446,7 +446,10 @@ They can later be printed with the \-r option. Standard output is used if \fIfile\fR is ``-''. .TP .B \-x -Print each packet (minus its link level header) in hex. +Print each packet (minus its link level header, unless +.B \-e +is specified) +in hex. The smaller of the entire packet or .I snaplen bytes will be printed. Note that this is the entire link-layer diff --git a/tcpdump.c b/tcpdump.c index 6b02404a..59eae3fa 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -30,7 +30,7 @@ static const char copyright[] = "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\ The Regents of the University of California. All rights reserved.\n"; static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.189 2002-12-12 07:28:36 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.190 2002-12-18 09:41:19 guy Exp $ (LBL)"; #endif /* @@ -795,7 +795,7 @@ default_print_unaligned(register const u_char *cp, register u_int length) #endif /* - * By default, print the packet out in hex. + * By default, print the specified data out in hex. */ void default_print(register const u_char *bp, register u_int length) @@ -803,6 +803,31 @@ default_print(register const u_char *bp, register u_int length) default_print_unaligned(bp, length); } +/* + * By default, print the packet out in hex; if eflag is set, print + * everything, otherwise print everything except for the link-layer + * header. + */ +void +default_print_packet(register const u_char *bp, register u_int length, + u_int hdr_length) +{ + if (eflag) { + /* + * Include the link-layer header. + */ + default_print_unaligned(bp, length); + } else { + /* + * Don't include the link-layer header - and if we have + * nothing past the link-layer header, print nothing. + */ + if (length > hdr_length) + default_print_unaligned(bp + hdr_length, + length - hdr_length); + } +} + #ifdef SIGINFO RETSIGTYPE requestinfo(int signo _U_) {