Give the IPX dissector dissector hash tables for the IPX type and socket
[obnox/wireshark/wip.git] / packet-ipx.c
index 93334ac25c5cd334861f9797610cad0cafb9b523..1fb9db630be054715ad4b01266f243187bd49a3f 100644 (file)
@@ -1,11 +1,11 @@
 /* packet-ipx.c
  * Routines for NetWare's IPX
- * Gilbert Ramirez <gram@verdict.uthscsa.edu>
+ * Gilbert Ramirez <gram@xiexie.org>
  *
- * $Id: packet-ipx.c,v 1.11 1998/10/14 05:18:30 gram Exp $
+ * $Id: packet-ipx.c,v 1.60 2000/05/30 03:35:51 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@unicom.net>
+ * By Gerald Combs <gerald@zing.org>
  * Copyright 1998 Gerald Combs
  *
  * 
 # include "config.h"
 #endif
 
-#include <gtk/gtk.h>
-#include <pcap.h>
-
-#include <stdio.h>
-
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
 
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
-#include "ethereal.h"
+#include <stdio.h>
+#include <glib.h>
+#include "etypes.h"
+#include "ppptypes.h"
+#include "llcsaps.h"
 #include "packet.h"
 #include "packet-ipx.h"
+#include "packet-nbipx.h"
+#include "resolv.h"
+
+#include "packet-snmp.h"
 
 /* The information in this module (IPX, SPX, NCP) comes from:
        NetWare LAN Analysis, Second Edition
   And from the ncpfs source code by Volker Lendecke
 
 */
+       
+static int proto_ipx = -1;
+static int hf_ipx_checksum = -1;
+static int hf_ipx_len = -1;
+static int hf_ipx_hops = -1;
+static int hf_ipx_packet_type = -1;
+static int hf_ipx_dnet = -1;
+static int hf_ipx_dnode = -1;
+static int hf_ipx_dsocket = -1;
+static int hf_ipx_snet = -1;
+static int hf_ipx_snode = -1;
+static int hf_ipx_ssocket = -1;
+
+static gint ett_ipx = -1;
+
+static dissector_table_t ipx_type_dissector_table;
+static dissector_table_t ipx_socket_dissector_table;
+
+static int proto_spx = -1;
+static int hf_spx_connection_control = -1;
+static int hf_spx_datastream_type = -1;
+static int hf_spx_src_id = -1;
+static int hf_spx_dst_id = -1;
+static int hf_spx_seq_nr = -1;
+static int hf_spx_ack_nr = -1;
+static int hf_spx_all_nr = -1;
+
+static gint ett_spx = -1;
+
+static int proto_ipxrip = -1;
+static int hf_ipxrip_request = -1;
+static int hf_ipxrip_response = -1;
+
+static gint ett_ipxrip = -1;
+
+static int proto_sap = -1;
+static int hf_sap_request = -1;
+static int hf_sap_response = -1;
+
+static gint ett_ipxsap = -1;
+static gint ett_ipxsap_server = -1;
+
+static gint ett_ipxmsg = -1;
+static int proto_ipxmsg = -1;
+static int hf_msg_conn = -1;
+static int hf_msg_sigchar = -1;
 
 static void
-dissect_spx(const u_char *pd, int offset, frame_data *fd, GtkTree *tree);
+dissect_spx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
 
 static void
-dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree);
+dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
 
 static void
-dissect_sap(const u_char *pd, int offset, frame_data *fd, GtkTree *tree);
+dissect_ipxsap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
+
+static void
+dissect_ipxmsg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
+
+#define UDP_PORT_IPX    213            /* RFC 1234 */
 
 struct port_info {
        guint16 port;
-       void    (*func) (const u_char *, int, frame_data *, GtkTree *);
        char    *text;
 };
 
@@ -84,17 +133,30 @@ struct server_info {
 /* ================================================================= */
 /* IPX                                                               */
 /* ================================================================= */
+
 static struct port_info        ports[] = {
-       { 0x0451, dissect_ncp,          "NCP" },
-       { 0x0452, dissect_sap,          "SAP" },
-       { 0x0453, dissect_ipxrip,       "RIP" },
-       { 0x0455, NULL,                         "NetBIOS" },
-       { 0x0456, NULL,                         "Diagnostic" },
-       { 0x0457, NULL,                         "Serialization" },
-       { 0x0551, NULL,                         "NWLink SMB Name Query" },
-       { 0x0553, dissect_nwlink_dg,"NWLink SMB Datagram" },
-       { 0x055d, NULL,                         "Attachmate Gateway" },
-       { 0x0000, NULL,                         NULL }
+       { IPX_SOCKET_PING_CISCO,                "CISCO PING" },
+       { IPX_SOCKET_NCP,                       "NCP" },
+       { IPX_SOCKET_SAP,                       "SAP" },
+       { IPX_SOCKET_IPXRIP,                    "RIP" },
+       { IPX_SOCKET_NETBIOS,                   "NetBIOS" },
+       { IPX_SOCKET_DIAGNOSTIC,                "Diagnostic" },
+       { IPX_SOCKET_SERIALIZATION,             "Serialization" },
+       { IPX_SOCKET_NWLINK_SMB_NAMEQUERY,      "NWLink SMB Name Query" },
+       { IPX_SOCKET_NWLINK_SMB_DGRAM,          "NWLink SMB Datagram" },
+       { IPX_SOCKET_NWLINK_SMB_BROWSE,         "NWLink SMB Browse" },
+       { IPX_SOCKET_ATTACHMATE_GW,             "Attachmate Gateway" },
+       { IPX_SOCKET_IPX_MESSAGE,               "IPX Message" },
+       { IPX_SOCKET_SNMP_AGENT,                "SNMP Agent" },
+       { IPX_SOCKET_SNMP_SINK,                 "SNMP Sink" },
+       { IPX_SOCKET_PING_NOVELL,               "NOVELL PING" },
+       { IPX_SOCKET_UDP_TUNNEL,                "UDP Tunnel" },
+       { IPX_SOCKET_TCP_TUNNEL,                "TCP Tunnel" },
+       { IPX_SOCKET_TCP_TUNNEL,                "TCP Tunnel" },
+       { IPX_SOCKET_ADSM,                      "ADSM" },
+       { IPX_SOCKET_EIGRP,                     "Cisco EIGRP for IPX" },
+       { IPX_SOCKET_WIDE_AREA_ROUTER,          "Wide Area Router" },
+       { 0x0000,                               NULL }
 };
 
 static char*
@@ -110,47 +172,55 @@ port_text(guint16 port) {
        return "Unknown";
 }
 
-static void*
-port_func(guint16 port) {
-       int i=0;
+static const value_string ipx_packet_type_vals[] = {
+       { IPX_PACKET_TYPE_IPX,          "IPX" },
+       { IPX_PACKET_TYPE_RIP,          "RIP" },
+       { IPX_PACKET_TYPE_ECHO,         "Echo" },
+       { IPX_PACKET_TYPE_ERROR,        "Error" },
+       { IPX_PACKET_TYPE_PEP,          "PEP" }, /* Packet Exchange Packet */
+       { IPX_PACKET_TYPE_SPX,          "SPX" },
+       { 16,                           "Experimental Protocol" },
+       { IPX_PACKET_TYPE_NCP,          "NCP" },
+       { 18,                           "Experimental Protocol" },
+       { 19,                           "Experimental Protocol" },
+       { IPX_PACKET_TYPE_WANBCAST,     "NetBIOS Broadcast" },
+       { 21,                           "Experimental Protocol" },
+       { 22,                           "Experimental Protocol" },
+       { 23,                           "Experimental Protocol" },
+       { 24,                           "Experimental Protocol" },
+       { 25,                           "Experimental Protocol" },
+       { 26,                           "Experimental Protocol" },
+       { 27,                           "Experimental Protocol" },
+       { 28,                           "Experimental Protocol" },
+       { 29,                           "Experimental Protocol" },
+       { 30,                           "Experimental Protocol" },
+       { 31,                           "Experimental Protocol" },
+       { 0,                            NULL }
+};
 
-       while (ports[i].text != NULL) {
-               if (ports[i].port == port) {
-                       return ports[i].func;
-               }
-               i++;
-       }
-       return dissect_data;
-}
+static const value_string ipxmsg_sigchar_vals[] = {
+       { '?', "Poll inactive station" },
+       { 0, NULL }
+};
 
-char *
-ipx_packet_type(u_char val)
+gchar*
+ipxnet_to_string(const guint8 *ad)
 {
-       if (val == 0) {
-               return "IPX";
-       }
-       else if (val == 5) {
-               return "SPX";
-       }
-       else if (val == 17) {
-               return "NCP";
-       }
-       else if (val == 20) {
-               return "NetBIOS Broadcast";
-       }
-       else if (val >= 16 && val <= 31) {
-               return "Experimental Protocol";
-       }
-       else {
-               return "Unknown";
-       }
+       guint32 addr = pntohl(ad);
+       return ipxnet_to_str_punct(addr, ' ');
 }
 
+/* We use a different representation of hardware addresses
+ * than ether_to_str(); we don't put punctuation between the hex
+ * digits.
+ */
+
 gchar*
-ipxnet_to_string(const guint8 *ad)
+ipx_addr_to_str(guint32 net, const guint8 *ad)
 {
-       static gchar    str[3][12];
+       static gchar    str[3][8+1+MAXNAMELEN+1]; /* 8 digits, 1 period, NAME, 1 null */
        static gchar    *cur;
+       char            *name;
 
        if (cur == &str[0][0]) {
                cur = &str[1][0];
@@ -160,89 +230,154 @@ ipxnet_to_string(const guint8 *ad)
                cur = &str[0][0];
        }
 
-       sprintf(cur, "%02X %02X %02X %02X", ad[0], ad[1], ad[2], ad[3]);
+       name = get_ether_name_if_known(ad);
+
+       if (name) {
+               sprintf(cur, "%s.%s", get_ipxnet_name(net), name);
+       }
+       else {
+               sprintf(cur, "%s.%s", get_ipxnet_name(net), ether_to_str_punct(ad, '\0'));
+       }
        return cur;
 }
 
-void
-dissect_ipx(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
-
-       GtkWidget       *ipx_tree, *ti;
-       u_char          ipx_type;
-
-       char            *dnet, *snet;
-       guint16         dsocket, ssocket;
-       void            (*dissect) (const u_char *, int, frame_data *, GtkTree *);
-
-       /* Calculate here for use in win_info[] and in tree */
-       dnet = ipxnet_to_string((guint8*)&pd[offset+6]);
-       snet = ipxnet_to_string((guint8*)&pd[offset+18]);
-       dsocket = pntohs(&pd[offset+16]);
+gchar *
+ipxnet_to_str_punct(const guint32 ad, char punct) {
+  static gchar  str[3][12];
+  static gchar *cur;
+  gchar        *p;
+  int          i;
+  guint32      octet;
+  static const gchar hex_digits[16] = "0123456789ABCDEF";
+  static const guint32  octet_mask[4] =
+         { 0xff000000 , 0x00ff0000, 0x0000ff00, 0x000000ff };
+
+  if (cur == &str[0][0]) {
+    cur = &str[1][0];
+  } else if (cur == &str[1][0]) {  
+    cur = &str[2][0];
+  } else {  
+    cur = &str[0][0];
+  }
+  p = &cur[12];
+  *--p = '\0';
+  i = 3;
+  for (;;) {
+    octet = (ad & octet_mask[i]) >> ((3 - i) * 8);
+    *--p = hex_digits[octet&0xF];
+    octet >>= 4;
+    *--p = hex_digits[octet&0xF];
+    if (i == 0)
+      break;
+    if (punct)
+      *--p = punct;
+    i--;
+  }
+  return p;
+}
 
-       if (fd->win_info[COL_NUM]) {
-               strcpy(fd->win_info[COL_PROTOCOL], "IPX");
-               sprintf(fd->win_info[COL_INFO], "%s (0x%04X)", port_text(dsocket), dsocket);
-       }
+void
+capture_ipx(const u_char *pd, int offset, packet_counts *ld)
+{
+       ld->ipx++;
+}
 
+void
+dissect_ipx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
+
+       proto_tree      *ipx_tree;
+       proto_item      *ti;
+       guint8          ipx_type, ipx_hops;
+       guint16         ipx_checksum, ipx_length;
+       int             len;
+       guint8          *ipx_snode, *ipx_dnode, *ipx_snet, *ipx_dnet;
+
+       guint16         ipx_dsocket, ipx_ssocket;
+       guint32         ipx_dnet_val, ipx_snet_val;
+
+       /* Calculate here for use in pinfo and in tree */
+       ipx_dnet = (guint8*)&pd[offset+6];
+       ipx_snet = (guint8*)&pd[offset+18];
+       ipx_dnet_val = pntohl(ipx_dnet);
+       ipx_snet_val = pntohl(ipx_snet);
+       ipx_dsocket = pntohs(&pd[offset+16]);
+       ipx_ssocket = pntohs(&pd[offset+28]);
+       ipx_dnode = (guint8*)&pd[offset+10];
+       ipx_snode = (guint8*)&pd[offset+22];
        ipx_type = pd[offset+5];
+       ipx_length = pntohs(&pd[offset+2]);
+
+       /* Length of IPX datagram plus headers above it. */
+       len = ipx_length + offset;
+
+       /* Set the payload and captured-payload lengths to the minima of
+          (the IPX length plus the length of the headers above it) and
+          the frame lengths. */
+       if (pi.len > len)
+               pi.len = len;
+       if (pi.captured_len > len)
+               pi.captured_len = len;
+
+       SET_ADDRESS(&pi.net_src, AT_IPX, 10, &pd[offset+18]);
+       SET_ADDRESS(&pi.src, AT_IPX, 10, &pd[offset+18]);
+       SET_ADDRESS(&pi.net_dst, AT_IPX, 10, &pd[offset+6]);
+       SET_ADDRESS(&pi.dst, AT_IPX, 10, &pd[offset+6]);
+
+       if (check_col(fd, COL_PROTOCOL))
+               col_add_str(fd, COL_PROTOCOL, "IPX");
+       if (check_col(fd, COL_INFO))
+               col_add_fstr(fd, COL_INFO, "%s (0x%04X)", port_text(ipx_dsocket),
+                               ipx_dsocket);
 
        if (tree) {
-               ti = add_item_to_tree(GTK_WIDGET(tree), offset, 30,
-                       "Internetwork Packet Exchange");
-               ipx_tree = gtk_tree_new();
-               add_subtree(ti, ipx_tree, ETT_IPX);
-               add_item_to_tree(ipx_tree, offset,      2, "Checksum: 0x%04X",
-                       (pd[offset] << 8) | pd[offset+1]);
-               add_item_to_tree(ipx_tree, offset+2,    2, "Length: %d bytes",
-                       (pd[offset+2] << 8) | pd[offset+3]);
-               add_item_to_tree(ipx_tree, offset+4,    1, "Transport Control: %d hops",
-                       pd[offset+4]);
-               add_item_to_tree(ipx_tree, offset+5,    1, "Packet Type: %s",
-                       ipx_packet_type(ipx_type));
-               add_item_to_tree(ipx_tree, offset+6,    4, "Destination Network: %s",
-                       dnet);
-               add_item_to_tree(ipx_tree, offset+10,   6, "Destination Node: %s",
-                       ether_to_str((guint8*)&pd[offset+10]));
-               /*dsocket = ntohs(*((guint16*)&pd[offset+16]));*/
-               add_item_to_tree(ipx_tree, offset+16,   2,
-                       "Destination Socket: %s (0x%04X)", port_text(dsocket), dsocket);
-               add_item_to_tree(ipx_tree, offset+18,   4, "Source Network: %s",
-                       snet);
-               add_item_to_tree(ipx_tree, offset+22,   6, "Source Node: %s",
-                       ether_to_str((guint8*)&pd[offset+22]));
-               ssocket = pntohs(&pd[offset+28]);
-               add_item_to_tree(ipx_tree, offset+28,   2,
-                       "Source Socket: %s (0x%04X)", port_text(ssocket), ssocket);
+               ipx_checksum = pntohs(&pd[offset]);
+               ipx_hops = pd[offset+4];
+
+               ti = proto_tree_add_item(tree, proto_ipx, NullTVB, offset, 30, NULL);
+               ipx_tree = proto_item_add_subtree(ti, ett_ipx);
+               proto_tree_add_item(ipx_tree, hf_ipx_checksum, NullTVB, offset, 2, ipx_checksum);
+               proto_tree_add_uint_format(ipx_tree, hf_ipx_len, NullTVB, offset+2, 2, ipx_length,
+                       "Length: %d bytes", ipx_length);
+               proto_tree_add_uint_format(ipx_tree, hf_ipx_hops, NullTVB, offset+4, 1, ipx_hops,
+                       "Transport Control: %d hops", ipx_hops);
+               proto_tree_add_item(ipx_tree, hf_ipx_packet_type, NullTVB, offset+5, 1, ipx_type);
+               proto_tree_add_item(ipx_tree, hf_ipx_dnet, NullTVB, offset+6, 4, ipx_dnet_val);
+               proto_tree_add_item(ipx_tree, hf_ipx_dnode, NullTVB, offset+10, 6, ipx_dnode);
+               proto_tree_add_uint_format(ipx_tree, hf_ipx_dsocket, NullTVB, offset+16, 2,
+                       ipx_dsocket, "Destination Socket: %s (0x%04X)",
+                       port_text(ipx_dsocket), ipx_dsocket);
+               proto_tree_add_item(ipx_tree, hf_ipx_snet, NullTVB, offset+18, 4, ipx_snet_val);
+               proto_tree_add_item(ipx_tree, hf_ipx_snode, NullTVB, offset+22, 6, ipx_snode);
+               proto_tree_add_uint_format(ipx_tree, hf_ipx_ssocket, NullTVB, offset+28, 2,
+                       ipx_ssocket, "Source Socket: %s (0x%04X)", port_text(ipx_ssocket),
+                       ipx_ssocket);
        }
        offset += 30;
 
+       if (dissector_try_port(ipx_type_dissector_table, ipx_type, pd,
+           offset, fd, tree))
+               return;
        switch (ipx_type) {
-               case 5: /* SPX */
-                       dissect_spx(pd, offset, fd, tree);
-                       break;
-
-               case 17: /* NCP */
-                       dissect_ncp(pd, offset, fd, tree);
-                       break;
-
-               case 20: /* NetBIOS */
-                       if (dsocket == 0x0455) {
-                               dissect_nbipx_ns(pd, offset, fd, tree);
-                               break;
+               case IPX_PACKET_TYPE_WANBCAST:
+               case IPX_PACKET_TYPE_PEP:
+                       if (ipx_dsocket == IPX_SOCKET_NETBIOS) {
+                               dissect_nbipx(pd, offset, fd, tree);
+                               return;
                        }
                        /* else fall through */
 
                case 0: /* IPX, fall through to default */
-               default:
-                       dissect = port_func(dsocket);
-                       if (dissect) {
-                               dissect(pd, offset, fd, tree);
-                       }
-                       else {
-                               dissect_data(pd, offset, fd, tree);
-                       }
+                       /* XXX - should type 0's be dissected as NBIPX
+                          if they're aimed at the NetBIOS socket? */
                        break;
        }
+       if (dissector_try_port(ipx_socket_dissector_table, ipx_dsocket, pd,
+           offset, fd, tree))
+               return;
+       if (dissector_try_port(ipx_socket_dissector_table, ipx_ssocket, pd,
+           offset, fd, tree))
+               return;
+       dissect_data(pd, offset, fd, tree);
 }
 
 
@@ -258,7 +393,8 @@ spx_conn_ctrl(u_char ctrl)
                { 0x10, "End-of-Message" },
                { 0x20, "Attention" },
                { 0x40, "Acknowledgment Required"},
-               { 0x80, "System Packet"}
+               { 0x80, "System Packet"},
+               { 0x00, NULL }
        };
 
        while (conns[i].text != NULL) {
@@ -271,7 +407,7 @@ spx_conn_ctrl(u_char ctrl)
 }
 
 static char*
-datastream(u_char type)
+spx_datastream(u_char type)
 {
        switch (type) {
                case 0xfe:
@@ -284,102 +420,156 @@ datastream(u_char type)
 }
 
 static void
-dissect_spx(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
-
-       GtkWidget       *spx_tree, *ti;
+dissect_spx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
+       proto_tree      *spx_tree;
+       proto_item      *ti;
 
-       if (fd->win_info[COL_NUM]) {
-               strcpy(fd->win_info[COL_PROTOCOL], "SPX");
-               strcpy(fd->win_info[COL_INFO], "SPX");
-       }
+       if (check_col(fd, COL_PROTOCOL))
+               col_add_str(fd, COL_PROTOCOL, "SPX");
+       if (check_col(fd, COL_INFO))
+               col_add_str(fd, COL_INFO, "SPX");
 
        if (tree) {
-               ti = add_item_to_tree(GTK_WIDGET(tree), offset, 12,
-                       "Sequenced Packet Exchange");
-               spx_tree = gtk_tree_new();
-               add_subtree(ti, spx_tree, ETT_SPX);
+               ti = proto_tree_add_item(tree, proto_spx, NullTVB, offset, 12, NULL);
+               spx_tree = proto_item_add_subtree(ti, ett_spx);
+
+               proto_tree_add_uint_format(spx_tree, hf_spx_connection_control, NullTVB,
+                                          offset,      1,
+                                          pd[offset],
+                                          "Connection Control: %s (0x%02X)",
+                                          spx_conn_ctrl(pd[offset]), 
+                                          pd[offset]);
+
+               proto_tree_add_uint_format(spx_tree, hf_spx_datastream_type, NullTVB,
+                                          offset+1,     1,
+                                          pd[offset+1],
+                                          "Datastream Type: %s (0x%02X)",
+                                          spx_datastream(pd[offset+1]), 
+                                          pd[offset+1]);
+
+               proto_tree_add_item(spx_tree, hf_spx_src_id, NullTVB, 
+                                   offset+2,     2,
+                                   pntohs( &pd[offset+2] ));
+
+               proto_tree_add_item(spx_tree, hf_spx_dst_id, NullTVB,
+                                   offset+4,     2,
+                                   pntohs( &pd[offset+4] ));
+
+               proto_tree_add_item(spx_tree, hf_spx_seq_nr, NullTVB, 
+                                   offset+6,     2,
+                                   pntohs( &pd[offset+6] ) );
+
+               proto_tree_add_item(spx_tree, hf_spx_ack_nr, NullTVB,
+                                   offset+8,     2,
+                                   pntohs( &pd[offset+8] ) );
+
+               proto_tree_add_item(spx_tree, hf_spx_all_nr, NullTVB,
+                                   offset+10,     2,
+                                   pntohs( &pd[offset+10] ) );
 
-               add_item_to_tree(spx_tree, offset,      1,
-                       "Connection Control: %s (0x%02X)",
-                       spx_conn_ctrl(pd[offset]), pd[offset]);
-
-               add_item_to_tree(spx_tree, offset+1,     1,
-                       "Datastream Type: %s (0x%02X)",
-                       datastream(pd[offset+1]), pd[offset+1]);
-
-               add_item_to_tree(spx_tree, offset+2,     2,
-                       "Source Connection ID: %d", pntohs( &pd[offset+2] ) );
+               offset += 12;
+               dissect_data(pd, offset, fd, tree);
+       }
+}
 
-               add_item_to_tree(spx_tree, offset+4,     2,
-                       "Destination Connection ID: %d", pntohs( &pd[offset+4] ) );
+/* ================================================================= */
+/* IPX Message                                                       */
+/* ================================================================= */
+static void
+dissect_ipxmsg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
+       proto_tree      *msg_tree;
+       proto_item      *ti;
+       u_char conn_number, sig_char;
+
+       if ( ! BYTES_ARE_IN_FRAME(offset,2) )
+       {
+               return;
+       }
 
-               add_item_to_tree(spx_tree, offset+6,     2,
-                       "Sequence Number: %d", pntohs( &pd[offset+6] ) );
+       conn_number = pd[offset];
+       sig_char = pd[offset+1];
 
-               add_item_to_tree(spx_tree, offset+8,     2,
-                       "Acknowledgment Number: %d", pntohs( &pd[offset+8] ) );
+       if (check_col(fd, COL_PROTOCOL))
+        col_add_str(fd, COL_PROTOCOL, "IPX MSG");
+       if (check_col(fd, COL_PROTOCOL)) {
+               col_add_fstr(fd, COL_INFO, 
+                       "%s, Connection %d", 
+                       val_to_str(sig_char, ipxmsg_sigchar_vals, "Unknown Signature Char"), conn_number);
+       }
 
-               add_item_to_tree(spx_tree, offset+10,     2,
-                       "Allocation Number: %d", pntohs( &pd[offset+10] ) );
+       if (tree) {
+               ti = proto_tree_add_item(tree, proto_ipxmsg, NullTVB, offset, END_OF_FRAME, NULL);
+               msg_tree = proto_item_add_subtree(ti, ett_ipxmsg);
 
-               offset += 12;
-               dissect_data(pd, offset, fd, tree);
+               proto_tree_add_item(msg_tree, hf_msg_conn, NullTVB, offset, 1, conn_number);
+               proto_tree_add_item(msg_tree, hf_msg_sigchar, NullTVB, offset+1, 1, sig_char);
        }
 }
 
+
 /* ================================================================= */
 /* IPX RIP                                                           */
 /* ================================================================= */
 static void
-dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
-
-       GtkWidget       *rip_tree, *ti;
+dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
+       proto_tree      *rip_tree;
+       proto_item      *ti;
        guint16         operation;
        struct ipx_rt_def route;
-       int                     cursor;
+       int             cursor;
 
        char            *rip_type[2] = { "Request", "Response" };
 
        operation = pntohs(&pd[offset]) - 1;
 
-       if (fd->win_info[COL_NUM]) {
-               strcpy(fd->win_info[COL_PROTOCOL], "IPX RIP");
-               if (operation < 2) {
-                       sprintf(fd->win_info[COL_INFO], rip_type[operation]);
-               }
-               else {
-                       strcpy(fd->win_info[COL_INFO], "Unknown Packet Type");
-               }
+       if (check_col(fd, COL_PROTOCOL))
+        col_add_str(fd, COL_PROTOCOL, "IPX RIP");
+       if (check_col(fd, COL_PROTOCOL)) {
+        if (operation < 2) {
+                col_add_str(fd, COL_INFO, rip_type[operation]);
+        }
+        else {
+                col_add_str(fd, COL_INFO, "Unknown Packet Type");
+        }
        }
 
        if (tree) {
-               ti = add_item_to_tree(GTK_WIDGET(tree), offset, END_OF_FRAME,
-                       "IPX Routing Information Protocol");
-               rip_tree = gtk_tree_new();
-               add_subtree(ti, rip_tree, ETT_IPXRIP);
+               ti = proto_tree_add_item(tree, proto_ipxrip, NullTVB, offset, END_OF_FRAME, NULL);
+               rip_tree = proto_item_add_subtree(ti, ett_ipxrip);
 
                if (operation < 2) {
-                       add_item_to_tree(rip_tree, offset, 2,
+                       proto_tree_add_text(rip_tree, NullTVB, offset, 2,
                        "RIP packet type: %s", rip_type[operation]);
+
+                       if (operation == 0) {
+                         proto_tree_add_item_hidden(rip_tree, 
+                                                    hf_ipxrip_request, 
+                                                    NullTVB, offset, 2, 1);
+                       } else {
+                         proto_tree_add_item_hidden(rip_tree, 
+                                                    hf_ipxrip_response, 
+                                                    NullTVB, offset, 2, 1);
+                       }
+
                }
                else {
-                       add_item_to_tree(rip_tree, offset, 2, "Unknown RIP packet type");
+                       proto_tree_add_text(rip_tree, NullTVB, offset, 2, "Unknown RIP packet type");
                }
 
-               for (cursor = offset + 2; cursor < fd->cap_len; cursor += 8) {
+               for (cursor = offset + 2; cursor < pi.captured_len; cursor += 8) {
                        memcpy(&route.network, &pd[cursor], 4);
                        route.hops = pntohs(&pd[cursor+4]);
                        route.ticks = pntohs(&pd[cursor+6]);
 
                        if (operation == IPX_RIP_REQUEST - 1) {
-                               add_item_to_tree(rip_tree, cursor,      8,
+                               proto_tree_add_text(rip_tree, NullTVB, cursor,      8,
                                        "Route Vector: %s, %d hop%s, %d tick%s",
                                        ipxnet_to_string((guint8*)&route.network),
                                        route.hops,  route.hops  == 1 ? "" : "s",
                                        route.ticks, route.ticks == 1 ? "" : "s");
                        }
                        else {
-                               add_item_to_tree(rip_tree, cursor,      8,
+                               proto_tree_add_text(rip_tree, NullTVB, cursor,      8,
                                        "Route Vector: %s, %d hop%s, %d tick%s (%d ms)",
                                        ipxnet_to_string((guint8*)&route.network),
                                        route.hops,  route.hops  == 1 ? "" : "s",
@@ -393,7 +583,7 @@ dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
 
 
 /* ================================================================= */
-/* SAP                                                                                                                          */
+/* SAP                                                                  */
 /* ================================================================= */
 static char*
 server_type(guint16 type)
@@ -431,10 +621,28 @@ server_type(guint16 type)
                { 0x0111,       "Test server" },
                { 0x0133,       "NetWare Name Service" },
                { 0x0166,       "NetWare management" },
+               { 0x023f,       "SMS Testing and Development" },
                { 0x026a,       "NetWare management" },
                { 0x026b,       "Time synchronization" },
+               { 0x027b,       "NetWare Management Agent" },
                { 0x0278,       "NetWare Directory server" },
+               { 0x030c,       "HP LaserJet / Quick Silver" },
+               { 0x0355,       "Arcada Software" },
+               { 0x0361,       "NETINELO" },
+               { 0x037e,       "Powerchute UPS Monitoring" },
+               { 0x03e1,       "UnixWare Application Server" },
+               { 0x044c,       "Archive" },
                { 0x055d,       "Attachmate SNA gateway" },
+               { 0x0610,       "Adaptec SCSI Management" },
+               { 0x0640,       "NT Server-RPC/GW for NW/Win95 User Level Sec" },
+               { 0x064e,       "NT Server-IIS" },
+               { 0x0810,       "ELAN License Server Demo" },
+               { 0x8002,       "Intel NetPort Print Server" },
+
+/* For any unidentified ones, I found a really big list of them at: */
+/*    http://www.inpnet.org/cnpweb/saplist.txt */
+/*    http://www.isi.edu/in-notes/iana/assignments/novell-sap-numbers */
+
                { 0x0000,       NULL }
        };
 
@@ -448,10 +656,11 @@ server_type(guint16 type)
 }
 
 static void
-dissect_sap(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
+dissect_ipxsap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
 
-       GtkWidget       *sap_tree, *s_tree, *ti;
-       int                     cursor;
+       proto_tree      *sap_tree, *s_tree;
+       proto_item      *ti;
+       int             cursor;
        struct sap_query query;
        struct sap_server_ident server;
 
@@ -461,34 +670,42 @@ dissect_sap(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
        query.query_type = pntohs(&pd[offset]);
        query.server_type = pntohs(&pd[offset+2]);
 
-       if (fd->win_info[COL_NUM]) {
-               strcpy(fd->win_info[COL_PROTOCOL], "SAP");
-               if (query.query_type < 4) {
-                       sprintf(fd->win_info[COL_INFO], sap_type[query.query_type - 1]);
+       if (check_col(fd, COL_PROTOCOL))
+               col_add_str(fd, COL_PROTOCOL, "SAP");
+       if (check_col(fd, COL_INFO)) {
+               if (query.query_type >= 1 && query.query_type <= 4) {
+                       col_add_str(fd, COL_INFO, sap_type[query.query_type - 1]);
                }
                else {
-                       strcpy(fd->win_info[COL_INFO], "Unknown Packet Type");
+                       col_add_str(fd, COL_INFO, "Unknown Packet Type");
                }
        }
 
        if (tree) {
-               ti = add_item_to_tree(GTK_WIDGET(tree), offset, END_OF_FRAME,
-                       "Service Advertising Protocol");
-               sap_tree = gtk_tree_new();
-               add_subtree(ti, sap_tree, ETT_IPXSAP);
-
-               if (query.query_type < 4) {
-                       add_item_to_tree(sap_tree, offset, 2, sap_type[query.query_type - 1]);
+               ti = proto_tree_add_item(tree, proto_sap, NullTVB, offset, END_OF_FRAME, NULL);
+               sap_tree = proto_item_add_subtree(ti, ett_ipxsap);
+
+               if (query.query_type >= 1 && query.query_type <= 4) {
+                       proto_tree_add_text(sap_tree, NullTVB, offset, 2, sap_type[query.query_type - 1]);
+                       if ((query.query_type - 1) % 2) {
+                         proto_tree_add_item_hidden(sap_tree, 
+                                                    hf_sap_response, 
+                                                    NullTVB, offset, 2, 1);
+                       } else {
+                         proto_tree_add_item_hidden(sap_tree, 
+                                                    hf_sap_request, 
+                                                    NullTVB, offset, 2, 1);
+                       }
                }
                else {
-                       add_item_to_tree(sap_tree, offset, 2,
+                       proto_tree_add_text(sap_tree, NullTVB, offset, 2,
                                        "Unknown SAP Packet Type %d", query.query_type);
                }
 
                if (query.query_type == IPX_SAP_GENERAL_RESPONSE ||
                                query.query_type == IPX_SAP_NEAREST_RESPONSE) { /* responses */
 
-                       for (cursor = offset + 2; cursor < fd->cap_len; cursor += 64) {
+                       for (cursor = offset + 2; (cursor + 64) <= pi.captured_len; cursor += 64) {
                                server.server_type = pntohs(&pd[cursor]);
                                memcpy(server.server_name, &pd[cursor+2], 48);
                                memcpy(&server.server_network, &pd[cursor+50], 4);
@@ -496,28 +713,188 @@ dissect_sap(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
                                server.server_port = pntohs(&pd[cursor+60]);
                                server.intermediate_network = pntohs(&pd[cursor+62]);
 
-                               ti = add_item_to_tree(GTK_WIDGET(sap_tree), cursor+2, 48,
+                               ti = proto_tree_add_text(sap_tree, NullTVB, cursor+2, 48,
                                        "Server Name: %s", server.server_name);
-                               s_tree = gtk_tree_new();
-                               add_subtree(ti, s_tree, ETT_IPXSAP_SERVER);
+                               s_tree = proto_item_add_subtree(ti, ett_ipxsap_server);
 
-                               add_item_to_tree(s_tree, cursor, 2, "Server Type: %s (0x%04X)",
+                               proto_tree_add_text(s_tree, NullTVB, cursor, 2, "Server Type: %s (0x%04X)",
                                                server_type(server.server_type), server.server_type);
-                               add_item_to_tree(s_tree, cursor+50, 4, "Network: %s",
+                               proto_tree_add_text(s_tree, NullTVB, cursor+50, 4, "Network: %s",
                                                ipxnet_to_string((guint8*)&pd[cursor+50]));
-                               add_item_to_tree(s_tree, cursor+54, 6, "Node: %s",
+                               proto_tree_add_text(s_tree, NullTVB, cursor+54, 6, "Node: %s",
                                                ether_to_str((guint8*)&pd[cursor+54]));
-                               add_item_to_tree(s_tree, cursor+60, 2, "Socket: %s (0x%04X)",
+                               proto_tree_add_text(s_tree, NullTVB, cursor+60, 2, "Socket: %s (0x%04X)",
                                                port_text(server.server_port), server.server_port);
-                               add_item_to_tree(s_tree, cursor+62, 2,
+                               proto_tree_add_text(s_tree, NullTVB, cursor+62, 2,
                                                "Intermediate Networks: %d",
                                                server.intermediate_network);
                        }
                }
                else {  /* queries */
-                       add_item_to_tree(sap_tree, offset+2, 2, "Server Type: %s (0x%04X)",
+                       proto_tree_add_text(sap_tree, NullTVB, offset+2, 2, "Server Type: %s (0x%04X)",
                                        server_type(query.server_type), query.server_type);
                }
        }
 }
 
+void
+proto_register_ipx(void)
+{
+       static hf_register_info hf_ipx[] = {
+               { &hf_ipx_checksum,
+               { "Checksum",           "ipx.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_len,
+               { "Length",             "ipx.len", FT_UINT16, BASE_DEC, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_hops,
+               { "Transport Control (Hops)", "ipx.hops", FT_UINT8, BASE_DEC, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_packet_type,
+               { "Packet Type",        "ipx.packet_type", FT_UINT8, BASE_HEX, VALS(ipx_packet_type_vals),
+                       0x0,
+                       "" }},
+
+               { &hf_ipx_dnet,
+               { "Destination Network","ipx.dst.net", FT_IPXNET, BASE_NONE, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_dnode,
+               { "Destination Node",   "ipx.dst.node", FT_ETHER, BASE_NONE, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_dsocket,
+               { "Destination Socket", "ipx.dst.socket", FT_UINT16, BASE_HEX, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_snet,
+               { "Source Network","ipx.src.net", FT_IPXNET, BASE_NONE, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_snode,
+               { "Source Node",        "ipx.src.node", FT_ETHER, BASE_NONE, NULL, 0x0,
+                       "" }},
+
+               { &hf_ipx_ssocket,
+               { "Source Socket",      "ipx.src.socket", FT_UINT16, BASE_HEX, NULL, 0x0,
+                       "" }},
+       };
+
+       static hf_register_info hf_spx[] = {
+               { &hf_spx_connection_control,
+               { "Connection Control",         "spx.ctl", 
+                 FT_UINT8,     BASE_HEX,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_datastream_type,
+               { "Datastream type",            "spx.type", 
+                 FT_UINT8,     BASE_HEX,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_src_id,
+               { "Source Connection ID",       "spx.src", 
+                 FT_UINT16,    BASE_DEC,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_dst_id,
+               { "Destination Connection ID",  "spx.dst", 
+                 FT_UINT16,    BASE_DEC,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_seq_nr,
+               { "Sequence Number",            "spx.seq", 
+                 FT_UINT16,    BASE_DEC,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_ack_nr,
+               { "Acknowledgment Number",      "spx.ack", 
+                 FT_UINT16,    BASE_DEC,       NULL,   0x0,
+                 "" }},
+
+               { &hf_spx_all_nr,
+               { "Allocation Number",          "spx.alloc", 
+                 FT_UINT16,    BASE_DEC,       NULL,   0x0,
+                 "" }}
+       };
+
+       static hf_register_info hf_ipxrip[] = {
+               { &hf_ipxrip_request,
+               { "Request",                    "ipxrip.request", 
+                 FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
+                 "TRUE if IPX RIP request" }},
+
+               { &hf_ipxrip_response,
+               { "Response",                   "ipxrip.response", 
+                 FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
+                 "TRUE if IPX RIP response" }}
+       };
+
+       static hf_register_info hf_sap[] = {
+               { &hf_sap_request,
+               { "Request",                    "ipxsap.request", 
+                 FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
+                 "TRUE if SAP request" }},
+
+               { &hf_sap_response,
+               { "Response",                   "ipxsap.response", 
+                 FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
+                 "TRUE if SAP response" }}
+       };
+
+       static hf_register_info hf_ipxmsg[] = {
+               { &hf_msg_conn,
+               { "Connection Number",                  "ipxmsg.conn", 
+                 FT_UINT8,     BASE_NONE,      NULL,   0x0,
+                 "Connection Number" }},
+
+               { &hf_msg_sigchar,
+               { "Signature Char",                     "ipxmsg.sigchar", 
+                 FT_UINT8,     BASE_NONE,      VALS(ipxmsg_sigchar_vals),      0x0,
+                 "Signature Char" }}
+       };
+
+       static gint *ett[] = {
+               &ett_ipx,
+               &ett_spx,
+               &ett_ipxmsg,
+               &ett_ipxrip,
+               &ett_ipxsap,
+               &ett_ipxsap_server,
+       };
+
+       proto_ipx = proto_register_protocol ("Internetwork Packet eXchange", "ipx");
+       proto_register_field_array(proto_ipx, hf_ipx, array_length(hf_ipx));
+
+       proto_spx = proto_register_protocol ("Sequenced Packet eXchange", "spx");
+       proto_register_field_array(proto_spx, hf_spx, array_length(hf_spx));
+
+       proto_ipxrip = proto_register_protocol ("IPX Routing Information Protocol", "ipxrip");
+       proto_register_field_array(proto_ipxrip, hf_ipxrip, array_length(hf_ipxrip));
+
+       proto_ipxmsg = proto_register_protocol ("IPX Message", "ipxmsg");
+       proto_register_field_array(proto_ipxmsg, hf_ipxmsg, array_length(hf_ipxmsg));
+
+       proto_sap = proto_register_protocol ("Service Advertisement Protocol", "ipxsap");
+       proto_register_field_array(proto_sap, hf_sap, array_length(hf_sap));
+
+       proto_register_subtree_array(ett, array_length(ett));
+
+       ipx_type_dissector_table = register_dissector_table("ipx.packet_type");
+       ipx_socket_dissector_table = register_dissector_table("ipx.socket");
+}
+
+void
+proto_reg_handoff_ipx(void)
+{
+       dissector_add("udp.port", UDP_PORT_IPX, dissect_ipx);
+       dissector_add("ethertype", ETHERTYPE_IPX, dissect_ipx);
+       dissector_add("ppp.protocol", PPP_IPX, dissect_ipx);
+       dissector_add("llc.dsap", SAP_NETWARE, dissect_ipx);
+       dissector_add("ipx.packet_type", IPX_PACKET_TYPE_SPX, dissect_spx);
+       dissector_add("ipx.socket", IPX_SOCKET_SAP, dissect_ipxsap);
+       dissector_add("ipx.socket", IPX_SOCKET_IPXRIP, dissect_ipxrip);
+       dissector_add("ipx.socket", IPX_SOCKET_IPX_MESSAGE, dissect_ipxmsg);
+}