This is a static, read-only archive of Wireshark Q&A. Older questions and answers from October 2017 and earlier can be found at osqa-ask.wireshark.org.
0

Custom display field for text-based protocol

asked Oct 14 '25

updated Oct 14 '25

I’m writing a dissector for a text-based protocol. There’re fields that identify peers, the fields are N-digit strings (say, 00123, 45678, 00000). Certain peer identifiers have custom meanings, for the rest it is conventional for human-readable stuff to use just the numbers, without leading zeros.

So, I need to make Wireshark display value of such a field in one of two formats:

  • custom strings (for certain values);
  • integers with leading zeros stripped (say, 123 instead of 00123, but 45678 is still 45678).

In fact, I already do such conversion myself (with a custom function) in the dissector to build a COL_INFO string and for proto_item_append_text() which is then used as a root for the rest of fields displayed.

But I can’t seem to understand the right way to declare a header_field_info struct that would let me apply such custom formatting. Right now I managed to display the fields with FT_STRING but then I have all N characters shown, according to the length parameter of proto_tree_add_item.

Reading the source code, seems like custom formatters are not applicable to FT_STRING fields, nor to any other arbitrary-length fields.

What is the recommended way to solve the problem?

1 Answer

0

answered Oct 14 '25

Assuming thar your numbers fit in an appropriate size integer, I would declare a FT_UINT32 or whatever with the BASE_SPECIAL_VALS property and a value string containing the special values. Then convert your string to an integer manually, and call proto_tree_add_uint

cc-by-sa Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.