]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cdp.c
Use more the ND_TTEST_1() macro
[tcpdump] / print-cdp.c
index fcdd63dc20ed6e07dc28dc2307eb808862e71988..bf8262656003201db9e73fa6fdfd43ebf6a6c9c3 100644 (file)
@@ -104,7 +104,7 @@ cdp_print(netdissect_options *ndo,
 
        tptr = pptr; /* temporary pointer */
 
-       ND_TCHECK2(*tptr, CDP_HEADER_LEN);
+       ND_TCHECK_LEN(tptr, CDP_HEADER_LEN);
        ND_PRINT((ndo, "CDPv%u, ttl: %us", EXTRACT_U_1((tptr + CDP_HEADER_VERSION_OFFSET)),
                                           EXTRACT_U_1(tptr + CDP_HEADER_TTL_OFFSET)));
        if (ndo->ndo_vflag)
@@ -112,7 +112,7 @@ cdp_print(netdissect_options *ndo,
        tptr += CDP_HEADER_LEN;
 
        while (tptr < (pptr+length)) {
-               ND_TCHECK2(*tptr, CDP_TLV_HEADER_LEN); /* read out Type and Length */
+               ND_TCHECK_LEN(tptr, CDP_TLV_HEADER_LEN); /* read out Type and Length */
                type = EXTRACT_BE_U_2(tptr + CDP_TLV_TYPE_OFFSET);
                len  = EXTRACT_BE_U_2(tptr + CDP_TLV_LEN_OFFSET); /* object length includes the 4 bytes header length */
                if (len < CDP_TLV_HEADER_LEN) {
@@ -131,7 +131,7 @@ cdp_print(netdissect_options *ndo,
                tptr += CDP_TLV_HEADER_LEN;
                len -= CDP_TLV_HEADER_LEN;
 
-               ND_TCHECK2(*tptr, len);
+               ND_TCHECK_LEN(tptr, len);
 
                if (ndo->ndo_vflag || type == 1) { /* in non-verbose mode just print Device-ID */
 
@@ -202,7 +202,7 @@ cdp_print(netdissect_options *ndo,
                    case 0x0b: /* Duplex - CDPv2 */
                        if (len < 1)
                            goto trunc;
-                       ND_PRINT((ndo, "%s", *(tptr) ? "full": "half"));
+                       ND_PRINT((ndo, "%s", EXTRACT_U_1(tptr) ? "full": "half"));
                        break;
 
                    /* http://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cata/186/2_12_m/english/release/notes/186rn21m.html
@@ -224,12 +224,12 @@ cdp_print(netdissect_options *ndo,
                    case 0x12: /* AVVID trust bitmap - not documented */
                        if (len < 1)
                            goto trunc;
-                       ND_PRINT((ndo, "0x%02x", *(tptr)));
+                       ND_PRINT((ndo, "0x%02x", EXTRACT_U_1(tptr)));
                        break;
                    case 0x13: /* AVVID untrusted port CoS - not documented */
                        if (len < 1)
                            goto trunc;
-                       ND_PRINT((ndo, "0x%02x", *(tptr)));
+                       ND_PRINT((ndo, "0x%02x", EXTRACT_U_1(tptr)));
                        break;
                    case 0x14: /* System Name - not documented */
                        ND_PRINT((ndo, "'"));
@@ -243,7 +243,7 @@ cdp_print(netdissect_options *ndo,
                    case 0x17: /* Physical Location - not documented */
                        if (len < 1)
                            goto trunc;
-                       ND_PRINT((ndo, "0x%02x", *(tptr)));
+                       ND_PRINT((ndo, "0x%02x", EXTRACT_U_1(tptr)));
                        if (len > 1) {
                                ND_PRINT((ndo, "/"));
                                (void)fn_printn(ndo, tptr + 1, len - 1, NULL);
@@ -295,8 +295,8 @@ cdp_print_addr(netdissect_options *ndo,
                ND_TCHECK_2(p);
                if (p + 2 > endp)
                        goto trunc;
-               pt = p[0];              /* type of "protocol" field */
-               pl = p[1];              /* length of "protocol" field */
+               pt = EXTRACT_U_1(p);            /* type of "protocol" field */
+               pl = EXTRACT_U_1(p + 1);                /* length of "protocol" field */
                p += 2;
 
                ND_TCHECK_2(p + pl);
@@ -304,7 +304,8 @@ cdp_print_addr(netdissect_options *ndo,
                        goto trunc;
                al = EXTRACT_BE_U_2(p + pl);    /* address length */
 
-               if (pt == PT_NLPID && pl == 1 && *p == NLPID_IP && al == 4) {
+               if (pt == PT_NLPID && pl == 1 && EXTRACT_U_1(p) == NLPID_IP &&
+                   al == 4) {
                        /*
                         * IPv4: protocol type = NLPID, protocol length = 1
                         * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
@@ -327,7 +328,7 @@ cdp_print_addr(netdissect_options *ndo,
                         * Ethertype, address length = 16
                         */
                        p += 10;
-                       ND_TCHECK2(*p, al);
+                       ND_TCHECK_LEN(p, al);
                        if (p + al > endp)
                                goto trunc;
 
@@ -338,7 +339,7 @@ cdp_print_addr(netdissect_options *ndo,
                        /*
                         * Generic case: just print raw data
                         */
-                       ND_TCHECK2(*p, pl);
+                       ND_TCHECK_LEN(p, pl);
                        if (p + pl > endp)
                                goto trunc;
                        ND_PRINT((ndo, "pt=0x%02x, pl=%d, pb=", EXTRACT_U_1((p - 2)), pl));
@@ -351,7 +352,7 @@ cdp_print_addr(netdissect_options *ndo,
                                goto trunc;
                        ND_PRINT((ndo, ", al=%d, a=", al));
                        p += 2;
-                       ND_TCHECK2(*p, al);
+                       ND_TCHECK_LEN(p, al);
                        if (p + al > endp)
                                goto trunc;
                        while (al-- > 0) {