This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

how to display character value for a field in my protocol dissection ?i am getting the decimal value ,but want to convert to a character..plz explain

asked 27 May '13, 03:37

ajain's gravatar image

ajain
146711
accept rate: 0%

edited 27 May '13, 04:46


Use FT_STRING field type. Here is an example taken from doc/README.developer:

static hf_register_info hf[] = {
    {&hf_cstring,
     {"C String", "c.string", FT_STRING, BASE_NONE, NULL, 0x0,
      NULL, HFILL}
     }
   };

/**
*   Dissect a buffer containing ASCII C strings.
*
*   @param  tvb     The buffer to dissect.
*   @param  pinfo   Packet Info.
*   @param  tree    The protocol tree.
**/
static void dissect_cstr(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
{
    guint offset = 0;
    while(offset < tvb_reported_length(tvb)) {
        gint available = tvb_reported_length_remaining(tvb, offset);
        gint len = tvb_strnlen(tvb, offset, available);

        if( -1 == len ) {
            /* we ran out of data: ask for more */
            pinfo->desegment_offset = offset;
            pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
            return;
        }

        col_set_str(pinfo->cinfo, COL_INFO, "C String");

        len += 1; /* Add one for the '\0' */

        if (tree) {
            proto_tree_add_item(tree, hf_cstring, tvb, offset, len,
                ENC_ASCII|ENC_NA);
        }
        offset += (guint)len;
    }

    /* if we get here, then the end of the tvb coincided with the end of a
       string. Happy days. */
}

See doc/README.developer or search for FT_STRING usage in the source code for more information.

permanent link

answered 27 May '13, 05:10

Pascal%20Quantin's gravatar image

Pascal Quantin
5.5k1060
accept rate: 30%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×16

question asked: 27 May '13, 03:37

question was seen: 3,346 times

last updated: 04 Jun '13, 01:16

p​o​w​e​r​e​d by O​S​Q​A