Ask Your Question

Revision history [back]

ASCII to Integer in Dissector

I'm trying to write a dissector whose packets contain ASCII characters "00581804..." and I would like to grab them and convert them to integers so that my field types can be UINT32s. I'd like to grab 0058 (0x30303538) and convert it to 58 (0x3A). My code looks like the following:

static hf_register_info hf[] = {
        { &hf_foo, //- The index for this node.
            { "FOO Field Title", "foo",
            FT_UINT32, BASE_DEC,
            NULL, 0x0,
            NULL, HFILL }
static int dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_) {
    proto_tree_add_item(foo_tree, hf_foo, tvb, offset, 4, ENC_ASCII);

except it prints out 808465720 (the decimal equivalent of 0x30303538). Is there anyway for the proto_tree_add_item() function (or a similar tree add) to parse an ascii string but pass it to the formatting as an integer or other numerical value? Ideally I'd like to return or store this value for later use as well.