]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ppp.c
When checking for pcap_if_t, add $V_INCLS to CFLAGS, so we look at the
[tcpdump] / print-ppp.c
index d4fb4f29b2ca772d79d6ab48fca2b0d59302d203..cfa92e5e720bb334c40e9f4306d00cc6ba2fe476 100644 (file)
@@ -31,7 +31,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.94 2004-03-24 03:30:06 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.98 2004-07-06 22:11:17 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -47,6 +47,7 @@ static const char rcsid[] _U_ =
 
 #include <pcap.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "interface.h"
 #include "extract.h"
@@ -71,13 +72,14 @@ struct tok ppptype2str[] = {
         { PPP_DECNET,    "DECNET" },
         { PPP_APPLE,     "APPLE" },
        { PPP_IPX,        "IPX" },
-       { PPP_VJC,        "VJC" },
-       { PPP_VJNC,       "VJNC" },
+       { PPP_VJC,        "VJC IP" },
+       { PPP_VJNC,       "VJNC IP" },
        { PPP_BRPDU,      "BRPDU" },
        { PPP_STII,       "STII" },
        { PPP_VINES,      "VINES" },
        { PPP_MPLS_UCAST, "MPLS" },
        { PPP_MPLS_MCAST, "MPLS" },
+        { PPP_COMP,       "Compressed"},
 
        { PPP_HELLO,      "HELLO" },
        { PPP_LUXCOM,     "LUXCOM" },
@@ -370,6 +372,7 @@ static int print_ipcp_config_options (const u_char *p, int);
 static int print_ccp_config_options (const u_char *p, int);
 static int print_bacp_config_options (const u_char *p, int);
 static void handle_ppp (u_int proto, const u_char *p, int length);
+static void ppp_hdlc(const u_char *p, int length);
 
 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
 static void
@@ -1052,10 +1055,81 @@ trunc:
 }
 
 
+static void
+ppp_hdlc(const u_char *p, int length)
+{
+       u_char *b, *s, *t, c;
+       int i, proto;
+       const void *se;
+
+       b = (u_int8_t *)malloc(length);
+       if (b == NULL)
+               return;
+
+       /*
+        * Unescape all the data into a temporary, private, buffer.
+        * Do this so that we dont overwrite the original packet
+        * contents.
+        */
+       for (s = (u_char *)p, t = b, i = length; i > 0; i--) {
+               c = *s++;
+               if (c == 0x7d) {
+                       if (i > 1) {
+                               i--;
+                               c = *s++ ^ 0x20;
+                       } else
+                               continue;
+               }
+               *t++ = c;
+       }
+
+       se = snapend;
+       snapend = t;
+
+        /* now lets guess about the payload codepoint format */
+        proto = *b; /* start with a one-octet codepoint guess */
+        
+        switch (proto) {
+        case PPP_IP:
+            ip_print(b+1, t - b - 1);
+            goto cleanup;
+#ifdef INET6
+        case PPP_IPV6:
+            ip6_print(b+1, t - b - 1);
+            goto cleanup;
+#endif
+        default: /* no luck - try next guess */
+            break;
+        }
+
+        proto = EXTRACT_16BITS(b); /* next guess - load two octets */
+
+        switch (proto) {
+        case 0xff03: /* looks like a PPP frame */
+            proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
+            handle_ppp(proto, b+4, t - b - 4);
+            break;
+        default: /* last guess - proto must be a PPP proto-id */
+            handle_ppp(proto, b+2, t - b - 2);
+            break;
+        }
+
+cleanup:
+        snapend = se;
+       free(b);
+        return;
+}
+
+
 /* PPP */
 static void
 handle_ppp(u_int proto, const u_char *p, int length)
 {
+        if ((proto & 0xff00) == 0x7e00) {/* is this an escape code ? */
+            ppp_hdlc(p-1, length);
+            return;
+        }
+
        switch (proto) {
        case PPP_LCP:
        case PPP_IPCP:
@@ -1076,6 +1150,7 @@ handle_ppp(u_int proto, const u_char *p, int length)
                handle_bap(p, length);
                break;
        case ETHERTYPE_IP:      /*XXX*/
+        case PPP_VJNC:
        case PPP_IP:
                ip_print(p, length);
                break;
@@ -1096,10 +1171,13 @@ handle_ppp(u_int proto, const u_char *p, int length)
        case PPP_MPLS_MCAST:
                mpls_print(p, length);
                break;
+       case PPP_COMP:
+               printf("compressed PPP data");
+               break;
        default:
-                printf("unknown PPP protocol (0x%04x)", proto);
-                print_unknown_data(p,"\n\t",length);
-                break;
+               printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
+               print_unknown_data(p,"\n\t",length);
+               break;
        }
 }