]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ppp.c
Makefile.in: don't remove configure and config.h.in in make distclean.
[tcpdump] / print-ppp.c
index 759b06b118ec15bd85e0108f8e6c1455b270e2dc..aba243ddb6f252251be5649fa5decdeccf0b4e4a 100644 (file)
@@ -42,8 +42,6 @@
 #include <net/if_ppp.h>
 #endif
 
-#include <stdlib.h>
-
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -731,7 +729,6 @@ print_lcp_config_options(netdissect_options *ndo,
                                ND_PRINT(" (length bogus, should be = 7)");
                                return 0;
                        }
-                       ND_TCHECK_4(p + 3);
                        ND_PRINT(": IPv4 %s", GET_IPADDR_STRING(p + 3));
                        break;
                case MEDCLASS_MAC:
@@ -1038,7 +1035,6 @@ print_ipcp_config_options(netdissect_options *ndo,
                        ND_PRINT(" (length bogus, should be = 10)");
                        return len;
                }
-               ND_TCHECK_4(p + 6);
                ND_PRINT(": src %s, dst %s",
                       GET_IPADDR_STRING(p + 2),
                       GET_IPADDR_STRING(p + 6));
@@ -1124,7 +1120,6 @@ print_ipcp_config_options(netdissect_options *ndo,
                        ND_PRINT(" (length bogus, should be = 6)");
                        return 0;
                }
-               ND_TCHECK_4(p + 2);
                ND_PRINT(": %s", GET_IPADDR_STRING(p + 2));
                break;
        default:
@@ -1368,7 +1363,7 @@ ppp_hdlc(netdissect_options *ndo,
        u_char *b, *t, c;
        const u_char *s;
        u_int i, proto;
-       const void *se;
+       const void *sb, *se;
 
        if (caplen == 0)
                return;
@@ -1382,7 +1377,7 @@ ppp_hdlc(netdissect_options *ndo,
 
        /*
         * Unescape all the data into a temporary, private, buffer.
-        * Do this so that we dont overwrite the original packet
+        * Do this so that we don't overwrite the original packet
         * contents.
         */
        for (s = p, t = b, i = caplen; i != 0; i--) {
@@ -1400,8 +1395,11 @@ ppp_hdlc(netdissect_options *ndo,
 
        /*
         * Change the end pointer, so bounds checks work.
+        * Change the pointer to packet data to help debugging.
         */
+       sb = ndo->ndo_packetp;
        se = ndo->ndo_snapend;
+       ndo->ndo_packetp = b;
        ndo->ndo_snapend = t;
        length = ND_BYTES_AVAILABLE_AFTER(b);
 
@@ -1430,18 +1428,26 @@ ppp_hdlc(netdissect_options *ndo,
             if (length < 4)
                 goto trunc;
             proto = GET_BE_U_2(b + 2); /* load the PPP proto-id */
-            handle_ppp(ndo, proto, b + 4, length - 4);
+            if ((proto & 0xff00) == 0x7e00)
+                ND_PRINT("(protocol 0x%04x invalid)", proto);
+            else
+                handle_ppp(ndo, proto, b + 4, length - 4);
             break;
         default: /* last guess - proto must be a PPP proto-id */
-            handle_ppp(ndo, proto, b + 2, length - 2);
+            if ((proto & 0xff00) == 0x7e00)
+                ND_PRINT("(protocol 0x%04x invalid)", proto);
+            else
+                handle_ppp(ndo, proto, b + 2, length - 2);
             break;
         }
 
 cleanup:
+       ndo->ndo_packetp = sb;
        ndo->ndo_snapend = se;
         return;
 
 trunc:
+       ndo->ndo_packetp = sb;
        ndo->ndo_snapend = se;
        nd_print_trunc(ndo);
 }
@@ -1564,11 +1570,18 @@ ppp_print(netdissect_options *ndo,
                hdr_len += 2;
        }
 
-       if (ndo->ndo_eflag)
-               ND_PRINT("%s (0x%04x), length %u: ",
-                         tok2str(ppptype2str, "unknown", proto),
+       if (ndo->ndo_eflag) {
+               const char *typestr;
+               typestr = tok2str(ppptype2str, "unknown", proto);
+               ND_PRINT("%s (0x%04x), length %u",
+                         typestr,
                          proto,
                          olen);
+               if (*typestr == 'u')    /* "unknown" */
+                       return hdr_len;
+
+               ND_PRINT(": ");
+       }
 
        handle_ppp(ndo, proto, p, length);
        return (hdr_len);