X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/3824a6c0417a551961d1a1bf4f94f10eff736afc..39d15607cad1b4b463794c1a67873f6182dc52f7:/print-cdp.c diff --git a/print-cdp.c b/print-cdp.c index 2e605fd3..5383fd50 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -24,7 +24,6 @@ * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -37,14 +36,13 @@ #include "interface.h" #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ +#include "nlpid.h" + +static const char tstr[] = "[|cdp]"; -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.20 2003-11-15 00:39:17 guy Exp $"; -#endif #define CDP_HEADER_LEN 4 -static struct tok cdp_tlv_values[] = { +static const struct tok cdp_tlv_values[] = { { 0x01, "Device-ID"}, { 0x02, "Address"}, { 0x03, "Port-ID"}, @@ -69,7 +67,7 @@ static struct tok cdp_tlv_values[] = { { 0, NULL} }; -static struct tok cdp_capability_values[] = { +static const struct tok cdp_capability_values[] = { { 0x01, "Router" }, { 0x02, "Transparent Bridge" }, { 0x04, "Source Route Bridge" }, @@ -91,7 +89,7 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) const u_char *tptr; if (caplen < CDP_HEADER_LEN) { - (void)printf("[|cdp]"); + printf("%s", tstr); return; } @@ -99,9 +97,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)) { @@ -123,22 +121,25 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) tok2str(cdp_tlv_values,"unknown field type", type), type, len, - len>1 ? "s" : ""); /* plural */ + PLURAL_SUFFIX(len)); /* plural */ switch (type) { case 0x01: /* Device-ID */ if (!vflag) - printf(", Device-ID '%.*s'", len, tptr); - else - printf("'%.*s'", len, tptr); + printf(", Device-ID "); + printf("'"); + fn_printn(tptr, len, NULL); + printf("'"); break; case 0x02: /* Address */ if (cdp_print_addr(tptr, len) < 0) goto trunc; break; case 0x03: /* Port-ID */ - printf("'%.*s'", len, tptr); + printf("'"); + fn_printn(tptr, len, NULL); + printf("'"); break; case 0x04: /* Capabilities */ printf("(0x%08x): %s", @@ -155,7 +156,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) } break; case 0x06: /* Platform */ - printf("'%.*s'", len, tptr); + printf("'"); + fn_printn(tptr, len, NULL); + printf("'"); break; case 0x07: /* Prefixes */ if (cdp_print_prefixes(tptr, len) < 0) @@ -164,7 +167,9 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) case 0x08: /* Protocol Hello Option - not documented */ break; case 0x09: /* VTP Mgmt Domain - not documented */ - printf("'%.*s'", len,tptr); + printf("'"); + fn_printn(tptr, len, NULL); + printf("'"); break; case 0x0a: /* Native VLAN ID - not documented */ printf("%d",EXTRACT_16BITS(tptr)); @@ -194,17 +199,23 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) printf("0x%02x", *(tptr)); break; case 0x14: /* System Name - not documented */ - printf("'%.*s'", len, tptr); + printf("'"); + fn_printn(tptr, len, NULL); + printf("'"); break; case 0x16: /* System Object ID - not documented */ if (cdp_print_addr(tptr, len) < 0) goto trunc; break; case 0x17: /* Physical Location - not documented */ - printf("0x%02x/%.*s", *(tptr), len - 1, tptr + 1 ); + printf("0x%02x", *(tptr)); + if (len > 1) { + printf("/"); + fn_printn(tptr + 1, len - 1, NULL); + } break; default: - print_unknown_data(tptr,"\n\t ",len); + print_unknown_data(gndo,tptr,"\n\t ",len); break; } } @@ -213,9 +224,12 @@ 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]"); + printf("%s", tstr); } /* @@ -235,26 +249,29 @@ cdp_print_addr(const u_char * p, int l) int pt, pl, al, num; const u_char *endp = p + l; #ifdef INET6 - static u_char prot_ipv6[] = { + static const u_char prot_ipv6[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd }; #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 +279,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 +297,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 +311,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)