From Ulf Lamping: extend the progress dialog box to give more progress
[obnox/wireshark/wip.git] / packet-wcp.c
index 505682aa01d247493d396a484bb5fa9f757fbc9b..8527b2b2934c38d6865806665c9154aadee58768 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for Wellfleet Compression frame disassembly
  * Copyright 2001, Jeffrey C. Foster <jfoste@woodward.com>
  *
- * $Id: packet-wcp.c,v 1.17 2001/11/30 04:39:45 guy Exp $
+ * $Id: packet-wcp.c,v 1.27 2002/08/02 23:36:04 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <stdio.h>
 #include <glib.h>
 #include <string.h>
-#include "packet.h"
+#include <epan/packet.h>
 #include "packet-frame.h"
-#include "conversation.h"
+#include <epan/conversation.h>
 #include "etypes.h"
 #include "nlpid.h"
 
@@ -174,7 +170,7 @@ static int hf_wcp_offset = -1;
 static gint ett_wcp = -1;
 static gint ett_wcp_field = -1;
 
-static dissector_handle_t fr_handle;
+static dissector_handle_t fr_uncompressed_handle;
 
 /*
  * Bits in the address field.
@@ -223,7 +219,7 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
 static wcp_window_t *get_wcp_window_ptr( packet_info *pinfo);
 
 static void
-dissect_wcp_con_req(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
+dissect_wcp_con_req(tvbuff_t *tvb, int offset, proto_tree *tree) {
 
 /* WCP connector request message */
 
@@ -244,7 +240,7 @@ dissect_wcp_con_req(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *t
 }
 
 static void
-dissect_wcp_con_ack( tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree){
+dissect_wcp_con_ack( tvbuff_t *tvb, int offset, proto_tree *tree){
 
 /* WCP connector ack message */
 
@@ -255,7 +251,7 @@ dissect_wcp_con_ack( tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *
 }
 
 static void
-dissect_wcp_init( tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree){
+dissect_wcp_init( tvbuff_t *tvb, int offset, proto_tree *tree){
 
 /* WCP Initiate Request/Ack message */
 
@@ -268,7 +264,7 @@ dissect_wcp_init( tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tre
 
 
 static void
-dissect_wcp_reset( tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree){
+dissect_wcp_reset( tvbuff_t *tvb, int offset, proto_tree *tree){
 
 /* Process WCP Reset Request/Ack message */
 
@@ -308,10 +304,10 @@ static void dissect_wcp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
        guint16         temp, cmd, ext_cmd, seq;
        tvbuff_t        *next_tvb;
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "WCP");
-       if (check_col(pinfo->fd, COL_INFO))
-               col_clear(pinfo->fd, COL_INFO);
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "WCP");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
 
        temp =tvb_get_ntohs(tvb, 0); 
 
@@ -327,10 +323,10 @@ static void dissect_wcp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
 
 /*XXX should test seq to be sure it the last + 1 !! */
 
-       if (check_col(pinfo->fd, COL_INFO)){
-               col_add_str(pinfo->fd, COL_INFO, val_to_str(cmd, cmd_string, "Unknown"));
+       if (check_col(pinfo->cinfo, COL_INFO)){
+               col_add_str(pinfo->cinfo, COL_INFO, val_to_str(cmd, cmd_string, "Unknown"));
                if ( cmd == 0xf)
-                       col_append_fstr(pinfo->fd, COL_INFO, ", %s",
+                       col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
                                val_to_str(ext_cmd, ext_cmd_string, "Unknown"));
        }       
 
@@ -345,19 +341,19 @@ static void dissect_wcp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
                                        tvb_get_guint8( tvb, 0));
                        switch (ext_cmd){
                        case CONNECT_REQ:
-                               dissect_wcp_con_req( tvb, 1, pinfo, wcp_tree);
+                               dissect_wcp_con_req( tvb, 1, wcp_tree);
                                break;
 
                        case CONNECT_ACK:
-                               dissect_wcp_con_ack( tvb, 1, pinfo, wcp_tree);
+                               dissect_wcp_con_ack( tvb, 1, wcp_tree);
                                break;
                        case INIT_REQ:
                        case INIT_ACK:
-                               dissect_wcp_init( tvb, 1, pinfo, wcp_tree);
+                               dissect_wcp_init( tvb, 1, wcp_tree);
                                break;
                        case RESET_REQ:
                        case RESET_ACK:
-                               dissect_wcp_reset( tvb, 1, pinfo, wcp_tree);
+                               dissect_wcp_reset( tvb, 1, wcp_tree);
                                break;
                        default:
                                break;
@@ -397,13 +393,13 @@ static void dissect_wcp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
                        tvb_reported_length( tvb)-1, 1,
                        tvb_get_guint8( tvb, tvb_reported_length(tvb)-1));
 
-       call_dissector(fr_handle, next_tvb, pinfo, tree);
+       call_dissector(fr_uncompressed_handle, next_tvb, pinfo, tree);
 
        return;
 }
 
 
-guint8 *decompressed_entry( guint8 *src, guint8 *dst, int *len, guint8 * buf_start, guint8 *buf_end){
+static guint8 *decompressed_entry( guint8 *src, guint8 *dst, int *len, guint8 * buf_start, guint8 *buf_end){
 
 /* do the decompression for one field */
 
@@ -498,6 +494,14 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
        buf_end = buf_start + MAX_WIN_BUF_LEN;
        tmp = buf_ptr->buf_cur;
 
+       if (cnt - offset > MAX_WCP_BUF_LEN) {
+               if (tree)
+                       proto_tree_add_text( tree, src_tvb, offset, -1,
+                               "Compressed data exceeds maximum buffer length (%d > %d)",
+                               cnt - offset, MAX_WCP_BUF_LEN);
+               return NULL;
+       }
+
        src = tvb_memcpy(src_tvb, src_buf, offset, cnt - offset);
        dst = buf_ptr->buf_cur;
 
@@ -584,17 +588,17 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
 
 
         TRY {
-                tvb = tvb_new_real_data( pdata_ptr->buffer, pdata_ptr->len, pdata_ptr->len, "uncompressed");
+                tvb = tvb_new_real_data( pdata_ptr->buffer, pdata_ptr->len, pdata_ptr->len);
 
         }
         CATCH(BoundsError) {
-                g_assert_not_reached();
+               g_assert_not_reached();
                g_free(buf);
                return NULL;
         }
         CATCH(ReportedBoundsError) {
-               g_free(buf);
-               return NULL;
+               g_free(buf);
+               return NULL;
         }
         ENDTRY; 
 
@@ -602,7 +606,7 @@ static tvbuff_t *wcp_uncompress( tvbuff_t *src_tvb, int offset, packet_info *pin
         tvb_set_child_real_data_tvbuff( src_tvb, tvb);
 
        /* Add new data to the data source list */
-       pinfo->fd->data_src = g_slist_append( pinfo->fd->data_src, tvb);
+       add_new_data_source( pinfo, tvb, "Uncompressed WCP");
        return tvb;
 
 }
@@ -727,12 +731,14 @@ proto_register_wcp(void)
 
 void
 proto_reg_handoff_wcp(void) {
+    dissector_handle_t wcp_handle;
 
     /*
      * Get handle for the Frame Relay (uncompressed) dissector.
      */
-    fr_handle = find_dissector("fr");
+    fr_uncompressed_handle = find_dissector("fr_uncompressed");
 
-    dissector_add("fr.ietf", NLPID_COMPRESSED, dissect_wcp, proto_wcp);
-    dissector_add("ethertype",  ETHERTYPE_WCP, dissect_wcp, proto_wcp);
+    wcp_handle = create_dissector_handle(dissect_wcp, proto_wcp);
+    dissector_add("fr.ietf", NLPID_COMPRESSED, wcp_handle);
+    dissector_add("ethertype",  ETHERTYPE_WCP, wcp_handle);
 }