]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add a nd_printjn() function
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 8 Jan 2021 15:09:41 +0000 (16:09 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 8 Jan 2021 15:09:41 +0000 (16:09 +0100)
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.

netdissect.h
util-print.c

index 1f8efc803618970ab90dc056a4b2de5d4b160a24..44d4df0fcde7455606f765a989f19f8881afc572 100644 (file)
@@ -394,6 +394,7 @@ extern void fn_print_str(netdissect_options *, const u_char *);
 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 void nd_printjn(netdissect_options *, const u_char *, u_int);
 extern void nd_printjnp(netdissect_options *, const u_char *, u_int);
 
 /*
index f9ea618d1a4dce8823d01e31ab3862985c3f0656..5424c20e6a9e65cf6759a9b6a7695e908517a601 100644 (file)
@@ -198,6 +198,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.