X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f5fe14663d9ed32b7a995ed0924c04e705f74237..69ead2a09cf7d0666c6a7ac12e47fd9743242c61:/util-print.c diff --git a/util-print.c b/util-print.c index 469b8261..113f7846 100644 --- a/util-print.c +++ b/util-print.c @@ -46,6 +46,7 @@ #ifdef HAVE_FCNTL_H #include #endif +#include #include #include #include @@ -56,6 +57,8 @@ #include "timeval-operations.h" int32_t thiszone; /* seconds offset from gmt to local time */ +/* invalid string to print '(invalid)' for malformed or corrupted packets */ +const char istr[] = " (invalid)"; /* * timestamp display buffer size, the biggest size of both formats is needed @@ -65,6 +68,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. @@ -524,7 +544,6 @@ mask2plen(uint32_t mask) return (prefix_len); } -#ifdef INET6 int mask62plen(const u_char *mask) { @@ -551,7 +570,6 @@ mask62plen(const u_char *mask) } return (cidr_len); } -#endif /* INET6 */ /* * Routine to print out information for text-based protocols such as FTP, @@ -765,7 +783,7 @@ txtproto_print(netdissect_options *ndo, const u_char *pptr, u_int len, /* Capitalize the protocol name */ for (pnp = protoname; *pnp != '\0'; pnp++) - ND_PRINT((ndo, "%c", toupper(*pnp))); + ND_PRINT((ndo, "%c", toupper((u_char)*pnp))); if (is_reqresp) { /*