From b58cddb15484ab7abbdd8d12e38a8ab768923f29 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 29 May 2002 10:32:00 +0000 Subject: [PATCH] Make "-x" and "-X" work with PPPoE interfaces; based on code from Darren Reed, with additions to get the PPP header length from the PPP print routine. --- CREDITS | 1 + interface.h | 6 +++--- print-ppp.c | 11 ++++++++--- print-pppoe.c | 25 ++++++++++++++++++------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CREDITS b/CREDITS index 215a6f76..602f2ba4 100644 --- a/CREDITS +++ b/CREDITS @@ -24,6 +24,7 @@ Additional people who have contributed patches: Craig Rodrigues Crist J. Clark Daniel Hagerty + Darren Reed Francisco Matias Cuenca-Acuna Frank Volf Gert Doering diff --git a/interface.h b/interface.h index ab68aef2..8242c958 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.183 2002-05-29 10:06:24 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.184 2002-05-29 10:32:01 guy Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -240,8 +240,8 @@ extern void pimv1_print(const u_char *, u_int); extern void cisco_autorp_print(const u_char *, u_int); extern void mobile_print(const u_char *, u_int); extern void pim_print(const u_char *, u_int); -extern void pppoe_print(const u_char *, u_int); -extern void ppp_print(register const u_char *, u_int); +extern u_int pppoe_print(const u_char *, u_int); +extern u_int ppp_print(register const u_char *, u_int); extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void ppp_hdlc_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); diff --git a/print-ppp.c b/print-ppp.c index 614248b0..59789853 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.65 2001-10-24 03:49:19 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.66 2002-05-29 10:32:02 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -990,11 +990,12 @@ handle_ppp(u_int proto, const u_char *p, int length) } /* Standard PPP printer */ -void +u_int ppp_print(register const u_char *p, u_int length) { u_int proto; u_int full_length = length; + u_int hdr_len = 0; /* * Here, we assume that p points to the Address and Control @@ -1005,6 +1006,7 @@ ppp_print(register const u_char *p, u_int length) if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) { p += 2; /* ACFC not used */ length -= 2; + hdr_len += 2; } if (length < 2) @@ -1013,18 +1015,21 @@ ppp_print(register const u_char *p, u_int length) proto = *p; /* PFC is used */ p++; length--; + hdr_len++; } else { proto = EXTRACT_16BITS(p); p += 2; length -= 2; + hdr_len += 2; } printf("%s %d: ", ppp_protoname(proto), full_length); handle_ppp(proto, p, length); - return; + return (hdr_len); trunc: printf("[|ppp]"); + return (0); } diff --git a/print-pppoe.c b/print-pppoe.c index c6a2cb44..1f68fe96 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.15 2001-07-05 18:54:17 guy Exp $ (LBL)"; +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.16 2002-05-29 10:32:01 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -99,6 +99,7 @@ pppoe_if_print(u_char *user, const struct pcap_pkthdr *h, { register u_int length = h->len; register u_int caplen = h->caplen; + u_int hdr_len; ++infodelay; ts_print(&h->ts); @@ -111,14 +112,23 @@ pppoe_if_print(u_char *user, const struct pcap_pkthdr *h, packetp = p; snapend = p + caplen; - pppoe_print(p, length); + 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 (xflag && caplen > hdr_len) + default_print(p + hdr_len, caplen - hdr_len); + putchar('\n'); + --infodelay; if (infoprint) info(0); } -void +u_int pppoe_print(register const u_char *bp, u_int length) { u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length; @@ -127,7 +137,7 @@ pppoe_print(register const u_char *bp, u_int length) pppoe_packet = bp; if (pppoe_packet > snapend) { printf("[|pppoe]"); - return; + return (PPPOE_HDRLEN); } pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4; @@ -139,7 +149,7 @@ pppoe_print(register const u_char *bp, u_int length) if (snapend < pppoe_payload) { printf(" truncated PPPoE"); - return; + return (PPPOE_HDRLEN); } if (pppoe_ver != 1) { @@ -211,9 +221,10 @@ pppoe_print(register const u_char *bp, u_int length) p += tag_len; /* p points to next tag */ } + return (0); } else { + /* PPPoE data */ printf(" "); - ppp_print(pppoe_payload, pppoe_length); + return (PPPOE_HDRLEN + ppp_print(pppoe_payload, pppoe_length)); } - return; } -- 2.39.5