X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/91d032ddef9c198e4a78bccebbe33b38b6f5949b..refs/pull/471/head:/util-print.c diff --git a/util-print.c b/util-print.c index cfdcfe8c..bcb14337 100644 --- a/util-print.c +++ b/util-print.c @@ -39,19 +39,20 @@ #include "config.h" #endif -#include +#include #include #ifdef HAVE_FCNTL_H #include #endif +#include #include #include #include #include -#include "interface.h" +#include "netdissect.h" #include "ascii_strcasecmp.h" #include "timeval-operations.h" @@ -65,10 +66,28 @@ 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. * Return true if truncated. + * Stop at ep (if given) or before the null char, whichever is first. */ int fn_print(netdissect_options *ndo, @@ -101,6 +120,7 @@ fn_print(netdissect_options *ndo, * Print out a counted filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. + * Stop at ep (if given) or after n bytes, whichever is first. */ int fn_printn(netdissect_options *ndo, @@ -128,6 +148,8 @@ fn_printn(netdissect_options *ndo, * Print out a null-padded filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. + * Stop at ep (if given) or after n bytes or before the null char, + * whichever is first. */ int fn_printzp(netdissect_options *ndo, @@ -280,14 +302,14 @@ ts_print(netdissect_options *ndo, #else nano_prec = 0; #endif - if (!(tcpdump_timevalisset(&tv_ref))) + if (!(netdissect_timevalisset(&tv_ref))) tv_ref = *tvp; /* set timestamp for first packet */ - negative_offset = tcpdump_timevalcmp(tvp, &tv_ref, <); + negative_offset = netdissect_timevalcmp(tvp, &tv_ref, <); if (negative_offset) - tcpdump_timevalsub(&tv_ref, tvp, &tv_result, nano_prec); + netdissect_timevalsub(&tv_ref, tvp, &tv_result, nano_prec); else - tcpdump_timevalsub(tvp, &tv_ref, &tv_result, nano_prec); + netdissect_timevalsub(tvp, &tv_ref, &tv_result, nano_prec); ND_PRINT((ndo, (negative_offset ? "-" : " "))); @@ -471,7 +493,7 @@ bittok2str(register const struct tok *lp, register const char *fmt, /* * Convert a value to a string using an array; the macro - * tok2strary() in is the public interface to + * tok2strary() in is the public interface to * this function and ensures that the second argument is * correct for bounds-checking. */ @@ -520,7 +542,6 @@ mask2plen(uint32_t mask) return (prefix_len); } -#ifdef INET6 int mask62plen(const u_char *mask) { @@ -547,7 +568,6 @@ mask62plen(const u_char *mask) } return (cidr_len); } -#endif /* INET6 */ /* * Routine to print out information for text-based protocols such as FTP,