]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
wireshark: Introduce and use vir_val_to_str()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 10 Oct 2025 16:23:18 +0000 (18:23 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 14 Oct 2025 13:08:28 +0000 (15:08 +0200)
Wireshark offers val_to_str() function which converts numeric
value to string by looking up value ('val') in an array ('vs') of
<val, string> pairs. If no corresponding string is found, then
the value is formatted using given 'fmt' string.

Starting from wireshark-4.6.0 not only this function gained
another argument but also returns a strdup()-ed string. To keep
our code simple, let's introduce a wrapper so which can be then
adjusted as needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tools/wireshark/src/packet-libvirt.c

index 6c729801d4055fcbdb971479da9fb9def01706f5..f6ad2c4578d4566431b1f2ade2af6657d5ceb98b 100644 (file)
@@ -140,6 +140,15 @@ static const value_string status_strings[] = {
     { -1, NULL }
 };
 
+static const char *
+G_GNUC_PRINTF(3, 0)
+vir_val_to_str(const uint32_t val,
+               const value_string *vs,
+               const char *fmt)
+{
+    return val_to_str(val, vs, fmt);
+}
+
 static gboolean
 dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf,
                    guint32 maxlen)
@@ -466,14 +475,14 @@ dissect_libvirt_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
     status = tvb_get_ntohil(tvb, offset); offset += 4;
 
     col_add_fstr(pinfo->cinfo, COL_INFO, "Prog=%s",
-                 val_to_str(prog, program_strings, "%x"));
+                 vir_val_to_str(prog, program_strings, "%x"));
 
     vs = get_program_data(prog, VIR_PROGRAM_PROCSTRINGS);
-    col_append_fstr(pinfo->cinfo, COL_INFO, " Proc=%s", val_to_str(proc, vs, "%d"));
+    col_append_fstr(pinfo->cinfo, COL_INFO, " Proc=%s", vir_val_to_str(proc, vs, "%d"));
 
     col_append_fstr(pinfo->cinfo, COL_INFO, " Type=%s Serial=%u Status=%s",
-                    val_to_str(type, type_strings, "%d"), serial,
-                    val_to_str(status, status_strings, "%d"));
+                    vir_val_to_str(type, type_strings, "%d"), serial,
+                    vir_val_to_str(status, status_strings, "%d"));
 
     if (tree) {
         gint *hf_proc;