]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cdp.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-cdp.c
index d3bce2e9caa2b91390461ffda5f49bb0d84861d4..0f36337bc03e3e5942c1007ae225bd2ff6dbc043 100644 (file)
@@ -26,9 +26,7 @@
 
 /* \summary: Cisco Discovery Protocol (CDP) printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
@@ -213,7 +211,7 @@ struct cdp_tlvinfo {
 static const struct cdp_tlvinfo cdptlvs[] = {
        /* 0x00 */
        [ 0x01 ] = { "Device-ID", cdp_print_string, VERBOSE_OR_NOT_VERBOSE, -1, -1 },
-       [ 0x02 ] = { "Address", cdp_print_addr, VERBOSE_ONLY, -1, -1 },
+       [ 0x02 ] = { "Address", cdp_print_addr, VERBOSE_ONLY, 4, -1 },
        [ 0x03 ] = { "Port-ID", cdp_print_string, VERBOSE_ONLY, -1, -1 },
        [ 0x04 ] = { "Capability", cdp_print_capability, VERBOSE_ONLY, 4, 4 },
        [ 0x05 ] = { "Version String", cdp_print_version, VERBOSE_ONLY, -1, -1 },
@@ -297,7 +295,7 @@ cdp_print(netdissect_options *ndo,
                    (info ? (info->when_to_print == VERBOSE_OR_NOT_VERBOSE) : 0);
                if (len < CDP_TLV_HEADER_LEN) {
                        if (ndo->ndo_vflag)
-                               ND_PRINT("\n\t%s (0x%02x), TLV length: %u byte%s (too short)",
+                               ND_PRINT("\n\t%s (0x%04x), TLV length: %u byte%s (too short)",
                                         name, type, len, PLURAL_SUFFIX(len));
                        else
                                ND_PRINT(", %s TLV length %u too short",
@@ -314,7 +312,7 @@ cdp_print(netdissect_options *ndo,
 
                if (ndo->ndo_vflag) {
                        /* Print all TLVs when in verbose mode */
-                       ND_PRINT("\n\t%s (0x%02x), value length: %u byte%s: ",
+                       ND_PRINT("\n\t%s (0x%04x), value length: %u byte%s: ",
                                 name, type, len, PLURAL_SUFFIX(len));
                } else {
                        /* Print only some TLVs when not in verbose mode */
@@ -375,10 +373,6 @@ cdp_print_addr(netdissect_options *ndo,
                0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
        };
 
-       if (l < 4) {
-               ND_PRINT(" (not enough space for num)");
-               goto invalid;
-       }
        num = GET_BE_U_4(p);
        p += 4;
        l -= 4;
@@ -419,8 +413,7 @@ cdp_print_addr(netdissect_options *ndo,
                        ND_PRINT("IPv4 (%u) %s", num, GET_IPADDR_STRING(p));
                        p += al;
                        l -= al;
-               }
-               else if (pt == PT_IEEE_802_2 && pl == 8 &&
+               } else if (pt == PT_IEEE_802_2 && pl == 8 &&
                         memcmp(p, prot_ipv6, 8) == 0 && al == 16) {
                        /*
                         * IPv6: protocol type = IEEE 802.2 header,
@@ -438,8 +431,7 @@ cdp_print_addr(netdissect_options *ndo,
                        ND_PRINT("IPv6 (%u) %s", num, GET_IP6ADDR_STRING(p));
                        p += al;
                        l -= al;
-               }
-               else {
+               } else {
                        /*
                         * Generic case: just print raw data
                         */
@@ -488,7 +480,7 @@ cdp_print_prefixes(netdissect_options *ndo,
 
        ND_PRINT(" IPv4 Prefixes (%u):", l / 5);
 
-       while (l > 0) {
+       while (l != 0) {
                ND_PRINT(" %u.%u.%u.%u/%u",
                         GET_U_1(p), GET_U_1(p + 1), GET_U_1(p + 2),
                         GET_U_1(p + 3), GET_U_1(p + 4));