Ethereal-dev: Re: [ethereal-dev] Exception code checked in

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

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Sun, 14 May 2000 13:19:19 -0700
On Thu, May 11, 2000 at 03:13:23AM -0500, Gilbert Ramirez wrote:
> The FDDI dissector is the only dissector that uses it so far.

The current FDDI dissector, as it extracts the frame control field and
both addresses before building the tree, will give only "[Short Frame:
FDDI]" for a frame without a full FDDI header, even if some of the
fields are there in their entirety.

I've attached a patch that defers extracting fields until they're put
into the tree, although if multiple fields are to be used to generate
the Info column (either in the FDDI dissector or other dissectors that
use the tvbuff stuff), one might also have to build that field in pieces
with "col_append_XXX()" calls so as not to give up if the entire header
isn't present.
Index: packet-fddi.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-fddi.c,v
retrieving revision 1.32
diff -c -r1.32 packet-fddi.c
*** packet-fddi.c	2000/05/11 22:04:16	1.32
--- packet-fddi.c	2000/05/14 20:17:08
***************
*** 257,263 ****
  		gboolean bitswapped)
  {
    int        fc;
!   proto_tree *fh_tree;
    proto_item *ti;
    gchar      *fc_str;
    static u_char src[6], dst[6];
--- 257,263 ----
  		gboolean bitswapped)
  {
    int        fc;
!   proto_tree *fh_tree = NULL;
    proto_item *ti;
    gchar      *fc_str;
    static u_char src[6], dst[6];
***************
*** 268,316 ****
    if (check_col(pinfo->fd, COL_PROTOCOL))
      col_add_str(pinfo->fd, COL_PROTOCOL, "FDDI");
  
-   /* Extract the source and destination addresses, possibly bit-swapping
-      them. */
-   if (bitswapped) {
-     swap_mac_addr(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
-     swap_mac_addr(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
-   } else {
-     memcpy(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6), sizeof dst);
-     memcpy(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6), sizeof src);
-   }
- 
    fc = (int) tvb_get_guint8(tvb, FDDI_P_FC);
    fc_str = fddifc_to_str(fc);
  
    if (check_col(pinfo->fd, COL_INFO))
      col_add_str(pinfo->fd, COL_INFO, fc_str);
  
    /* XXX - copy them to some buffer associated with "pi", rather than
!      just making "src" and "dst" static? */
!   SET_ADDRESS(&pi.dl_src, AT_ETHER, 6, &src[0]);
!   SET_ADDRESS(&pi.src, AT_ETHER, 6, &src[0]);
    SET_ADDRESS(&pi.dl_dst, AT_ETHER, 6, &dst[0]);
    SET_ADDRESS(&pi.dst, AT_ETHER, 6, &dst[0]);
  
!   if (tree) {
! 	ti = proto_tree_add_protocol_format(tree, proto_fddi, tvb, 0, FDDI_HEADER_SIZE,
! 		"Fiber Distributed Data Interface, %s", fc_str);
  
!       swap_mac_addr(dst_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
!       swap_mac_addr(src_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
  
!       fh_tree = proto_item_add_subtree(ti, ett_fddi);
!       proto_tree_add_item(fh_tree, hf_fddi_fc, tvb, FDDI_P_FC, 1, fc);
!       proto_tree_add_item(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst);
        proto_tree_add_item(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src);
-       proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst);
        proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src);
  
        /* hide some bit-swapped mac address fields in the proto_tree, just in case */
-       proto_tree_add_item_hidden(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst_swapped);
        proto_tree_add_item_hidden(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src_swapped);
-       proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst_swapped);
        proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src_swapped);
- 
    }
  
    next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE, -1);
--- 268,326 ----
    if (check_col(pinfo->fd, COL_PROTOCOL))
      col_add_str(pinfo->fd, COL_PROTOCOL, "FDDI");
  
    fc = (int) tvb_get_guint8(tvb, FDDI_P_FC);
    fc_str = fddifc_to_str(fc);
  
    if (check_col(pinfo->fd, COL_INFO))
      col_add_str(pinfo->fd, COL_INFO, fc_str);
  
+   if (tree) {
+     ti = proto_tree_add_protocol_format(tree, proto_fddi, tvb, 0, FDDI_HEADER_SIZE,
+ 		"Fiber Distributed Data Interface, %s", fc_str);
+     fh_tree = proto_item_add_subtree(ti, ett_fddi);
+     proto_tree_add_item(fh_tree, hf_fddi_fc, tvb, FDDI_P_FC, 1, fc);
+   }
+ 
+   /* Extract the destination address, possibly bit-swapping it. */
+   if (bitswapped)
+     swap_mac_addr(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
+   else
+     memcpy(dst, (u_char *) tvb_get_ptr(tvb, FDDI_P_DHOST, 6), sizeof dst);
+   swap_mac_addr(dst_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_DHOST, 6));
+ 
    /* XXX - copy them to some buffer associated with "pi", rather than
!      just making "dst" static? */
    SET_ADDRESS(&pi.dl_dst, AT_ETHER, 6, &dst[0]);
    SET_ADDRESS(&pi.dst, AT_ETHER, 6, &dst[0]);
  
!   if (fh_tree) {
!     proto_tree_add_item(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst);
!     proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst);
! 
!     /* hide some bit-swapped mac address fields in the proto_tree, just in case */
!     proto_tree_add_item_hidden(fh_tree, hf_fddi_dst, tvb, FDDI_P_DHOST, 6, dst_swapped);
!     proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_DHOST, 6, dst_swapped);
!   }
! 
!   /* Extract the source address, possibly bit-swapping it. */
!   if (bitswapped)
!     swap_mac_addr(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
!   else
!     memcpy(src, (u_char *) tvb_get_ptr(tvb, FDDI_P_SHOST, 6), sizeof src);
!   swap_mac_addr(src_swapped, (u_char*) tvb_get_ptr(tvb, FDDI_P_SHOST, 6));
  
!   /* XXX - copy them to some buffer associated with "pi", rather than
!      just making "src" static? */
!   SET_ADDRESS(&pi.dl_src, AT_ETHER, 6, &src[0]);
!   SET_ADDRESS(&pi.src, AT_ETHER, 6, &src[0]);
  
!   if (fh_tree) {
        proto_tree_add_item(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src);
        proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src);
  
        /* hide some bit-swapped mac address fields in the proto_tree, just in case */
        proto_tree_add_item_hidden(fh_tree, hf_fddi_src, tvb, FDDI_P_SHOST, 6, src_swapped);
        proto_tree_add_item_hidden(fh_tree, hf_fddi_addr, tvb, FDDI_P_SHOST, 6, src_swapped);
    }
  
    next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE, -1);