From Ben Greear: Update to the LANforge dissector to handle newer protocol formats.
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Mar 2010 18:27:40 +0000 (18:27 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Mar 2010 18:27:40 +0000 (18:27 +0000)
   See: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4611
From me:
 - Remove #if 0'd #includes;
 - Use tvb_reported_length_remaining (instead of tvb_length_remaining)
 - Other minor cleanup (including whitespace).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@32319 f5534014-38df-0310-8fa8-9805f1628bb7

AUTHORS
epan/dissectors/packet-lanforge.c

diff --git a/AUTHORS b/AUTHORS
index de14da1c1f4e0b90e13068dfc7a44cc490c2aa95..86390f3abcbebe9559901b202dd096464d713067 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -2991,9 +2991,13 @@ Erwin van Eijk           <erwin.vaneijk [AT] gmail.com> {
 }
 
 Venkateshwaran Dorai   <venkateshwaran.d [AT] gmail.com> {
-       Server/Application State Protocol [SASP] (RFC 4678 )
+       Server/Application State Protocol [SASP] (RFC 4678 ) dissector
 }
        
+Ben Greear             <greearb [AT] candelatech.com> {
+       LANforge dissector
+}
+
 
 and by:
 
index 74699a5c40af7d028337f6fe24cc0b04a0bece67..04f9d65e82240190b7c5a92dbc31a9498a6a4b0b 100644 (file)
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # include "config.h"
 #endif
 
-#if 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#endif
-
 #include <glib.h>
 
 #include <epan/packet.h>
@@ -56,6 +50,8 @@ static int hf_lanforge_crc = -1;
 static int hf_lanforge_magic = -1;
 static int hf_lanforge_src_session = -1;
 static int hf_lanforge_dst_session = -1;
+static int hf_lanforge_pld_len_l = -1;
+static int hf_lanforge_pld_len_h = -1;
 static int hf_lanforge_pld_len = -1;
 static int hf_lanforge_pld_pattern = -1;
 static int hf_lanforge_seq = -1;
@@ -72,84 +68,96 @@ static dissector_handle_t data_handle;
 /* entry point */
 static gboolean dissect_lanforge(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-    proto_item *ti = NULL;
-    proto_item *tmp = NULL;
-    proto_tree *lanforge_tree = NULL;
+    proto_item *ti;
+    proto_item *tmp;
+    proto_tree *lanforge_tree;
     guint32 offset = 0;
     nstime_t tstamp;
     guint32 tss;
+    guint32 tmpi;
+    guint32 pld_len;
 
     /* check for min size */
-    if(tvb_length(tvb) < 28) {         /* Not a LANforge packet. */
-       return FALSE;
+    if(tvb_length(tvb) < 28) {  /* Not a LANforge packet. */
+        return FALSE;
     }
-    
+
     /* check for magic number */
     if(tvb_memeql(tvb, 4, lanforge_magic, 4) == -1) { /* Not a LANforge packet. */
        return FALSE;
     }
-        
+
     /* Make entries in Protocol column and Info column on summary display */
-    
+
     col_set_str(pinfo->cinfo, COL_PROTOCOL, "LANforge");
-    
+
     if(check_col(pinfo->cinfo, COL_INFO)) {
-       col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 16));
+        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 16));
     }
-    
+
     if(tree) {
-       
-       /* create display subtree for the protocol */
-       
-       ti = proto_tree_add_item(tree, proto_lanforge, tvb, 0, -1, FALSE);
-       
-       lanforge_tree = proto_item_add_subtree(ti, ett_lanforge);
-       
-       /* add items to the subtree */
-       
-       proto_tree_add_item(lanforge_tree, hf_lanforge_crc, tvb, offset, 4, FALSE);
-       offset+=4;
+
+        /* create display subtree for the protocol */
+
+        ti = proto_tree_add_item(tree, proto_lanforge, tvb, 0, -1, FALSE);
+
+        lanforge_tree = proto_item_add_subtree(ti, ett_lanforge);
+
+        /* add items to the subtree */
+
+        proto_tree_add_item(lanforge_tree, hf_lanforge_crc, tvb, offset, 4, FALSE);
+        offset+=4;
 
         proto_tree_add_item(lanforge_tree, hf_lanforge_magic, tvb, offset, 4, FALSE);
-       offset+=4;
+        offset+=4;
 
-       proto_tree_add_item(lanforge_tree, hf_lanforge_src_session, tvb, offset, 2, FALSE);
-       offset+=2;
-        
-       proto_tree_add_item(lanforge_tree, hf_lanforge_dst_session, tvb, offset, 2, FALSE);
-       offset+=2;
+        proto_tree_add_item(lanforge_tree, hf_lanforge_src_session, tvb, offset, 2, FALSE);
+        offset+=2;
 
-        proto_tree_add_item(lanforge_tree, hf_lanforge_pld_len, tvb, offset, 2, FALSE);
+        proto_tree_add_item(lanforge_tree, hf_lanforge_dst_session, tvb, offset, 2, FALSE);
         offset+=2;
 
-        proto_tree_add_item(lanforge_tree, hf_lanforge_pld_pattern, tvb, offset, 2, FALSE);
+        pld_len = tvb_get_ntohs(tvb, offset);
+        tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_pld_len_l, tvb, offset, 2, FALSE);
+        PROTO_ITEM_SET_GENERATED(tmp);
         offset+=2;
 
+        tmpi = tvb_get_guint8(tvb, offset);
+        tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_pld_len_h, tvb, offset, 1, FALSE);
+        PROTO_ITEM_SET_GENERATED(tmp);
+        offset+=1;
+        pld_len |= (tmpi << 16);
+
+        proto_tree_add_uint(lanforge_tree, hf_lanforge_pld_len, tvb, offset-3, 3, pld_len);
+
+        proto_tree_add_item(lanforge_tree, hf_lanforge_pld_pattern, tvb, offset, 1, FALSE);
+        offset+=1;
+
         proto_tree_add_item(lanforge_tree, hf_lanforge_seq, tvb, offset, 4, FALSE);
-       offset+=4;
+        offset+=4;
 
         tss = tvb_get_ntohl(tvb, offset);
-       tstamp.secs = tss;
-       tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_s, tvb, offset, 4, FALSE);
-       PROTO_ITEM_SET_GENERATED(tmp);
-       offset+=4;
+        tstamp.secs = tss;
+        tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_s, tvb, offset, 4, FALSE);
+        PROTO_ITEM_SET_GENERATED(tmp);
+        offset+=4;
 
         tss = tvb_get_ntohl(tvb, offset);
-       tstamp.nsecs = tss;
-       tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_ns, tvb, offset, 4, FALSE);
-       PROTO_ITEM_SET_GENERATED(tmp);
-       offset+=4;
+        tstamp.nsecs = tss;
+        tmp = proto_tree_add_item(lanforge_tree, hf_lanforge_tx_time_ns, tvb, offset, 4, FALSE);
+        PROTO_ITEM_SET_GENERATED(tmp);
+        offset+=4;
+
+        proto_tree_add_time(lanforge_tree, hf_lanforge_timestamp, tvb, offset - 8, 8, &tstamp);
 
-       proto_tree_add_time(lanforge_tree, hf_lanforge_timestamp, tvb, offset - 8, 8, &tstamp);
-       
 #if 0
-       if(tvb_length_remaining(tvb, offset)) /* random data */
-           proto_tree_add_text(lanforge_tree, tvb, offset, -1, "Data (%u bytes)",
-                               tvb_length_remaining(tvb, offset));
+        if(tvb_reported_length_remaining(tvb, offset) > 0) /* random data */
+            proto_tree_add_text(lanforge_tree, tvb, offset, -1, "Data (%u bytes)",
+                                tvb_length_remaining(tvb, offset));
 #else
-       if(tvb_length_remaining(tvb, offset)) /* random data */
-           call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo,
-               lanforge_tree);
+        if(tvb_reported_length_remaining(tvb, offset) > 0) /* random data */
+            call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo,
+                lanforge_tree);
 #endif
     }
 
@@ -159,104 +167,120 @@ static gboolean dissect_lanforge(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
 
 /* Register the protocol with Wireshark */
 void proto_register_lanforge(void)
-{                 
+{
     /* Setup list of header fields */
-    
+
     static hf_register_info hf[] = {
-       
-       { &hf_lanforge_crc,
-         { 
-             "CRC", "LANforge.CRC", 
-             FT_UINT32, BASE_HEX, NULL, 0x0, 
-             "The LANforge CRC number", HFILL
-         }
-       },
+
+        { &hf_lanforge_crc,
+          {
+              "CRC", "LANforge.CRC",
+              FT_UINT32, BASE_HEX, NULL, 0x0,
+              "The LANforge CRC number", HFILL
+          }
+        },
 
         { &hf_lanforge_magic,
-         { 
-             "Magic number", "LANforge.magic", 
-             FT_UINT32, BASE_HEX, NULL, 0x0, 
-             "The LANforge magic number", HFILL
-         }
-       },
-
-       { &hf_lanforge_src_session,
-         { 
-             "Source session ID", "LANforge.source-session-id", 
-             FT_UINT16, BASE_DEC, NULL, 0x0, 
-             "The LANforge source session ID", HFILL
-         }
-       },
-        
-       { &hf_lanforge_dst_session,
-         { 
-             "Dest session ID", "LANforge.dest-session-id", 
-             FT_UINT16, BASE_DEC, NULL, 0x0, 
-             "The LANforge dest session ID", HFILL
-         }
-       },
-        
-       { &hf_lanforge_pld_len,
-         { 
-             "Payload Length", "LANforge.pld-length", 
-             FT_UINT16, BASE_DEC, NULL, 0x0, 
-             "The LANforge payload length", HFILL
-         }
-       },
+          {
+              "Magic number", "LANforge.magic",
+              FT_UINT32, BASE_HEX, NULL, 0x0,
+              "The LANforge magic number", HFILL
+          }
+        },
+
+        { &hf_lanforge_src_session,
+          {
+              "Source session ID", "LANforge.source-session-id",
+              FT_UINT16, BASE_DEC, NULL, 0x0,
+              "The LANforge source session ID", HFILL
+          }
+        },
+
+        { &hf_lanforge_dst_session,
+          {
+              "Dest session ID", "LANforge.dest-session-id",
+              FT_UINT16, BASE_DEC, NULL, 0x0,
+              "The LANforge dest session ID", HFILL
+          }
+        },
+
+        { &hf_lanforge_pld_len_l,
+          {
+              "Payload Length(L)", "LANforge.pld-len-L",
+              FT_UINT16, BASE_DEC, NULL, 0x0,
+              "The LANforge payload length (low bytes)", HFILL
+          }
+        },
+
+        { &hf_lanforge_pld_len_h,
+          {
+              "Payload Length(H)", "LANforge.pld-len-H",
+              FT_UINT8, BASE_DEC, NULL, 0x0,
+              "The LANforge payload length (high byte)", HFILL
+          }
+        },
+
+        { &hf_lanforge_pld_len,
+          {
+              "Payload Length", "LANforge.pld-length",
+              FT_UINT32, BASE_DEC, NULL, 0x0,
+              "The LANforge payload length", HFILL
+          }
+        },
 
         { &hf_lanforge_pld_pattern,
-         { 
-             "Payload Pattern", "LANforge.pld-pattern", 
-             FT_UINT16, BASE_DEC, NULL, 0x0, 
-             "The LANforge payload pattern", HFILL
-         }
-       },
-
-       { &hf_lanforge_seq,
-         { 
-             "Sequence Number", "LANforge.seqno", 
-             FT_UINT32, BASE_DEC, NULL, 0x0, 
-             "The LANforge Sequence Number", HFILL
-         }
-       },
-
-       { &hf_lanforge_tx_time_s,
-         { 
-             "Timestamp Secs", "LANforge.ts-secs", 
-             FT_UINT32, BASE_DEC, NULL, 0x0, 
-             "Timestamp secs", HFILL
-         }
-       },
-        
-       { &hf_lanforge_tx_time_ns,
-         { 
-             "Timestamp nsecs", "LANforge.ts-nsecs", 
-             FT_UINT32, BASE_DEC, NULL, 0x0, 
-             NULL, HFILL
-         }
-       },
-
-       { &hf_lanforge_timestamp,
-         { 
-             "Timestamp", "LANforge.timestamp", 
-             FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
-             NULL, HFILL
-         }
-       }
+          {
+              "Payload Pattern", "LANforge.pld-pattern",
+              FT_UINT16, BASE_DEC, NULL, 0x0,
+              "The LANforge payload pattern", HFILL
+          }
+        },
+
+        { &hf_lanforge_seq,
+          {
+              "Sequence Number", "LANforge.seqno",
+              FT_UINT32, BASE_DEC, NULL, 0x0,
+              "The LANforge Sequence Number", HFILL
+          }
+        },
+
+        { &hf_lanforge_tx_time_s,
+          {
+              "Timestamp Secs", "LANforge.ts-secs",
+              FT_UINT32, BASE_DEC, NULL, 0x0,
+              "Timestamp secs", HFILL
+          }
+        },
+
+        { &hf_lanforge_tx_time_ns,
+          {
+              "Timestamp nsecs", "LANforge.ts-nsecs",
+              FT_UINT32, BASE_DEC, NULL, 0x0,
+              NULL, HFILL
+          }
+        },
+
+        { &hf_lanforge_timestamp,
+          {
+              "Timestamp", "LANforge.timestamp",
+              FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
+              NULL, HFILL
+          }
+        }
     };
-       
+
     /* Setup protocol subtree array */
-       
+
     static gint *ett[] = {
-       &ett_lanforge
+        &ett_lanforge
     };
-       
+
     /* Register the protocol name and description */
-       
+
     proto_lanforge = proto_register_protocol("LANforge Traffic Generator", "LANforge", "lanforge");
-       
+
     /* Required function calls to register the header fields and subtrees used */
-       
+
     proto_register_field_array(proto_lanforge, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
 }
@@ -266,7 +290,7 @@ void proto_reg_handoff_lanforge(void)
 {
     /* Register as a heuristic UDP dissector */
     heur_dissector_add("udp", dissect_lanforge, proto_lanforge);
-    heur_dissector_add("tcp", dissect_lanforge, proto_lanforge); 
+    heur_dissector_add("tcp", dissect_lanforge, proto_lanforge);
 
     /* Find data dissector handle */
     data_handle = find_dissector("data");