Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks for the advice Chuck - using BASE_CUSTOM was exactly what I needed!

A little convoluted but I found a good example of what I needed to implement in one of the GSM Abis dissectors (epan/dissectors/packet-gsm_abis_oml.c) .

I created five new functions - one each to handle bytes (0x%02X) & words (0x%04X), and then three to handle outputs that included value strings.

Revisiting my original example, I now call print_dmx_message which both prints out the message name and also prints the message number in upper case hex:

static void
print_dmx_message(gchar *result, guint16 message_number )
{
    /* print message name and number 0xABCD (or 0x000A, etc.) */
    const gchar *tmp = NULL;

    tmp = try_val_to_str(message_number, dmxMessageNumber);
    if (tmp)
    {
        g_snprintf(result, ITEM_LABEL_LENGTH, "%s (0x%04X)",
                   tmp,message_number);
    }
    else
    {
        g_snprintf(result, ITEM_LABEL_LENGTH, "Unknown (0x%04X)",
                   message_number);
    }
}

...
        { &hf_emb_msg_header_t_number,
            {"DMX message number", "emb.dmx.number",
                FT_UINT16, BASE_CUSTOM, CF_FUNC(print_dmx_message), 0x0,
                "DX message number (message_number_t)", HFILL}},

Thanks for the advice Chuck - using BASE_CUSTOM BASE_CUSTOM was exactly what I needed!

A little convoluted but I found a good example of what I needed to implement in one of the GSM Abis dissectors (epan/dissectors/packet-gsm_abis_oml.c) .

I created five new functions - one each to handle bytes (0x%02X) (0x%02X) & words (0x%04X), (0x%04X), and then three to handle outputs that included value strings.

Revisiting my original example, I now call print_dmx_message which both prints out the message name and also prints the message number in upper case hex:

static void
print_dmx_message(gchar *result, guint16 message_number )
{
    /* print message name and number 0xABCD (or 0x000A, etc.) */
    const gchar *tmp = NULL;

    tmp = try_val_to_str(message_number, dmxMessageNumber);
    if (tmp)
    {
        g_snprintf(result, ITEM_LABEL_LENGTH, "%s (0x%04X)",
                   (0x%04X)", tmp,message_number);
    }
    else
    {
        g_snprintf(result, ITEM_LABEL_LENGTH, "Unknown (0x%04X)",
                   (0x%04X)", message_number);
    }
}

} 
    ...
         { &hf_emb_msg_header_t_number,
             {"DMX message number", "emb.dmx.number",
                 FT_UINT16, BASE_CUSTOM, CF_FUNC(print_dmx_message), 0x0,
                 "DX message number (message_number_t)", HFILL}},