Wireshark-dev: Re: [Wireshark-dev] How to get a header_field_info instance from its id?
From: Jakub Zawadzki <darkjames-ws@xxxxxxxxxxxx>
Date: Wed, 19 Aug 2015 17:54:44 +0200
Hi,

W dniu 19.08.2015 16:45, yves baumes napisał(a):
My first one would be: how do I get the header_field_info structure
instance from its structure id? Here is what I'm trying to achieve:

static int hf_instr_id = -1;
[...]

    { &hf_instr_id,
      { "Instrument Identifier", "my_proto.instr_id", FT_UINT64,
BASE_DEC, NULL, 0x00,
        "[...]", HFILL }
    },

[...]
    ptvcursor_add(cursor, hf_instr_id, 8, ENC_LITTLE_ENDIAN);


In the line just above I'd like to replace the length (which is 8) by
something roughly looking like that:

    int len = ftype_len(gap_hfinfo.hfi[xxx]->type);
    ptvcursor_add(cursor, hf_instr_id, len, ENC_LITTLE_ENDIAN);

One of my issue is that gap_hfinfo array (which contains all the
header_fields_info instances) is static to the proto.c file. And I
find no accessors to it.
Is there an actual way that I've overlooked?

/** Get the header_field information based upon a field or protocol id.
 @param hfindex item # n (0-indexed)
 @return the registered item */
WS_DLL_PUBLIC header_field_info* proto_registrar_get_nth(guint hfindex);


btw. there is also a proto_registrar_get_length() function,
which do what you want (ftype_len(...)->type).

Cheers,
Jakub.