Now that WinPcap is a DLL, I can load it at run-time rather than load-time.
[obnox/wireshark/wip.git] / packet-ascend.c
index b6330c62f505a7c6d93c99e3fbba5739993200e4..ce351ce6b283a3d2fac242c081a56cb54f271d90 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-ascend.c
  * Routines for decoding Lucent/Ascend packet traces
  *
- * $Id: packet-ascend.c,v 1.9 2000/02/15 21:01:58 gram Exp $
+ * $Id: packet-ascend.c,v 1.25 2001/03/30 06:10:54 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -32,8 +32,6 @@
 #include <glib.h>
 #include <string.h>
 #include "packet.h"
-#include "packet-eth.h"
-#include "packet-ppp.h"
 
 static int proto_ascend  = -1;
 static int hf_link_type  = -1;
@@ -51,52 +49,58 @@ static const value_string encaps_vals[] = {
   {ASCEND_PFX_WDD,   "Ethernet"    },
   {0,                NULL          } };
 
-void
-dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) {
-  proto_tree *fh_tree;
-  proto_item *ti;
+static dissector_handle_t eth_handle;
+static dissector_handle_t ppp_hdlc_handle;
+
+static void
+dissect_ascend(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+  proto_tree                   *fh_tree;
+  proto_item                   *ti;
+  union wtap_pseudo_header     *pseudo_header = pinfo->pseudo_header;
 
   /* load the top pane info. This should be overwritten by
      the next protocol in the stack */
-  if(check_col(fd, COL_RES_DL_SRC))
-    col_add_str(fd, COL_RES_DL_SRC, "N/A" );
-  if(check_col(fd, COL_RES_DL_DST))
-    col_add_str(fd, COL_RES_DL_DST, "N/A" );
-  if(check_col(fd, COL_PROTOCOL))
-    col_add_str(fd, COL_PROTOCOL, "N/A" );
-  if(check_col(fd, COL_INFO))
-    col_add_str(fd, COL_INFO, "Lucent/Ascend packet trace" );
+  if(check_col(pinfo->fd, COL_RES_DL_SRC))
+    col_set_str(pinfo->fd, COL_RES_DL_SRC, "N/A" );
+  if(check_col(pinfo->fd, COL_RES_DL_DST))
+    col_set_str(pinfo->fd, COL_RES_DL_DST, "N/A" );
+  if(check_col(pinfo->fd, COL_PROTOCOL))
+    col_set_str(pinfo->fd, COL_PROTOCOL, "N/A" );
+  if(check_col(pinfo->fd, COL_INFO))
+    col_set_str(pinfo->fd, COL_INFO, "Lucent/Ascend packet trace" );
 
   /* populate a tree in the second pane with the status of the link
      layer (ie none) */
   if(tree) {
-    ti = proto_tree_add_text(tree, 0, 0, "Lucent/Ascend packet trace" );
+    ti = proto_tree_add_protocol_format(tree, proto_ascend, tvb, 0, 0,
+                                       "Lucent/Ascend packet trace");
     fh_tree = proto_item_add_subtree(ti, ett_raw);
-    proto_tree_add_item(fh_tree, hf_link_type, 0, 0, 
-                       fd->pseudo_header.ascend.type);
-    if (fd->pseudo_header.ascend.type == ASCEND_PFX_WDD) {
-      proto_tree_add_item(fh_tree, hf_called_number, 0, 0, 
-                         fd->pseudo_header.ascend.call_num);
-      proto_tree_add_item(fh_tree, hf_chunk, 0, 0,
-                         fd->pseudo_header.ascend.chunk);
-      proto_tree_add_item_hidden(fh_tree, hf_session_id, 0, 0, 0);
+    proto_tree_add_uint(fh_tree, hf_link_type, tvb, 0, 0, 
+                       pseudo_header->ascend.type);
+    if (pseudo_header->ascend.type == ASCEND_PFX_WDD) {
+      proto_tree_add_string(fh_tree, hf_called_number, tvb, 0, 0, 
+                         pseudo_header->ascend.call_num);
+      proto_tree_add_uint(fh_tree, hf_chunk, tvb, 0, 0,
+                         pseudo_header->ascend.chunk);
+      proto_tree_add_uint_hidden(fh_tree, hf_session_id, tvb, 0, 0, 0);
     } else {  /* It's wandsession data */
-      proto_tree_add_item(fh_tree, hf_user_name, 0, 0, 
-                         fd->pseudo_header.ascend.user);
-      proto_tree_add_item(fh_tree, hf_session_id, 0, 0,
-                         fd->pseudo_header.ascend.sess);
-      proto_tree_add_item_hidden(fh_tree, hf_chunk, 0, 0, 0);
+      proto_tree_add_string(fh_tree, hf_user_name, tvb, 0, 0, 
+                         pseudo_header->ascend.user);
+      proto_tree_add_uint(fh_tree, hf_session_id, tvb, 0, 0,
+                         pseudo_header->ascend.sess);
+      proto_tree_add_uint_hidden(fh_tree, hf_chunk, tvb, 0, 0, 0);
     }
-    proto_tree_add_item(fh_tree, hf_task, 0, 0, fd->pseudo_header.ascend.task);
+    proto_tree_add_uint(fh_tree, hf_task, tvb, 0, 0, pseudo_header->ascend.task);
   }
 
-  switch (fd->pseudo_header.ascend.type) {
+  switch (pseudo_header->ascend.type) {
     case ASCEND_PFX_WDS_X:
     case ASCEND_PFX_WDS_R:
-      dissect_ppp(pd, fd, tree);
+      call_dissector(ppp_hdlc_handle, tvb, pinfo, tree);
       break;
     case ASCEND_PFX_WDD:
-      dissect_eth(pd, 0, fd, tree);
+      call_dissector(eth_handle, tvb, pinfo, tree);
       break;
     default:
       break;
@@ -135,7 +139,19 @@ proto_register_ascend(void)
     &ett_raw,
   };
 
-  proto_ascend = proto_register_protocol("Lucent/Ascend debug output", "ascend");
+  proto_ascend = proto_register_protocol("Lucent/Ascend debug output",
+                                        "Lucent/Ascend", "ascend");
   proto_register_field_array(proto_ascend, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_ascend(void)
+{
+  /*
+   * Get handles for the Ethernet and PPP-in-HDLC-like-framing dissectors.
+   */
+  eth_handle = find_dissector("eth");
+  ppp_hdlc_handle = find_dissector("ppp_hdlc");
+  dissector_add("wtap_encap", WTAP_ENCAP_ASCEND, dissect_ascend, proto_ascend);
+}