From: Francois-Xavier Le Bail Date: Sun, 1 Nov 2020 11:43:37 +0000 (+0100) Subject: Add a nd_printjnp() function X-Git-Tag: tcpdump-4.99-bp~77 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/635e3cc92b72ca048a6b5b89b883980e4e1b4bdc Add a nd_printjnp() function It prints a null-padded 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 or before the null char, whichever occurs first. The suffix comes from: j:longJmp, n:after N bytes, p:null-Padded. --- diff --git a/netdissect.h b/netdissect.h index afa5283d..854fb8a5 100644 --- a/netdissect.h +++ b/netdissect.h @@ -395,6 +395,7 @@ extern int nd_print(netdissect_options *, const u_char *, 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 int nd_printzp(netdissect_options *, const u_char *, u_int, const u_char *); +extern void nd_printjnp(netdissect_options *, const u_char *, u_int); /* * Flags for txtproto_print(). diff --git a/util-print.c b/util-print.c index 2524991b..3d3caa5a 100644 --- a/util-print.c +++ b/util-print.c @@ -228,6 +228,28 @@ nd_printzp(netdissect_options *ndo, return (n == 0) ? 0 : ret; } +/* + * Print a null-padded 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 or before + * the null char, whichever occurs first. + * The suffix comes from: j:longJmp, n:after N bytes, p:null-Padded. + */ +void +nd_printjnp(netdissect_options *ndo, const u_char *s, u_int n) +{ + u_char c; + + while (n > 0) { + c = GET_U_1(s); + if (c == '\0') + break; + fn_print_char(ndo, c); + n--; + s++; + } +} + /* * Print the timestamp .FRAC part (Microseconds/nanoseconds) */