From: Francois-Xavier Le Bail Date: Fri, 8 Jan 2021 15:09:41 +0000 (+0100) Subject: Add a nd_printjn() function X-Git-Tag: tcpdump-4.99.5~189 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/432c2490b4e9253184909b4055d4fb381b2382b1 Add a nd_printjn() function It prints a counted filename (or other ASCII string), part of the packet buffer, filtering out non-printable characters. Stop if truncated (via GET_U_1/longjmp) or after n bytes, whichever is first. The suffix comes from: j:longJmp, n:after N bytes. (cherry picked from commit 90ddb17d272bbe39dccc08f7b109077b73996fee) --- diff --git a/netdissect.h b/netdissect.h index 9dc70db0..675af511 100644 --- a/netdissect.h +++ b/netdissect.h @@ -443,6 +443,7 @@ extern void fn_print_char(netdissect_options *, u_char); extern void fn_print_str(netdissect_options *, const u_char *); extern u_int nd_printztn(netdissect_options *, const u_char *, u_int, const u_char *); extern int nd_printn(netdissect_options *, const u_char *, u_int, const u_char *); +extern void nd_printjn(netdissect_options *, const u_char *, u_int); extern void nd_printjnp(netdissect_options *, const u_char *, u_int); /* diff --git a/util-print.c b/util-print.c index 05483378..2408c8f4 100644 --- a/util-print.c +++ b/util-print.c @@ -171,6 +171,23 @@ nd_printn(netdissect_options *ndo, return (n == 0) ? 0 : 1; } +/* + * Print a counted filename (or other ASCII string), part of + * the packet buffer, filtering out non-printable characters. + * Stop if truncated (via GET_U_1/longjmp) or after n bytes, + * whichever is first. + * The suffix comes from: j:longJmp, n:after N bytes. + */ +void +nd_printjn(netdissect_options *ndo, const u_char *s, u_int n) +{ + while (n > 0) { + fn_print_char(ndo, GET_U_1(s)); + n--; + s++; + } +} + /* * Print a null-padded filename (or other ASCII string), part of * the packet buffer, filtering out non-printable characters.