]> The Tcpdump Group git mirrors - tcpdump/commitdiff
from Greg Stark <gsstark[AT]mit.edu>:
authorhannes <hannes>
Fri, 13 Jun 2003 05:55:21 +0000 (05:55 +0000)
committerhannes <hannes>
Fri, 13 Jun 2003 05:55:21 +0000 (05:55 +0000)
honor the payload length in PPPoE frames to match actual
BRAS and client behaviour

CREDITS
print-pppoe.c

diff --git a/CREDITS b/CREDITS
index da63e61cc726953189a1ce3a59f51ee45e88f025..ff399908f572b4c40584d7711feb9790d7f9dae6 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -39,6 +39,7 @@ Additional people who have contributed patches:
        Fulvio Risso                    <[email protected]>
        George Bakos                    <[email protected]>
        Gert Doering                    <[email protected]>
+        Greg Stark                      <[email protected]>
        Gilbert Ramirez Jr.             <[email protected]>
        Gisle Vanem                     <[email protected]>
        Hank Leininger                  <[email protected]>
index 1b908281aff4fc2ab9ff18acfd066e15a8dec51a..f3b2236fc3f92e65bb937ece39ecc9b5e9cfa9b3 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.21 2002-12-19 09:39:14 guy Exp $ (LBL)";
+"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.22 2003-06-13 05:55:22 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -88,6 +88,7 @@ static struct tok pppoetag2str[] = {
 };
 
 #define PPPOE_HDRLEN 6
+#define MAXTAGPRINT 80
 
 u_int
 pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p)
@@ -134,14 +135,19 @@ pppoe_print(register const u_char *bp, u_int length)
                printf(" [ses 0x%x]", pppoe_sessionid);
        }
 
-       if (pppoe_payload + pppoe_length < snapend) {
-#if 0
-               const u_char *x = pppoe_payload + pppoe_length;
+       if (pppoe_payload + pppoe_length < snapend && snapend-pppoe_payload+14 > 64) {
+               /* (small packets are probably just padded up to the ethernet
+                  minimum of 64 bytes) */
                printf(" [length %d (%d extra bytes)]",
                    pppoe_length, snapend - pppoe_payload - pppoe_length);
-               default_print(x, snapend - x);
-#endif
+#if RESPECT_PAYLOAD_LENGTH
                snapend = pppoe_payload+pppoe_length;
+#else
+               /* Actual PPPoE implementations appear to ignore the payload
+                  length and use the full ethernet frame anyways */
+               pppoe_length = snapend-pppoe_payload;
+#endif
+               
        }
 
        if (pppoe_code) {
@@ -162,25 +168,36 @@ pppoe_print(register const u_char *bp, u_int length)
                        /* p points to tag_value */
 
                        if (tag_len) {
-                               int isascii = 1;
+                               unsigned isascii = 0, isgarbage = 0;
                                const u_char *v = p;
                                u_short l;
-
-                               for (v = p; v < p + tag_len; v++)
-                                       if (*v >= 127 || *v < 32) {
-                                               isascii = 0;
-                                               break;
+                               char tag_str[MAXTAGPRINT];
+                               unsigned tag_str_len = 0;
+
+                               for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++)
+                                       if (*v >= 32 && *v < 127) {
+                                               tag_str[tag_str_len++] = *v;
+                                               isascii++;
+                                       } else {
+                                               tag_str[tag_str_len++] = '.';
+                                               isgarbage++;
                                        }
+                               tag_str[tag_str_len] = 0;
 
-                               /* TODO print UTF8 decoded text */
-                               if (isascii) {
-                                       l = (tag_len < 80 ? tag_len : 80);
+                               if (isascii > isgarbage) {
                                        printf(" [%s \"%*.*s\"]",
-                                           tok2str(pppoetag2str, "TAG-0x%x", tag_type),
-                                           l, l, p);
-                               } else
-                                       printf(" [%s UTF8]",
-                                           tok2str(pppoetag2str, "TAG-0x%x", tag_type));
+                                              tok2str(pppoetag2str, "TAG-0x%x", tag_type),
+                                              tag_str_len, tag_str_len, tag_str);
+                               } else {
+                                       /* Print hex, not fast to abuse printf but this doesn't get used much */
+                                       printf(" [%s 0x", tok2str(pppoetag2str, "TAG-0x%x", tag_type));
+                                       for (v=p; v<p+tag_len; v++) {
+                                               printf("%02.2X", *v);
+                                       }
+                                       printf("]");
+                               }
+                               
+
                        } else
                                printf(" [%s]", tok2str(pppoetag2str,
                                    "TAG-0x%x", tag_type));