]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add a nd_printjnp() function
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 1 Nov 2020 11:43:37 +0000 (12:43 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 1 Nov 2020 11:50:29 +0000 (12:50 +0100)
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.

netdissect.h
util-print.c

index afa5283d6199d5628e068d1a339024891e0d5124..854fb8a522333cecd8eabd867f71bd4c52b353c0 100644 (file)
@@ -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().
index 2524991b5517e220c90798ebbd965d455792354b..3d3caa5aa79ed0f47fd68f08d40594d051fe342f 100644 (file)
@@ -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)
  */