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.
diff --git a/CREDITS b/CREDITS
index 215a6f7..602f2ba 100644
--- a/CREDITS
+++ b/CREDITS
@@ -24,6 +24,7 @@
Craig Rodrigues <rodrigc@mediaone.net>
Crist J. Clark <cjclark@alum.mit.edu>
Daniel Hagerty <hag@ai.mit.edu>
+ Darren Reed <darrenr@reed.wattle.id.au>
Francisco Matias Cuenca-Acuna <mcuenca@george.rutgers.edu>
Frank Volf <volf@oasis.IAEhv.nl>
Gert Doering <gert@greenie.muc.de>
diff --git a/interface.h b/interface.h
index ab68aef..8242c95 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 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 614248b..5978985 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 @@
}
/* 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 @@
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 @@
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 c6a2cb4..1f68fe9 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 @@
{
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 @@
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_packet = bp;
if (pppoe_packet > snapend) {
printf("[|pppoe]");
- return;
+ return (PPPOE_HDRLEN);
}
pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4;
@@ -139,7 +149,7 @@
if (snapend < pppoe_payload) {
printf(" truncated PPPoE");
- return;
+ return (PPPOE_HDRLEN);
}
if (pppoe_ver != 1) {
@@ -211,9 +221,10 @@
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;
}