Ethereal-dev: [Ethereal-dev] question on tvbuff composite

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Anand V. Narwani" <anarwani@xxxxxxxxx>
Date: Tue, 25 Feb 2003 10:18:39 -0500
Folks,
I am attempting to write a dissector for the Dynamic Channel Change messages in DOCSIS.  The DCC request message contains a number of Type/Length/Value fields.  One of the types that may be present is an Upstream Channel Descriptor Message (for which there is already a dissector written).  The problem is that the length field is only one byte long so that if a UCD message is greater than 254 bytes, it must be split into multiple TLV Values.
My solution was to use a tvbuff composite type to dissect the message:

tvbuff *ucd_message = NULL;

static void
append_to_ucdsubst_tvbuff (tvbuff_t * tvb, guint16 start, guint16 len)
{
    tvbuff_t *msg_frag;
    /* check to see if ucd_message is NULL.  if so
     * then create a new composite tvbuff */
    if ( ucd_message == NULL)
    {
        ucd_message = tvb_new_composite();
    }
    msg_frag = tvb_new_subset(tvb, start, len, len);
    tvb_composite_append(ucd_message, msg_frag);

}

static void
dissect_dccreq (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
{
<snip>
/* pos is the current position in the message */
/* tlv_data_len is the total length of the TLV data */
      while (pos < tlv_data_len) {
        type = tvb_get_guint8 (tvb, pos++);
        length = tvb_get_guint8 (tvb, pos++);
        switch(type) {
                <snip>
                case UCD_SUBSITUTION:
                        append_to_tvbuff_composite(tvb, pos, length);
                <snip>
        }
        pos += length;
        }
      /* the entire TLV block is dissected, so we have all fragments */
      if (ucd_message != NULL)
      {
        tvb_composite_finalize(ucd_message);
        call_dissector (docsis_ucd_handle, ucd_message, pinfo, dccreq_tree);
      }
}

Since I can find no other uses of Composite TVBuff's and I am running into some issues testing this code, I am asking that you code review this and let me know if there are any reasons why this may not work.

Thanks in advance,
Anand

--
          .
          |___
         (}o o{)
-------ooO-(_)-Ooo-------
Anand V. Narwani,  CCIE 3892
Advanced Engineering Services   
Cisco Systems, Inc.
Direct/Fax: 919.392.3404