]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cdp.c
Make it clearer that the hex or hex-and-ASCII dump for "-x", "-xx",
[tcpdump] / print-cdp.c
index fdc62e89375d55b4048f1d21e28bc650020d3234..f8f4427c046ba0b4235d62aa7a18f5c63ab13380 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.21 2003-11-16 09:36:15 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.25 2004-10-07 14:53:11 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -41,6 +41,7 @@ static const char rcsid[] _U_ =
 #include "interface.h"
 #include "addrtoname.h"
 #include "extract.h"                   /* must come after interface.h */
+#include "nlpid.h"
 
 #define CDP_HEADER_LEN  4
 
@@ -99,9 +100,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen)
 
         if (!TTEST2(*tptr, CDP_HEADER_LEN))
                 goto trunc;
-       printf("CDP v%u, ttl: %us", *tptr, *(tptr+1));
+       printf("CDPv%u, ttl: %us", *tptr, *(tptr+1));
         if (vflag)
-                printf(", checksum: %u (unverified)", EXTRACT_16BITS(tptr));
+                printf(", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr), length);
        tptr += CDP_HEADER_LEN;
 
        while (tptr < (pptr+length)) {
@@ -213,6 +214,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen)
                        break;
                tptr = tptr+len;
        }
+        if (vflag < 1)
+            printf(", length %u",caplen);
+
        return;
 trunc:
        printf("[|cdp]");
@@ -240,21 +244,24 @@ cdp_print_addr(const u_char * p, int l)
        };
 #endif
 
+       TCHECK2(*p, 2);
        num = EXTRACT_32BITS(p);
        p += 4;
 
        while (p < endp && num >= 0) {
+               TCHECK2(*p, 2);
                if (p + 2 > endp)
                        goto trunc;
                pt = p[0];              /* type of "protocol" field */
                pl = p[1];              /* length of "protocol" field */
                p += 2;
 
+               TCHECK2(p[pl], 2);
                if (p + pl + 2 > endp)
                        goto trunc;
                al = EXTRACT_16BITS(&p[pl]);    /* address length */
 
-               if (pt == PT_NLPID && pl == 1 && *p == 0xcc && al == 4) {
+               if (pt == PT_NLPID && pl == 1 && *p == NLPID_IP && al == 4) {
                        /*
                         * IPv4: protocol type = NLPID, protocol length = 1
                         * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
@@ -262,6 +269,7 @@ cdp_print_addr(const u_char * p, int l)
                         */
                        p += 3;
 
+                       TCHECK2(*p, 4);
                        if (p + 4 > endp)
                                goto trunc;
                        printf("IPv4 (%u) %s",
@@ -279,6 +287,7 @@ cdp_print_addr(const u_char * p, int l)
                         * Ethertype, address length = 16
                         */
                        p += 10;
+                       TCHECK2(*p, al);
                        if (p + al > endp)
                                goto trunc;
 
@@ -292,16 +301,19 @@ cdp_print_addr(const u_char * p, int l)
                        /*
                         * Generic case: just print raw data
                         */
+                       TCHECK2(*p, pl);
                        if (p + pl > endp)
                                goto trunc;
                        printf("pt=0x%02x, pl=%d, pb=", *(p - 2), pl);
                        while (pl-- > 0)
                                printf(" %02x", *p++);
+                       TCHECK2(*p, 2);
                        if (p + 2 > endp)
                                goto trunc;
                        al = (*p << 8) + *(p + 1);
                        printf(", al=%d, a=", al);
                        p += 2;
+                       TCHECK2(*p, al);
                        if (p + al > endp)
                                goto trunc;
                        while (al-- > 0)