Change the sub-dissector handoff registration routines so that the
authorGilbert Ramirez <gram@alumni.rice.edu>
Thu, 13 Apr 2000 18:18:56 +0000 (18:18 -0000)
committerGilbert Ramirez <gram@alumni.rice.edu>
Thu, 13 Apr 2000 18:18:56 +0000 (18:18 -0000)
sub-dissector table is not stored in the header_field_info struct, but
in a separate namespace. Dissector tables are now registered by name
and not by field ID. For example:

        udp_dissector_table = register_dissector_table("udp.port");

Because of this different namespace, dissector tables can have names
that are not field names.  This is useful for ethertype, since multiple
fields are "ethertypes".

packet-ethertype.c replaces ethertype.c (the name was changed so that it
would be named in the same fashion as all the filenames passed to make-reg-dotc)

Although it registers no protocol or field, it registers one dissector table:

ethertype_dissector_table = register_dissector_table("ethertype");

All protocols that can be called because of an ethertype field now register
that fact with dissector_add() calls.

In this way, one dissector_table services all ethertype fields
(hf_eth_type, hf_llc_type, hf_null_etype, hf_vlan_etype)

Furthermore, the code allows for names of protocols to exist in the
etype_vals, yet a dissector for that protocol doesn't exist. The name
of the dissector is printed in COL_INFO. You're welcome, Richard. :-)

svn path=/trunk/; revision=1848

22 files changed:
Makefile.am
Makefile.nmake
packet-aarp.c
packet-aarp.h [deleted file]
packet-arp.c
packet-atalk.c
packet-ethertype.c [moved from ethertype.c with 56% similarity]
packet-ip.c
packet-ipv6.c
packet-ipx.c
packet-mpls.c
packet-pppoe.c
packet-snmp.c
packet-tcp.c
packet-udp.c
packet-vines.c
packet-vlan.c
packet-x25.c
packet.c
packet.h
proto.c
proto.h

index b3dbfa6ab5e3b8daace9abe433ca455604296adf..03cc08a341f17c1ee9a7ca9c2ef957a9c18664d1 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.181 2000/04/12 22:53:13 guy Exp $
+# $Id: Makefile.am,v 1.182 2000/04/13 18:18:41 gram Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@zing.org>
@@ -34,7 +34,6 @@ YFLAGS=-d -p dfilter_
 
 DISSECTOR_SOURCES = \
        packet-aarp.c  \
-       packet-aarp.h  \
        packet-afs.c   \
        packet-afs.h   \
        packet-arp.c   \
@@ -66,6 +65,7 @@ DISSECTOR_SOURCES = \
        packet-dns.h   \
        packet-eth.c   \
        packet-eth.h   \
+       packet-ethertype.c   \
        packet-fddi.c  \
        packet-fddi.h  \
        packet-ftp.c   \
@@ -243,7 +243,6 @@ ETHEREAL_COMMON_SOURCES = \
        dfilter-scanner.l \
        dfilter.c      \
        dfilter.h      \
-       ethertype.c    \
        etypes.h       \
        follow.c       \
        follow.h       \
index 587a828f219e67fa98380f0ee9ebc43567b86261..779b49e44c6f6ecb841e85a2b7daf913fcefa0ef 100644 (file)
@@ -1,7 +1,7 @@
 ## Makefile for building ethereal.exe with Microsoft C and nmake
 ## Use: nmake -f makefile.nmake
 #
-# $Id: Makefile.nmake,v 1.25 2000/04/13 11:11:37 gram Exp $
+# $Id: Makefile.nmake,v 1.26 2000/04/13 18:18:42 gram Exp $
 
 include config.nmake
 
@@ -36,6 +36,7 @@ DISSECTOR_OBJECTS = \
        packet-dhis.obj  \
        packet-dns.obj   \
        packet-eth.obj   \
+       packet-ethertype.obj   \
        packet-fddi.obj  \
        packet-ftp.obj   \
        packet-giop.obj  \
@@ -140,7 +141,6 @@ ETHEREAL_COMMON_OBJECTS = \
        dfilter-grammar.obj \
        dfilter-scanner.obj \
        dfilter.obj      \
-       ethertype.obj    \
        follow.obj       \
        getopt.obj       \
        ipproto.obj      \
index f12149aeb8c636e896c1bcafb939469e994d36eb..8190707d421a063691a2d7ccefd379ce21375fab 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-aarp.c
  * Routines for Appletalk ARP packet disassembly
  *
- * $Id: packet-aarp.c,v 1.17 2000/03/12 04:47:33 gram Exp $
+ * $Id: packet-aarp.c,v 1.18 2000/04/13 18:18:43 gram Exp $
  *
  * Simon Wilkinson <sxw@dcs.ed.ac.uk>
  *
@@ -283,3 +283,9 @@ proto_register_aarp(void)
   proto_register_field_array(proto_aarp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_aarp(void)
+{
+       dissector_add("ethertype", ETHERTYPE_AARP, dissect_aarp);
+}
diff --git a/packet-aarp.h b/packet-aarp.h
deleted file mode 100644 (file)
index 83def70..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/* packet-aarp.h
- *
- * $Id: packet-aarp.h,v 1.1 2000/02/15 21:01:56 gram Exp $
- *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.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.
- */
-
-
-void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
index cce1e92028e005b88a1c84720958bc17bd921a55..57513c91dfd38bf6603a3932b07de16725b7f552 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-arp.c
  * Routines for ARP packet disassembly
  *
- * $Id: packet-arp.c,v 1.26 2000/03/12 04:47:34 gram Exp $
+ * $Id: packet-arp.c,v 1.27 2000/04/13 18:18:43 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -792,3 +792,10 @@ proto_register_arp(void)
   proto_register_field_array(proto_arp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_arp(void)
+{
+       dissector_add("ethertype", ETHERTYPE_ARP, dissect_arp);
+       dissector_add("ethertype", ETHERTYPE_REVARP, dissect_arp);
+}
index 824d5f68e9b4033e36b55737bbc54fec474c72e5..e07046630dbb9da19221795180ee32d9629bc3ff 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-atalk.c
  * Routines for Appletalk packet disassembly (DDP, currently).
  *
- * $Id: packet-atalk.c,v 1.31 2000/03/12 04:47:35 gram Exp $
+ * $Id: packet-atalk.c,v 1.32 2000/04/13 18:18:44 gram Exp $
  *
  * Simon Wilkinson <sxw@dcs.ed.ac.uk>
  *
@@ -35,6 +35,7 @@
 #include <glib.h>
 #include "packet.h"
 #include "packet-atalk.h"
+#include "etypes.h"
 
 static int proto_ddp = -1;
 static int hf_ddp_hopcount = -1;
@@ -555,3 +556,9 @@ proto_register_atalk(void)
 
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_atalk(void)
+{
+       dissector_add("ethertype", ETHERTYPE_ATALK, dissect_ddp);
+}
similarity index 56%
rename from ethertype.c
rename to packet-ethertype.c
index 93344ec03b886279b72e30204435cb1c340f64a2..6a4fb20a49ae2e9c6668fd49c35ba7fc010c2c6f 100644 (file)
@@ -1,8 +1,7 @@
 /* ethertype.c
  * Routines for calling the right protocol for the ethertype.
- * This is called by both packet-eth.c (Ethernet II) and packet-llc.c (SNAP)
  *
- * $Id: ethertype.c,v 1.28 2000/03/09 18:31:50 ashokn Exp $
+ * $Id: packet-ethertype.c,v 1.1 2000/04/13 18:18:45 gram Exp $
  *
  * Gilbert Ramirez <gram@xiexie.org>
  *
 #include <glib.h>
 #include "packet.h"
 #include "etypes.h"
-#include "packet-aarp.h"
-#include "packet-arp.h"
-#include "packet-atalk.h"
-#include "packet-ip.h"
-#include "packet-ipv6.h"
-#include "packet-ipx.h"
-#include "packet-pppoe.h"
-#include "packet-snmp.h"
-#include "packet-vines.h"
-#include "packet-vlan.h"
-#include "packet-x25.h"
-#include "packet-mpls.h"
+
+static dissector_table_t ethertype_dissector_table;
 
 const value_string etype_vals[] = {
     {ETHERTYPE_IP,     "IP"             },
@@ -97,62 +86,51 @@ ethertype(guint16 etype, int offset,
                const u_char *pd, frame_data *fd, proto_tree *tree, proto_tree
                *fh_tree, int item_id)
 {
-  if (tree) {
-       proto_tree_add_item(fh_tree, item_id, offset - 2, 2, etype);
-  }
-  switch (etype) {
-    case ETHERTYPE_IP:
-      dissect_ip(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_IPv6:
-      dissect_ipv6(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_X25L3:
-      dissect_x25(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_ARP:
-      dissect_arp(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_REVARP:
-      dissect_arp(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_ATALK:
-      dissect_ddp(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_AARP:
-      dissect_aarp(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_IPX:
-      dissect_ipx(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_VINES:
-      dissect_vines(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_LOOP:
-      dissect_data(pd, offset, fd, tree);
-      if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "LOOP"); }
-      break;
-    case ETHERTYPE_PPPOED:
-      dissect_pppoed(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_PPPOES:
-      dissect_pppoes(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_VLAN:
-      dissect_vlan(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_SNMP:
-      dissect_snmp(pd, offset, fd, tree);
-      break;
-    case ETHERTYPE_MPLS:
-      dissect_mpls(pd, offset, fd, tree);
-      break;
-    default:
-      dissect_data(pd, offset, fd, tree);
-      if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "0x%04x", etype); }
-      break;
-  }
-}
+       dissector_t     sub_dissector;
+       char            *description;
+       
+       /* Add to proto_tree */
+       if (tree) {
+               proto_tree_add_item(fh_tree, item_id, offset - 2, 2, etype);
+       }
+
+       /* Look for sub-dissector */
+       sub_dissector = dissector_lookup( ethertype_dissector_table, etype );
+
+       if (sub_dissector) {
+               /* Call sub-dissector */
+               sub_dissector(pd, offset, fd, tree);
+       }
+       else {
+               /* Label rest of packet as "Data" */
+               dissect_data(pd, offset, fd, tree);
 
+               /* Label protocol */
+               switch(etype) {
+                       case ETHERTYPE_LOOP:
+                               if (check_col(fd, COL_PROTOCOL)) {
+                                       col_add_fstr(fd, COL_PROTOCOL, "LOOP");
+                               }
+                               break;
+                           default:
+                               if (check_col(fd, COL_PROTOCOL)) {
+                                       col_add_fstr(fd, COL_PROTOCOL, "0x%04x", etype);
+                               }
+                               break;
+               }
+               if (check_col(fd, COL_INFO)) {
+                       description = match_strval(etype, etype_vals);
+                       if (description) {
+                               col_add_fstr(fd, COL_INFO, "%s", description);
+                       }
+               }
+       }
+}
 
 
+void
+proto_register_ethertype(void)
+{
+       /* subdissector code */
+       ethertype_dissector_table = register_dissector_table("ethertype");
+}
index c285a58148719fd0b9ac813a6c6e2f99d191395f..3fac5a22d72e57c15e3f348acc525d78662b6c3f 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-ip.c
  * Routines for IP and miscellaneous IP protocol packet disassembly
  *
- * $Id: packet-ip.c,v 1.78 2000/03/21 05:15:12 guy Exp $
+ * $Id: packet-ip.c,v 1.79 2000/04/13 18:18:45 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -50,6 +50,7 @@
 # include "snprintf.h"
 #endif
 
+#include "etypes.h"
 #include "packet-gre.h"
 #include "packet-ip.h"
 #include "packet-ipsec.h"
@@ -1516,6 +1517,12 @@ proto_register_ip(void)
        proto_register_subtree_array(ett, array_length(ett));
 }
 
+void
+proto_reg_handoff_ip(void)
+{
+       dissector_add("ethertype", ETHERTYPE_IP, dissect_ip);
+}
+
 void
 proto_register_icmp(void)
 {
index b93f3cc2bc022873a42c89e28c7f48962536c936..7a58a5426e6bbb953117bdd6eb9bf5cc5aeac476 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-ipv6.c
  * Routines for IPv6 packet disassembly 
  *
- * $Id: packet-ipv6.c,v 1.31 2000/03/21 04:15:04 guy Exp $
+ * $Id: packet-ipv6.c,v 1.32 2000/04/13 18:18:46 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -42,6 +42,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <glib.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-icmpv6.h"
 #include "packet-ip.h"
@@ -470,3 +471,9 @@ proto_register_ipv6(void)
   proto_register_field_array(proto_ipv6, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_ipv6(void)
+{
+       dissector_add("ethertype", ETHERTYPE_IPv6, dissect_ipv6);
+}
index 0e6df2638af902c2d2b754389f98b66e4d7dd599..f09c2af008fc1e7999c246700faf67427024b2c8 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for NetWare's IPX
  * Gilbert Ramirez <gram@xiexie.org>
  *
- * $Id: packet-ipx.c,v 1.52 2000/04/08 07:07:21 guy Exp $
+ * $Id: packet-ipx.c,v 1.53 2000/04/13 18:18:47 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -34,6 +34,7 @@
 
 #include <stdio.h>
 #include <glib.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-ipx.h"
 #include "packet-nbipx.h"
@@ -973,4 +974,5 @@ void
 proto_reg_handoff_ipx(void)
 {
        dissector_add("udp.port", UDP_PORT_IPX, dissect_ipx);
+       dissector_add("ethertype", ETHERTYPE_IPX, dissect_ipx);
 }
index 028d4b7ac8a8d300571d11f02bdb8074a61ee6e1..7c9cd5bbc39a96a9bf1757f538f064f35714663d 100644 (file)
@@ -3,7 +3,7 @@
  * 
  * (c) Copyright Ashok Narayanan <ashokn@cisco.com>
  *
- * $Id: packet-mpls.c,v 1.3 2000/03/20 22:52:44 gram Exp $
+ * $Id: packet-mpls.c,v 1.4 2000/04/13 18:18:48 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -43,6 +43,7 @@
 #endif
 
 #include <glib.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-mpls.h"
 #include "packet-ip.h"
@@ -190,3 +191,8 @@ proto_register_mpls(void)
        proto_register_subtree_array(ett, array_length(ett));
 }
 
+void
+proto_reg_handoff_mpls(void)
+{
+       dissector_add("ethertype", ETHERTYPE_MPLS, dissect_mpls);
+}
index ff1161250c827eedd046ed94915b13fb759455f4..af15049757147b184c333222cecd68c1a156e0d9 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-arp.c
  * Routines for ARP packet disassembly
  *
- * $Id: packet-pppoe.c,v 1.5 2000/02/15 21:02:54 gram Exp $
+ * $Id: packet-pppoe.c,v 1.6 2000/04/13 18:18:48 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -32,6 +32,7 @@
 #endif
 
 #include <glib.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-ppp.h"
 
@@ -247,3 +248,9 @@ proto_register_pppoed(void)
        proto_register_subtree_array(ett, array_length(ett));
 }
 
+void
+proto_reg_handoff_pppoe(void)
+{
+       dissector_add("ethertype", ETHERTYPE_PPPOED, dissect_pppoed);
+       dissector_add("ethertype", ETHERTYPE_PPPOES, dissect_pppoes);
+}
index c816e3426b55d423c2e467fa15c2331e65ad29b5..b72e42426e090a2980bdc937be1dcebe50ca1652 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for SNMP (simple network management protocol)
  * D.Jorand (c) 1998
  *
- * $Id: packet-snmp.c,v 1.27 2000/04/08 07:07:36 guy Exp $
+ * $Id: packet-snmp.c,v 1.28 2000/04/13 18:18:48 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -50,6 +50,7 @@
 #include <glib.h>
 
 #include "packet.h"
+#include "etypes.h"
 
 #if defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H)
  /*
@@ -1185,4 +1186,5 @@ proto_reg_handoff_snmp(void)
 {
        dissector_add("udp.port", UDP_PORT_SNMP, dissect_snmp);
        dissector_add("udp.port", UDP_PORT_SNMP_TRAP, dissect_snmp);
+       dissector_add("ethertype", ETHERTYPE_SNMP, dissect_snmp);
 }
index b06a58092c5b9675af1a7bbaf0cfa8c1de474e90..ecf39355cb0b34d51c010876d4b480148a3c6db5 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-tcp.c
  * Routines for TCP packet disassembly
  *
- * $Id: packet-tcp.c,v 1.67 2000/04/12 22:53:15 guy Exp $
+ * $Id: packet-tcp.c,v 1.68 2000/04/13 18:18:49 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -636,5 +636,5 @@ proto_register_tcp(void)
        proto_register_subtree_array(ett, array_length(ett));
 
 /* subdissector code */
-       subdissector_table = register_dissector_table(hf_tcp_port);
+       subdissector_table = register_dissector_table("tcp.port");
 }
index ca22c9f972c79db1a6e31912317671ce3df3ac25..079b19f44286536a06f58c228df9dbf58d914be0 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-udp.c
  * Routines for UDP packet disassembly
  *
- * $Id: packet-udp.c,v 1.60 2000/04/12 22:53:16 guy Exp $
+ * $Id: packet-udp.c,v 1.61 2000/04/13 18:18:50 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -246,5 +246,5 @@ proto_register_udp(void)
        proto_register_subtree_array(ett, array_length(ett));
 
 /* subdissector code */
-       udp_dissector_table = register_dissector_table(hf_udp_port);
+       udp_dissector_table = register_dissector_table("udp.port");
 }
index b1d35e04c58c7dbb972a765ff642f58ae3c53e8d..ba7d499d8c52dea8be35119a365c66b49e25fb3e 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-vines.c
  * Routines for Banyan VINES protocol packet disassembly
  *
- * $Id: packet-vines.c,v 1.12 2000/01/23 08:55:37 guy Exp $
+ * $Id: packet-vines.c,v 1.13 2000/04/13 18:18:52 gram Exp $
  *
  * Don Lafontaine <lafont02@cn.ca>
  *
@@ -37,6 +37,7 @@
 #endif
 
 #include <glib.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-vines.h"
 
@@ -339,3 +340,9 @@ proto_register_vines(void)
 
        proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_vines(void)
+{
+       dissector_add("ethertype", ETHERTYPE_VINES, dissect_vines);
+}
index f6215eb9c2399a9800c25a4fe3a44a7d62650f52..6096ff40e6338dc9ad476bb4abafd9ed7919c2f1 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-vlan.c
  * Routines for VLAN 802.1Q ethernet header disassembly
  *
- * $Id: packet-vlan.c,v 1.8 2000/02/15 21:03:25 gram Exp $
+ * $Id: packet-vlan.c,v 1.9 2000/04/13 18:18:52 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -133,3 +133,9 @@ proto_register_vlan(void)
   proto_register_field_array(proto_vlan, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
+
+void
+proto_reg_handoff_vlan(void)
+{
+       dissector_add("ethertype", ETHERTYPE_VLAN, dissect_vlan);
+}
index e6ece02fa8d506d38c6d6734f7c5ea7b96dd371a..51141f796916464372ac8badbf3499d775c4061c 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for x25 packet disassembly
  * Olivier Abad <abad@daba.dhis.net>
  *
- * $Id: packet-x25.c,v 1.22 2000/03/12 04:47:51 gram Exp $
+ * $Id: packet-x25.c,v 1.23 2000/04/13 18:18:53 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -36,6 +36,7 @@
 #include <glib.h>
 #include <stdlib.h>
 #include <string.h>
+#include "etypes.h"
 #include "packet.h"
 #include "packet-ip.h"
 #include "packet-osi.h"
@@ -1978,3 +1979,9 @@ proto_register_x25(void)
     proto_register_subtree_array(ett, array_length(ett));
     register_init_routine(&reinit_x25_hashtable);
 }
+
+void
+proto_reg_handoff_x25(void)
+{
+       dissector_add("ethertype", ETHERTYPE_X25L3, dissect_x25);
+}
index 9a24c8f99baece9c16f67e035c03da0a9233c449..f873f0cfe4dd5af7a4fed6ab4b6f83c4d39b43ab 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -1,7 +1,7 @@
 /* packet.c
  * Routines for packet disassembly
  *
- * $Id: packet.c,v 1.74 2000/04/04 16:33:57 gram Exp $
+ * $Id: packet.c,v 1.75 2000/04/13 18:18:54 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -1266,15 +1266,27 @@ proto_register_frame(void)
 
 /*********************** code added for sub-dissector lookup *********************/
 
-dissector_t dissector_lookup( dissector_table_t table, guint32 pattern) {
+static GHashTable *dissector_tables = NULL;
 
-/* lookup a dissector based upon pattern. */
+/* Finds a dissector table by field name. */
+static dissector_table_t
+find_dissector_table(const char *name)
+{
+       g_assert(dissector_tables);
+       return g_hash_table_lookup( dissector_tables, name );
+}
 
+dissector_t
+dissector_lookup( dissector_table_t table, guint32 pattern)
+{
+       /* lookup a dissector based upon pattern. */
        return g_hash_table_lookup( table, GUINT_TO_POINTER( pattern));
 }
 
 
-void dissector_add( char *name, guint32 pattern, dissector_t dissector) {
+void
+dissector_add( char *name, guint32 pattern, dissector_t dissector)
+{
 
 /* add an entry, lookup the dissector table for the specified field name,  */
 /* if a valid table found, add the subdissector */
@@ -1290,7 +1302,9 @@ void dissector_add( char *name, guint32 pattern, dissector_t dissector) {
 }
 
 
-void dissector_delete( char *name, guint32 pattern, dissector_t dissector) {
+void
+dissector_delete( char *name, guint32 pattern, dissector_t dissector)
+{
 
 /* delete the entry for this dissector at this pattern */
 
@@ -1327,20 +1341,23 @@ dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
                return FALSE;
 }
 
-dissector_table_t register_dissector_table( int id){
-
-/* Create and register the dissector array for this field; returns */
-/* a pointer to the dissector table. */
+dissector_table_t
+register_dissector_table(const char *name)
+{
+       dissector_table_t       sub_dissectors;
 
-/* NOTE: currently use the g_direct_XXX functions so all the hashing is done  */
-/*     by glib and we don't have to create hashing or comparison funtcions. */
-       
+       /* Create our hash-of-hashes if it doesn't already exist */
+       if (!dissector_tables) {
+               dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
+               g_assert(dissector_tables);
+       }
 
-       header_field_info *hfinfo = proto_registrar_get_nth(id);
+       /* Make sure the registration is unique */
+       g_assert(!g_hash_table_lookup( dissector_tables, name ));
 
-       g_assert( hfinfo);      
-               
-       hfinfo->sub_dissectors = g_hash_table_new( g_direct_hash, g_direct_equal);
-       return hfinfo->sub_dissectors;
+       /* Create and register the dissector array for this field; returns */
+       /* a pointer to the dissector table. */
+       sub_dissectors = g_hash_table_new( g_direct_hash, g_direct_equal );
+       g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
+       return sub_dissectors;
 }
-
index 9af8abda0f894e8869ed892d93ce804c16edeb17..8e8bc9f8342de08468a2dc1f46ec9ff23ac39fbc 100644 (file)
--- a/packet.h
+++ b/packet.h
@@ -1,7 +1,7 @@
 /* packet.h
  * Definitions for packet disassembly structures and routines
  *
- * $Id: packet.h,v 1.179 2000/04/04 07:02:57 guy Exp $
+ * $Id: packet.h,v 1.180 2000/04/13 18:18:54 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -210,12 +210,13 @@ typedef struct true_false_string {
        char    *false_string;
 } true_false_string;
 
+typedef GHashTable* dissector_table_t;
 
 /* types for sub-dissector lookup */
 typedef void (*dissector_t)(const u_char *, int, frame_data *, proto_tree *);
 
 /* a protocol uses the function to register its sub-dissector table */
-dissector_table_t register_dissector_table( int proto_id);
+dissector_table_t register_dissector_table(const char *name);
 
 /* dissector lookup routine.  called by protocol dissector to find a sub-dissector */
 dissector_t dissector_lookup( dissector_table_t table, guint32 pattern);
diff --git a/proto.c b/proto.c
index d71193a1251aba93ad3d421264e63a59563b955a..4cd2034de23b4a3f4f09a33df22f5dd531269786 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.61 2000/04/11 16:07:40 gram Exp $
+ * $Id: proto.c,v 1.62 2000/04/13 18:18:55 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -260,21 +260,6 @@ proto_registrar_get_nth(int hfindex)
        return g_ptr_array_index(gpa_hfinfo, hfindex);
 }
 
-/* Finds a dissector table by field name. */
-dissector_table_t
-find_dissector_table(const char *name)
-{
-       header_field_info       *hfinfo;
-       int                     i, len;
-
-       len = gpa_hfinfo->len;
-       for (i = 0; i < len ; i++) {
-               hfinfo = proto_registrar_get_nth(i);
-               if (strcmp(name, hfinfo->abbrev) == 0)
-                       return hfinfo->sub_dissectors;
-       }
-       return NULL;
-}
 
 /* Add a node with no text */
 proto_item *
@@ -949,8 +934,6 @@ proto_register_protocol(char *name, char *abbrev)
        hfinfo->blurb = "";
        hfinfo->parent = -1; /* this field differentiates protos and fields */
 
-       hfinfo->sub_dissectors = NULL;  /* clear sub-dissector table pointer */
-
        return proto_register_field_init(hfinfo, hfinfo->parent);
 }
 
diff --git a/proto.h b/proto.h
index da0756010de5083535553fbb05ae3ae0f9b2c059..d33cded1486b5c5425a832ee50cc1cf74b4b4a55 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -1,7 +1,7 @@
 /* proto.h
  * Definitions for protocol display
  *
- * $Id: proto.h,v 1.27 2000/04/04 02:34:40 gram Exp $
+ * $Id: proto.h,v 1.28 2000/04/13 18:18:56 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -90,9 +90,6 @@ enum {
 };
 
 
-/* types for sub-dissector lookup */
-typedef GHashTable* dissector_table_t;
-
 /* information describing a header field */
 typedef struct header_field_info {
        char                            *name;
@@ -106,7 +103,6 @@ typedef struct header_field_info {
        int                             id;             /* assigned by registration function, not programmer */
        int                             parent;         /* parent protocol */
        int                             bitshift;       /* bits to shift */
-       dissector_table_t               sub_dissectors; /* sub-dissector table pointer */
 } header_field_info;
 
 
@@ -342,9 +338,6 @@ char* proto_registrar_get_abbrev(int n);
 /* get the header field information based upon a field or protocol id */
 struct header_field_info* proto_registrar_get_nth(int hfindex);
 
-/* get the dissector table based upon a field or protocol name */
-dissector_table_t find_dissector_table(const char *name);
-
 /* Returns enum ftenum for item # n */
 int proto_registrar_get_ftype(int n);