From 3fd5ba0cf280b615ed06a4503015dd969240a3a5 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 7 Feb 2024 21:33:02 +0100 Subject: [PATCH] fmt/text2pcap: add re_text2pcap_trace helper --- include/re_fmt.h | 3 ++- src/fmt/text2pcap.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/re_fmt.h b/include/re_fmt.h index 33580a2b8..0645e28f1 100644 --- a/include/re_fmt.h +++ b/include/re_fmt.h @@ -209,7 +209,8 @@ size_t utf8_byteseq(char u[4], unsigned cp); struct re_text2pcap { bool in; const struct mbuf *mb; - char *id; + const char *id; }; int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap); +void re_text2pcap_trace(const char *id, bool in, const struct mbuf *mb); diff --git a/src/fmt/text2pcap.c b/src/fmt/text2pcap.c index f95cd8c68..249626ce3 100644 --- a/src/fmt/text2pcap.c +++ b/src/fmt/text2pcap.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap) @@ -29,3 +31,21 @@ int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap) return 0; } + + +void re_text2pcap_trace(const char *id, bool in, const struct mbuf *mb) +{ + struct re_text2pcap pcap = {.in = in, .mb = mb, .id = id}; + size_t pcap_buf_sz = (mbuf_get_left(mb) * 3) + 64; + + char *pcap_buf = mem_alloc(pcap_buf_sz, NULL); + if (!pcap_buf) + return; + + re_snprintf(pcap_buf, pcap_buf_sz, "%H", re_text2pcap, &pcap); + + re_trace_event("pcap", id, 'I', NULL, RE_TRACE_ARG_STRING_COPY, "pcap", + pcap_buf); + + mem_deref(pcap_buf); +}