]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CDP: Filter out non-printable characters
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 9 Nov 2015 14:59:58 +0000 (15:59 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 9 Nov 2015 15:29:32 +0000 (16:29 +0100)
Add a fn_print_char() to do filtering.

netdissect.h
print-cdp.c
util-print.c

index 47624d19f0ee1213f3fb5a091af05ab2d8cdf7c8..b2f824d3ea37acceeabeb7db5846e3f877f24b9a 100644 (file)
@@ -310,6 +310,7 @@ struct netdissect_options {
 extern void ts_print(netdissect_options *, const struct timeval *);
 extern void relts_print(netdissect_options *, int);
 
+extern void fn_print_char(netdissect_options *, u_char);
 extern int fn_print(netdissect_options *, const u_char *, const u_char *);
 extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *);
 extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *);
index 96ef143b158ec4f2c347a1702290b29e78f042a5..cd544ef5f9f75fccaf6ea2a4eed4304ec2e9852a 100644 (file)
@@ -169,9 +169,11 @@ cdp_print(netdissect_options *ndo,
                        ND_PRINT((ndo, "\n\t  "));
                        for (i=0;i<len;i++) {
                            j = *(tptr+i);
-                           ND_PRINT((ndo, "%c", j));
-                           if (j == 0x0a) /* lets rework the version string to get a nice indentation */
-                               ND_PRINT((ndo, "\t  "));
+                           if (j == '\n') /* lets rework the version string to
+                                             get a nice indentation */
+                               ND_PRINT((ndo, "\n\t  "));
+                           else
+                               fn_print_char(ndo, j);
                        }
                        break;
                    case 0x06: /* Platform */
index f11155ad2eb42664887546c78ae56441346ba781..bcb143373237926029d04ff45e8b2409a4398f56 100644 (file)
@@ -66,6 +66,23 @@ int32_t thiszone;            /* seconds offset from gmt to local time */
 
 #define TOKBUFSIZE 128
 
+/*
+ * Print out a character, filtering out the non-printable ones
+ */
+void
+fn_print_char(netdissect_options *ndo, u_char c)
+{
+       if (!ND_ISASCII(c)) {
+               c = ND_TOASCII(c);
+               ND_PRINT((ndo, "M-"));
+       }
+       if (!ND_ISPRINT(c)) {
+               c ^= 0x40;      /* DEL to ?, others to alpha */
+               ND_PRINT((ndo, "^"));
+       }
+       ND_PRINT((ndo, "%c", c));
+}
+
 /*
  * Print out a null-terminated filename (or other ascii string).
  * If ep is NULL, assume no truncation check is needed.