]> 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]>
Thu, 12 Oct 2023 17:22:30 +0000 (19:22 +0200)
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)

netdissect.h
util-print.c

index 9dc70db0a0fd02d15da535aad0651b566905e03b..675af5112cf39cf1ab5574b9e0e35d79ad364c4c 100644 (file)
@@ -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);
 
 /*
index 0548337860eee16e7666150390076c0b3295b156..2408c8f4b7f0a21444847971f303cab08809322e 100644 (file)
@@ -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.