From Anand V. Narwani:
[obnox/wireshark/wip.git] / packet-rpc.c
index 7fa88009f05294a5681f06b6252d9483bc995e51..107836cd3d63ad89a9d71e9a5720d7043a92a843 100644 (file)
@@ -2,10 +2,10 @@
  * Routines for rpc dissection
  * Copyright 1999, Uwe Girlich <Uwe.Girlich@philosys.de>
  * 
- * $Id: packet-rpc.c,v 1.37 2000/08/14 07:47:19 girlich Exp $
+ * $Id: packet-rpc.c,v 1.97 2002/06/07 10:11:39 guy Exp $
  * 
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  * 
  * Copied from packet-smb.c
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#include "packet.h"
-#include "conversation.h"
+#include <epan/packet.h>
+#include <epan/conversation.h>
 #include "packet-rpc.h"
+#include "packet-frame.h"
+#include "packet-tcp.h"
+#include "prefs.h"
+#include "reassemble.h"
+#include "rpc_defrag.h"
+#include "packet-nfs.h"
+
+/*
+ * See:
+ *
+ *     RFC 1831, "RPC: Remote Procedure Call Protocol Specification
+ *     Version 2";
+ *
+ *     RFC 1832, "XDR: External Data Representation Standard";
+ *
+ *     RFC 2203, "RPCSEC_GSS Protocol Specification".
+ *
+ * See also
+ *
+ *     RFC 2695, "Authentication Mechanisms for ONC RPC"
+ *
+ *     although we don't currently dissect AUTH_DES or AUTH_KERB.
+ */
 
+/* desegmentation of RPC over TCP */
+static gboolean rpc_desegment = TRUE;
 
-#define RPC_RM_FRAGLEN  0x7fffffffL
+/* defragmentation of fragmented RPC over TCP records */
+static gboolean rpc_defragment = FALSE;
 
 static struct true_false_string yesno = { "Yes", "No" };
 
@@ -64,22 +90,22 @@ const value_string rpc_auth_flavor[] = {
        { AUTH_UNIX, "AUTH_UNIX" },
        { AUTH_SHORT, "AUTH_SHORT" },
        { AUTH_DES, "AUTH_DES" },
-       { AUTH_GSS, "AUTH_GSS" },
+       { RPCSEC_GSS, "RPCSEC_GSS" },
        { 0, NULL }
 };
 
 static const value_string rpc_authgss_proc[] = {
-       { AUTH_GSS_DATA, "AUTH_GSS_DATA" },
-       { AUTH_GSS_INIT, "AUTH_GSS_INIT" },
-       { AUTH_GSS_CONTINUE_INIT, "AUTH_GSS_CONTINUE_INIT" },
-       { AUTH_GSS_DESTROY, "AUTH_GSS_DESTROY" },
+       { RPCSEC_GSS_DATA, "RPCSEC_GSS_DATA" },
+       { RPCSEC_GSS_INIT, "RPCSEC_GSS_INIT" },
+       { RPCSEC_GSS_CONTINUE_INIT, "RPCSEC_GSS_CONTINUE_INIT" },
+       { RPCSEC_GSS_DESTROY, "RPCSEC_GSS_DESTROY" },
        { 0, NULL }
 };
 
-static const value_string rpc_authgss_svc[] = {
-       { AUTH_GSS_SVC_NONE, "AUTH_GSS_SVC_NONE" },
-       { AUTH_GSS_SVC_INTEGRITY, "AUTH_GSS_SVC_INTEGRITY" },
-       { AUTH_GSS_SVC_PRIVACY, "AUTH_GSS_SVC_PRIVACY" },
+value_string rpc_authgss_svc[] = {
+       { RPCSEC_GSS_SVC_NONE, "rpcsec_gss_svc_none" },
+       { RPCSEC_GSS_SVC_INTEGRITY, "rpcsec_gss_svc_integrity" },
+       { RPCSEC_GSS_SVC_PRIVACY, "rpcsec_gss_svc_privacy" },
        { 0, NULL }
 };
 
@@ -104,11 +130,16 @@ static const value_string rpc_auth_state[] = {
        { AUTH_BADVERF, "bad verifier (seal broken)" },
        { AUTH_REJECTEDVERF, "verifier expired or replayed" },
        { AUTH_TOOWEAK, "rejected for security reasons" },
-       { AUTH_GSSCREDPROB, "GSS credential problem" },
-       { AUTH_GSSCTXPROB, "GSS context problem" },
+       { RPCSEC_GSSCREDPROB, "GSS credential problem" },
+       { RPCSEC_GSSCTXPROB, "GSS context problem" },
        { 0, NULL }
 };
 
+static const value_string rpc_authdes_namekind[] = {
+       { AUTHDES_NAMEKIND_FULLNAME, "ADN_FULLNAME" },
+       { AUTHDES_NAMEKIND_NICKNAME, "ADN_NICKNAME" },
+       { 0, NULL }
+};
 
 /* the protocol number */
 static int proto_rpc = -1;
@@ -142,6 +173,14 @@ static int hf_rpc_authgss_token = -1;
 static int hf_rpc_authgss_data_length = -1;
 static int hf_rpc_authgss_data = -1;
 static int hf_rpc_authgss_checksum = -1;
+static int hf_rpc_authdes_namekind = -1;
+static int hf_rpc_authdes_netname = -1;
+static int hf_rpc_authdes_convkey = -1;
+static int hf_rpc_authdes_window = -1;
+static int hf_rpc_authdes_nickname = -1;
+static int hf_rpc_authdes_timestamp = -1;
+static int hf_rpc_authdes_windowverf = -1;
+static int hf_rpc_authdes_timeverf = -1;
 static int hf_rpc_state_accept = -1;
 static int hf_rpc_state_reply = -1;
 static int hf_rpc_state_reject = -1;
@@ -150,13 +189,43 @@ static int hf_rpc_dup = -1;
 static int hf_rpc_call_dup = -1;
 static int hf_rpc_reply_dup = -1;
 static int hf_rpc_value_follows = -1;
+static int hf_rpc_array_len = -1;
+static int hf_rpc_time = -1;
+static int hf_rpc_fragments = -1;
+static int hf_rpc_fragment = -1;
+static int hf_rpc_fragment_overlap = -1;
+static int hf_rpc_fragment_overlap_conflict = -1;
+static int hf_rpc_fragment_multiple_tails = -1;
+static int hf_rpc_fragment_too_long_fragment = -1;
+static int hf_rpc_fragment_error = -1;
 
 static gint ett_rpc = -1;
+static gint ett_rpc_fragments = -1;
+static gint ett_rpc_fragment = -1;
+static gint ett_rpc_fraghdr = -1;
 static gint ett_rpc_string = -1;
 static gint ett_rpc_cred = -1;
 static gint ett_rpc_verf = -1;
 static gint ett_rpc_gids = -1;
 static gint ett_rpc_gss_data = -1;
+static gint ett_rpc_array = -1;
+
+static dissector_handle_t rpc_tcp_handle;
+static dissector_handle_t rpc_handle;
+static dissector_handle_t data_handle;
+
+fragment_items rpc_frag_items = {
+       &ett_rpc_fragment,
+       &ett_rpc_fragments,
+       &hf_rpc_fragments,
+       &hf_rpc_fragment,
+       &hf_rpc_fragment_overlap,
+       &hf_rpc_fragment_overlap_conflict,
+       &hf_rpc_fragment_multiple_tails,
+       &hf_rpc_fragment_too_long_fragment,
+       &hf_rpc_fragment_error,
+       "fragments"
+};
 
 /* Hash table with info on RPC program numbers */
 static GHashTable *rpc_progs;
@@ -164,13 +233,37 @@ static GHashTable *rpc_progs;
 /* Hash table with info on RPC procedure numbers */
 static GHashTable *rpc_procs;
 
+typedef struct _rpc_proc_info_key {
+       guint32 prog;
+       guint32 vers;
+       guint32 proc;
+} rpc_proc_info_key;
+
+typedef struct _rpc_proc_info_value {
+       gchar           *name;
+       dissect_function_t *dissect_call;
+       dissect_function_t *dissect_reply;
+} rpc_proc_info_value;
+
+typedef struct _rpc_prog_info_key {
+       guint32 prog;
+} rpc_prog_info_key;
+
+typedef struct _rpc_prog_info_value {
+       int proto;
+       int ett;
+       char* progname;
+} rpc_prog_info_value;
+
+static void dissect_rpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
+static void dissect_rpc_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
 /***********************************/
 /* Hash array with procedure names */
 /***********************************/
 
 /* compare 2 keys */
-gint
+static gint
 rpc_proc_equal(gconstpointer k1, gconstpointer k2)
 {
        rpc_proc_info_key* key1 = (rpc_proc_info_key*) k1;
@@ -183,7 +276,7 @@ rpc_proc_equal(gconstpointer k1, gconstpointer k2)
 }
 
 /* calculate a hash key */
-guint
+static guint
 rpc_proc_hash(gconstpointer k)
 {
        rpc_proc_info_key* key = (rpc_proc_info_key*) k;
@@ -216,6 +309,29 @@ rpc_init_proc_table(guint prog, guint vers, const vsff *proc_table)
        }
 }
 
+/*     return the name associated with a previously registered procedure. */
+char *rpc_proc_name(guint32 prog, guint32 vers, guint32 proc)
+{
+       rpc_proc_info_key key;
+       rpc_proc_info_value *value;
+       char *procname;
+       static char procname_static[20];
+
+       key.prog = prog;
+       key.vers = vers;
+       key.proc = proc;
+
+       if ((value = g_hash_table_lookup(rpc_procs,&key)) != NULL)
+               procname = value->name;
+       else {
+               /* happens only with strange program versions or
+                  non-existing dissectors */
+               sprintf(procname_static, "proc-%u", key.proc);
+               procname = procname_static;
+       }
+       return procname;
+}
+
 /*----------------------------------------*/
 /* end of Hash array with procedure names */
 /*----------------------------------------*/
@@ -226,7 +342,7 @@ rpc_init_proc_table(guint prog, guint vers, const vsff *proc_table)
 /*********************************/
 
 /* compare 2 keys */
-gint
+static gint
 rpc_prog_equal(gconstpointer k1, gconstpointer k2)
 {
        rpc_prog_info_key* key1 = (rpc_prog_info_key*) k1;
@@ -238,7 +354,7 @@ rpc_prog_equal(gconstpointer k1, gconstpointer k2)
 
 
 /* calculate a hash key */
-guint
+static guint
 rpc_prog_hash(gconstpointer k)
 {
        rpc_prog_info_key* key = (rpc_prog_info_key*) k;
@@ -252,7 +368,6 @@ rpc_init_prog(int proto, guint32 prog, int ett)
 {
        rpc_prog_info_key *key;
        rpc_prog_info_value *value;
-       char *uc_progname = NULL, *lc_progname = NULL;
 
        key = (rpc_prog_info_key *) g_malloc(sizeof(rpc_prog_info_key));
        key->prog = prog;
@@ -260,18 +375,7 @@ rpc_init_prog(int proto, guint32 prog, int ett)
        value = (rpc_prog_info_value *) g_malloc(sizeof(rpc_prog_info_value));
        value->proto = proto;
        value->ett = ett;
-
-       lc_progname = proto_registrar_get_abbrev(proto);
-       if ( lc_progname )
-       {
-               int i;
-               uc_progname = strdup(lc_progname);
-               for (i=0; i<strlen(uc_progname); i++)
-               {
-                       uc_progname[i] = toupper(uc_progname[i]);
-               }
-       }
-       value->progname = uc_progname;
+       value->progname = proto_get_protocol_short_name(proto);
 
        g_hash_table_insert(rpc_progs,key,value);
 }
@@ -300,55 +404,38 @@ char *rpc_prog_name(guint32 prog)
 /* end of Hash array with program names */
 /*--------------------------------------*/
 
-/* static array, first quick implementation, I'll switch over to GList soon */ 
-rpc_call_info rpc_call_table[RPC_CALL_TABLE_LENGTH];
-guint32 rpc_call_index = 0;
-guint32 rpc_call_firstfree = 0;
+typedef struct _rpc_call_info_key {
+       guint32 xid;
+       conversation_t *conversation;
+} rpc_call_info_key;
 
-void
-rpc_call_insert(rpc_call_info *call)
+static GMemChunk *rpc_call_info_key_chunk;
+
+static GMemChunk *rpc_call_info_value_chunk;
+
+static GHashTable *rpc_calls;
+
+static GHashTable *rpc_indir_calls;
+
+/* compare 2 keys */
+static gint
+rpc_call_equal(gconstpointer k1, gconstpointer k2)
 {
-       /* some space left? */
-       if (rpc_call_firstfree<RPC_CALL_TABLE_LENGTH) {
-               /* some space left */
-               /* take the first free entry */
-               rpc_call_index = rpc_call_firstfree;
-               /* increase this limit */
-               rpc_call_firstfree++;
-               /* rpc_call_firstfree may now be RPC_CALL_TABLE_LENGTH */
-       }
-       else {
-               /* no space left */
-               /* the next entry, with wrap around */
-               rpc_call_index = (rpc_call_index+1) % rpc_call_firstfree;
-       }
-               
-       /* put the entry in */
-       memcpy(&rpc_call_table[rpc_call_index],call,sizeof(*call));
-       return;
+       rpc_call_info_key* key1 = (rpc_call_info_key*) k1;
+       rpc_call_info_key* key2 = (rpc_call_info_key*) k2;
+
+       return (key1->xid == key2->xid &&
+           key1->conversation == key2->conversation);
 }
 
 
-rpc_call_info*
-rpc_call_lookup(rpc_call_info *call)
+/* calculate a hash key */
+static guint
+rpc_call_hash(gconstpointer k)
 {
-       int i;
-
-       i = rpc_call_index;
-       do {
-               if (
-                       rpc_call_table[i].xid == call->xid &&
-                       rpc_call_table[i].conversation == call->conversation
-               ) {
-                       return &rpc_call_table[i];
-               }
-               if (rpc_call_firstfree) {
-                       /* decrement by one, go to rpc_call_firstfree-1 
-                          at the start of the list */
-                       i = (i-1+rpc_call_firstfree) % rpc_call_firstfree;
-               }
-       } while (i!=rpc_call_index);
-       return NULL;
+       rpc_call_info_key* key = (rpc_call_info_key*) k;
+
+       return key->xid + (guint32)(key->conversation);
 }
 
 
@@ -361,23 +448,7 @@ rpc_roundup(unsigned int a)
 
 
 int
-dissect_rpc_bool(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
-int hfindex)
-{
-       guint32 value;
-
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       value = EXTRACT_UINT(pd, offset+0);
-       if (tree)
-               proto_tree_add_boolean(tree, hfindex, NullTVB, offset, 4, value);
-       offset += 4;
-
-       return offset;
-}
-
-
-int
-dissect_rpc_bool_tvb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+dissect_rpc_bool(tvbuff_t *tvb, proto_tree *tree,
 int hfindex, int offset)
 {
        if (tree)
@@ -387,26 +458,7 @@ int hfindex, int offset)
 
 
 int
-dissect_rpc_uint32(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
-char* name)
-{
-       guint32 value;
-
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       value = EXTRACT_UINT(pd, offset+0);
-
-       if (tree) {
-               proto_tree_add_text(tree, NullTVB, offset, 4,
-               "%s: %u", name, value);
-       }
-
-       offset += 4;
-       return offset;
-}
-
-
-int
-dissect_rpc_uint32_tvb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+dissect_rpc_uint32(tvbuff_t *tvb, proto_tree *tree,
 int hfindex, int offset)
 {
        if (tree)
@@ -416,54 +468,22 @@ int hfindex, int offset)
 
 
 int
-dissect_rpc_uint64(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
-char* name)
-{
-       guint32 value_low;
-       guint32 value_high;
-
-       if (!BYTES_ARE_IN_FRAME(offset,8)) return offset;
-       value_high = EXTRACT_UINT(pd, offset+0);
-       value_low = EXTRACT_UINT(pd, offset+4);
-
-       if (tree) {
-               if (value_high)
-                       proto_tree_add_text(tree, NullTVB, offset, 8,
-                               "%s: 0x%x%08x", name, value_high, value_low);
-               else
-                       proto_tree_add_text(tree, NullTVB, offset, 8,
-                               "%s: %u", name, value_low);
-       }
-
-       offset += 8;
-       return offset;
-}
-
-
-int
-dissect_rpc_uint64_tvb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+dissect_rpc_uint64(tvbuff_t *tvb, proto_tree *tree,
 int hfindex, int offset)
 {
-       guint32 value_low;
-       guint32 value_high;
-
-       value_high = tvb_get_ntohl(tvb, offset + 0);
-       value_low  = tvb_get_ntohl(tvb, offset + 4);
+       header_field_info       *hfinfo;
 
-       if (tree) {
-               if (value_high)
-                       proto_tree_add_text(tree, tvb, offset, 8,
-                               "%s: 0x%x%08x", proto_registrar_get_name(hfindex), value_high, value_low);
-               else
-                       proto_tree_add_uint(tree, hfindex, tvb, offset, 8, value_low);
-       }
+       hfinfo = proto_registrar_get_nth(hfindex);
+       g_assert(hfinfo->type == FT_UINT64);
+       if (tree)
+               proto_tree_add_item(tree, hfindex, tvb, offset, 8, FALSE);
 
        return offset + 8;
 }
 
 
 static int
-dissect_rpc_opaque_data(const u_char *pd, int offset, frame_data *fd,
+dissect_rpc_opaque_data(tvbuff_t *tvb, int offset,
     proto_tree *tree, int hfindex, gboolean string_data,
     char **string_buffer_ret)
 {
@@ -471,145 +491,148 @@ dissect_rpc_opaque_data(const u_char *pd, int offset, frame_data *fd,
        proto_tree *string_tree = NULL;
        int old_offset = offset;
 
-       int length_truncated = 0;
-
-       int string_truncated = 0;
-       guint32 string_length = 0;
+       guint32 string_length;
        guint32 string_length_full;
        guint32 string_length_packet;
-       guint32 string_length_copy = 0;
+       guint32 string_length_captured;
+       guint32 string_length_copy;
 
-       int fill_truncated = 0;
-       guint32 fill_length  = 0;
-       guint32 fill_length_packet  = 0;
-       guint32 fill_length_copy  = 0;
+       int fill_truncated;
+       guint32 fill_length;
+       guint32 fill_length_packet;
+       guint32 fill_length_captured;
+       guint32 fill_length_copy;
+
+       int exception = 0;
 
        char *string_buffer = NULL;
        char *string_buffer_print = NULL;
 
-       if (BYTES_ARE_IN_FRAME(offset,4)) {
-               string_length = EXTRACT_UINT(pd,offset+0);
-               string_length_full = rpc_roundup(string_length);
-               string_length_packet = pi.captured_len - (offset + 4);
-               if (string_length_packet < string_length) {
-                       /* truncated string */
-                       string_truncated = 1;
-                       string_length_copy = string_length_packet;
-                       fill_truncated = 2;
-                       fill_length = 0;
-                       fill_length_packet = 0;
-                       fill_length_copy = 0;
+       string_length = tvb_get_ntohl(tvb,offset+0);
+       string_length_full = rpc_roundup(string_length);
+       string_length_captured = tvb_length_remaining(tvb, offset + 4);
+       string_length_packet = tvb_reported_length_remaining(tvb, offset + 4);
+       if (string_length_captured < string_length) {
+               /* truncated string */
+               string_length_copy = string_length_captured;
+               fill_truncated = 2;
+               fill_length = 0;
+               fill_length_copy = 0;
+               if (string_length_packet < string_length)
+                       exception = ReportedBoundsError;
+               else
+                       exception = BoundsError;
+       }
+       else {
+               /* full string data */
+               string_length_copy = string_length;
+               fill_length = string_length_full - string_length;
+               fill_length_captured = tvb_length_remaining(tvb,
+                   offset + 4 + string_length);
+               fill_length_packet = tvb_reported_length_remaining(tvb,
+                   offset + 4 + string_length);
+               if (fill_length_captured < fill_length) {
+                       /* truncated fill bytes */
+                       fill_length_copy = fill_length_packet;
+                       fill_truncated = 1;
+                       if (fill_length_packet < fill_length)
+                               exception = ReportedBoundsError;
+                       else
+                               exception = BoundsError;
                }
                else {
-                       /* full string data */
-                       string_truncated = 0;
-                       string_length_copy = string_length;
-                       fill_length = string_length_full - string_length;
-                       fill_length_packet = pi.captured_len - (offset + 4 + string_length);
-                       if (fill_length_packet < fill_length) {
-                               /* truncated fill bytes */
-                               fill_length_copy = fill_length_packet;
-                               fill_truncated = 1;
-                       }
-                       else {
-                               /* full fill bytes */
-                               fill_length_copy = fill_length;
-                               fill_truncated = 0;
-                       }
+                       /* full fill bytes */
+                       fill_length_copy = fill_length;
+                       fill_truncated = 0;
                }
-               string_buffer = (char*)g_malloc(string_length_copy + 
+       }
+       string_buffer = (char*)g_malloc(string_length_copy + 
                        (string_data ? 1 : 0));
-               memcpy(string_buffer,pd+offset+4,string_length_copy);
-               if (string_data)
-                       string_buffer[string_length_copy] = '\0';
-
-               /* calculate a nice printable string */
-               if (string_length) {
-                       if (string_length != string_length_copy) {
-                               if (string_data) {
-                                       /* alloc maximum data area */
-                                       string_buffer_print = (char*)g_malloc(string_length_copy + 12 + 1);
-                                       /* copy over the data */
-                                       memcpy(string_buffer_print,string_buffer,string_length_copy);
-                                       /* append a 0 byte for sure printing */
-                                       string_buffer_print[string_length_copy] = '\0';
-                                       /* append <TRUNCATED> */
-                                       /* This way, we get the TRUNCATED even
-                                          in the case of totally wrong packets,
-                                          where \0 are inside the string.
-                                          TRUNCATED will appear at the
-                                          first \0 or at the end (where we 
-                                          put the securing \0).
-                                       */
-                                       strcat(string_buffer_print,"<TRUNCATED>");
-                               }
-                               else {
-                                       string_buffer_print = g_strdup("<DATA><TRUNCATED>");
-                               }
+       tvb_memcpy(tvb,string_buffer,offset+4,string_length_copy);
+       if (string_data)
+               string_buffer[string_length_copy] = '\0';
+
+       /* calculate a nice printable string */
+       if (string_length) {
+               if (string_length != string_length_copy) {
+                       if (string_data) {
+                               /* alloc maximum data area */
+                               string_buffer_print = (char*)g_malloc(string_length_copy + 12 + 1);
+                               /* copy over the data */
+                               memcpy(string_buffer_print,string_buffer,string_length_copy);
+                               /* append a 0 byte for sure printing */
+                               string_buffer_print[string_length_copy] = '\0';
+                               /* append <TRUNCATED> */
+                               /* This way, we get the TRUNCATED even
+                                  in the case of totally wrong packets,
+                                  where \0 are inside the string.
+                                  TRUNCATED will appear at the
+                                  first \0 or at the end (where we 
+                                  put the securing \0).
+                               */
+                               strcat(string_buffer_print,"<TRUNCATED>");
                        }
                        else {
-                               if (string_data) {
-                                       string_buffer_print = g_strdup(string_buffer);
-                               }
-                               else {
-                                       string_buffer_print = g_strdup("<DATA>");
-                               }
+                               string_buffer_print = g_strdup("<DATA><TRUNCATED>");
                        }
                }
                else {
-                       string_buffer_print = g_strdup("<EMPTY>");
+                       if (string_data) {
+                               string_buffer_print = g_strdup(string_buffer);
+                       }
+                       else {
+                               string_buffer_print = g_strdup("<DATA>");
+                       }
                }
        }
        else {
-               length_truncated = 1;
-               string_truncated = 2;
-               fill_truncated = 2;
-               string_buffer = g_strdup("");
-               string_buffer_print = g_strdup("<TRUNCATED>");
+               string_buffer_print = g_strdup("<EMPTY>");
        }
 
        if (tree) {
-               string_item = proto_tree_add_text(tree, NullTVB,offset+0, END_OF_FRAME,
+               string_item = proto_tree_add_text(tree, tvb,offset+0, -1,
                        "%s: %s", proto_registrar_get_name(hfindex), string_buffer_print);
                if (string_data) {
-                       proto_tree_add_string_hidden(tree, hfindex, NullTVB, offset+4,
+                       proto_tree_add_string_hidden(tree, hfindex, tvb, offset+4,
                                string_length_copy, string_buffer);
                }
                if (string_item) {
                        string_tree = proto_item_add_subtree(string_item, ett_rpc_string);
                }
        }
-       if (length_truncated) {
-               if (string_tree)
-                       proto_tree_add_text(string_tree, NullTVB,
-                               offset,pi.captured_len-offset,
-                               "length: <TRUNCATED>");
-               offset = pi.captured_len;
-       } else {
-               if (string_tree)
-                       proto_tree_add_text(string_tree, NullTVB,offset+0,4,
-                               "length: %u", string_length);
-               offset += 4;
+       if (string_tree)
+               proto_tree_add_text(string_tree, tvb,offset+0,4,
+                       "length: %u", string_length);
+       offset += 4;
 
-               if (string_tree)
-                       proto_tree_add_text(string_tree, NullTVB,offset,string_length_copy,
+       if (string_tree) {
+               if (string_data) {
+                       proto_tree_add_string_format(string_tree,
+                           hfindex, tvb, offset, string_length_copy,
+                               string_buffer_print, 
                                "contents: %s", string_buffer_print);
-               offset += string_length_copy;
-               if (fill_length) {
-                       if (string_tree) {
-                               if (fill_truncated) {
-                                       proto_tree_add_text(string_tree, NullTVB,
-                                       offset,fill_length_copy,
-                                       "fill bytes: opaque data<TRUNCATED>");
-                               }
-                               else {
-                                       proto_tree_add_text(string_tree, NullTVB,
-                                       offset,fill_length_copy,
-                                       "fill bytes: opaque data");
-                               }
+               } else {
+                       proto_tree_add_bytes_format(string_tree,
+                           hfindex, tvb, offset, string_length_copy,
+                               string_buffer_print, 
+                               "contents: %s", string_buffer_print);
+               }
+       }
+       offset += string_length_copy;
+       if (fill_length) {
+               if (string_tree) {
+                       if (fill_truncated) {
+                               proto_tree_add_text(string_tree, tvb,
+                               offset,fill_length_copy,
+                               "fill bytes: opaque data<TRUNCATED>");
+                       }
+                       else {
+                               proto_tree_add_text(string_tree, tvb,
+                               offset,fill_length_copy,
+                               "fill bytes: opaque data");
                        }
-                       offset += fill_length_copy;
                }
+               offset += fill_length_copy;
        }
        
        if (string_item) {
@@ -623,80 +646,51 @@ dissect_rpc_opaque_data(const u_char *pd, int offset, frame_data *fd,
                else
                        g_free (string_buffer_print);
        }
-       return offset;
-}
 
-
-int
-dissect_rpc_string(const u_char *pd, int offset, frame_data *fd,
-    proto_tree *tree, int hfindex, char **string_buffer_ret)
-{
-       offset = dissect_rpc_opaque_data(pd, offset, fd, tree, hfindex, TRUE,
-           string_buffer_ret);
-
-       return offset;
-}
-
-
-int
-dissect_rpc_string_tvb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int hfindex, int offset, char **string_buffer_ret)
-{
-       const guint8 *pd;
-       int compat_offset;
-       int compat_offset_new;
-
-       tvb_compat(tvb, &pd, &compat_offset);
-       compat_offset += offset;
-       
-       compat_offset_new = dissect_rpc_string(pd, compat_offset, pinfo->fd,
-                               tree, hfindex, string_buffer_ret);
-       offset += (compat_offset_new - compat_offset);
+       /*
+        * If the data was truncated, throw the appropriate exception,
+        * so that dissection stops and the frame is properly marked.
+        */
+       if (exception != 0)
+               THROW(exception);
        return offset;
 }
 
 
 int
-dissect_rpc_data(const u_char *pd, int offset, frame_data *fd,
-    proto_tree *tree, int hfindex)
+dissect_rpc_string(tvbuff_t *tvb, proto_tree *tree,
+    int hfindex, int offset, char **string_buffer_ret)
 {
-       offset = dissect_rpc_opaque_data(pd, offset, fd, tree, hfindex, FALSE,
-           NULL);
-
+       offset = dissect_rpc_opaque_data(tvb, offset, tree,
+           hfindex, TRUE, string_buffer_ret);
        return offset;
 }
 
 
 int
-dissect_rpc_data_tvb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int hfindex, int offset)
+dissect_rpc_data(tvbuff_t *tvb, proto_tree *tree,
+    int hfindex, int offset)
 {
-       const guint8 *pd;
-       int compat_offset;
-       int compat_offset_new;
+       offset = dissect_rpc_opaque_data(tvb, offset, tree, hfindex,
+           FALSE, NULL);
 
-       tvb_compat(tvb, &pd, &compat_offset);
-       compat_offset += offset;
-       
-       compat_offset_new = dissect_rpc_data(pd, compat_offset, pinfo->fd,
-                               tree, hfindex);
-       offset += (compat_offset_new - compat_offset);
        return offset;
 }
 
 
 int
-dissect_rpc_list(const u_char *pd, int offset, frame_data *fd,
-       proto_tree *tree, dissect_function_t *rpc_list_dissector)
+dissect_rpc_list(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+       int offset, dissect_function_t *rpc_list_dissector)
 {
        guint32 value_follows;
 
        while (1) {
-               if (!BYTES_ARE_IN_FRAME(offset,4)) break;
-               value_follows = EXTRACT_UINT(pd, offset+0);
-               proto_tree_add_boolean(tree,hf_rpc_value_follows, NullTVB,
+               value_follows = tvb_get_ntohl(tvb, offset+0);
+               proto_tree_add_boolean(tree,hf_rpc_value_follows, tvb,
                        offset+0, 4, value_follows);
                offset += 4;
                if (value_follows == 1) {
-                       offset = rpc_list_dissector(pd, offset, fd, tree);
+                       offset = rpc_list_dissector(tvb, offset, pinfo, tree);
                }
                else {
                        break;
@@ -706,8 +700,43 @@ dissect_rpc_list(const u_char *pd, int offset, frame_data *fd,
        return offset;
 }
 
+int
+dissect_rpc_array(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+       int offset, dissect_function_t *rpc_array_dissector,
+       int hfindex)
+{
+       proto_item* lock_item;
+       proto_tree* lock_tree;
+       guint32 num;
+       int old_offset = offset;
+
+       num = tvb_get_ntohl(tvb, offset);
+
+       if( num == 0 ){
+               proto_tree_add_none_format(tree, hfindex, tvb, offset, 4,
+                       "no values");
+               offset += 4;
+
+               return offset;
+       }
+
+       lock_item = proto_tree_add_item(tree, hfindex, tvb, offset, -1, FALSE);
+
+       lock_tree = proto_item_add_subtree(lock_item, ett_rpc_array);   
+
+       offset = dissect_rpc_uint32(tvb, lock_tree,
+                       hf_rpc_array_len, offset);
+
+       while (num--) {
+               offset = rpc_array_dissector(tvb, offset, pinfo, lock_tree);
+       }
+
+       proto_item_set_len(lock_item, offset-old_offset);
+       return offset;
+}
+
 static int
-dissect_rpc_authunix_cred(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_rpc_authunix_cred(tvbuff_t* tvb, proto_tree* tree, int offset)
 {
        guint stamp;
        guint uid;
@@ -718,44 +747,39 @@ dissect_rpc_authunix_cred(const u_char *pd, int offset, frame_data *fd, proto_tr
        proto_item *gitem;
        proto_tree *gtree = NULL;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       stamp = EXTRACT_UINT(pd,offset+0);
+       stamp = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_auth_stamp, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_auth_stamp, tvb,
                        offset+0, 4, stamp);
        offset += 4;
 
-       offset = dissect_rpc_string(pd,offset,fd,
-               tree,hf_rpc_auth_machinename,NULL);
+       offset = dissect_rpc_string(tvb, tree,
+                       hf_rpc_auth_machinename, offset, NULL);
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       uid = EXTRACT_UINT(pd,offset+0);
+       uid = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_auth_uid, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_auth_uid, tvb,
                        offset+0, 4, uid);
        offset += 4;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       gid = EXTRACT_UINT(pd,offset+0);
+       gid = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_auth_gid, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_auth_gid, tvb,
                        offset+0, 4, gid);
        offset += 4;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       gids_count = EXTRACT_UINT(pd,offset+0);
+       gids_count = tvb_get_ntohl(tvb,offset+0);
        if (tree) {
-               gitem = proto_tree_add_text(tree, NullTVB, offset, 4+gids_count*4,
-               "Auxiliary GIDs");
+               gitem = proto_tree_add_text(tree, tvb,
+                       offset, 4+gids_count*4, "Auxiliary GIDs");
                gtree = proto_item_add_subtree(gitem, ett_rpc_gids);
        }
        offset += 4;
        
-       if (!BYTES_ARE_IN_FRAME(offset,4*gids_count)) return offset;
        for (gids_i = 0 ; gids_i < gids_count ; gids_i++) {
-               gids_entry = EXTRACT_UINT(pd,offset+0);
+               gids_entry = tvb_get_ntohl(tvb,offset+0);
                if (gtree)
-               proto_tree_add_uint(gtree, hf_rpc_auth_gid, NullTVB,
+               proto_tree_add_uint(gtree, hf_rpc_auth_gid, tvb,
                        offset, 4, gids_entry);
                offset+=4;
        }
@@ -766,50 +790,101 @@ dissect_rpc_authunix_cred(const u_char *pd, int offset, frame_data *fd, proto_tr
 }
 
 static int
-dissect_rpc_authgss_cred(const u_char *pd, int offset,
-                        frame_data *fd, proto_tree *tree)
+dissect_rpc_authgss_cred(tvbuff_t* tvb, proto_tree* tree, int offset)
 {
        guint agc_v;
        guint agc_proc;
        guint agc_seq;
        guint agc_svc;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       agc_v = EXTRACT_UINT(pd, offset+0);
+       agc_v = tvb_get_ntohl(tvb, offset+0);
        if (tree)
                proto_tree_add_uint(tree, hf_rpc_authgss_v,
-                                   NullTVB, offset+0, 4, agc_v);
+                                   tvb, offset+0, 4, agc_v);
        offset += 4;
        
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       agc_proc = EXTRACT_UINT(pd, offset+0);
+       agc_proc = tvb_get_ntohl(tvb, offset+0);
        if (tree)
                proto_tree_add_uint(tree, hf_rpc_authgss_proc,
-                                   NullTVB, offset+0, 4, agc_proc);
+                                   tvb, offset+0, 4, agc_proc);
        offset += 4;
        
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       agc_seq = EXTRACT_UINT(pd, offset+0);
+       agc_seq = tvb_get_ntohl(tvb, offset+0);
        if (tree)
                proto_tree_add_uint(tree, hf_rpc_authgss_seq,
-                                   NullTVB, offset+0, 4, agc_seq);
+                                   tvb, offset+0, 4, agc_seq);
        offset += 4;
        
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       agc_svc = EXTRACT_UINT(pd, offset+0);
+       agc_svc = tvb_get_ntohl(tvb, offset+0);
        if (tree)
                proto_tree_add_uint(tree, hf_rpc_authgss_svc,
-                                   NullTVB, offset+0, 4, agc_svc);
+                                   tvb, offset+0, 4, agc_svc);
        offset += 4;
        
-       offset = dissect_rpc_data(pd,offset,fd,tree,
-                                 hf_rpc_authgss_ctx);
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_ctx,
+                       offset);
        
        return offset;
 }
 
 static int
-dissect_rpc_cred( const u_char *pd, int offset, frame_data *fd, proto_tree *tree )
+dissect_rpc_authdes_desblock(tvbuff_t *tvb, proto_tree *tree,
+int hfindex, int offset)
+{
+       guint32 value_low;
+       guint32 value_high;
+
+       value_high = tvb_get_ntohl(tvb, offset + 0);
+       value_low  = tvb_get_ntohl(tvb, offset + 4);
+
+       if (tree) {
+               proto_tree_add_text(tree, tvb, offset, 8,
+                       "%s: 0x%x%08x", proto_registrar_get_name(hfindex), value_high, 
+                       value_low);
+       }
+
+       return offset + 8;
+}
+
+static int
+dissect_rpc_authdes_cred(tvbuff_t* tvb, proto_tree* tree, int offset)
+{
+       guint adc_namekind;
+       guint window = 0;
+       guint nickname = 0;
+
+       adc_namekind = tvb_get_ntohl(tvb, offset+0);
+       if (tree)
+               proto_tree_add_uint(tree, hf_rpc_authdes_namekind,
+                                   tvb, offset+0, 4, adc_namekind);
+       offset += 4;
+
+       switch(adc_namekind)
+       {
+       case AUTHDES_NAMEKIND_FULLNAME:
+               offset = dissect_rpc_string(tvb, tree, 
+                       hf_rpc_authdes_netname, offset, NULL);
+               offset = dissect_rpc_authdes_desblock(tvb, tree,
+                       hf_rpc_authdes_convkey, offset);
+               window = tvb_get_ntohl(tvb, offset+0);
+               proto_tree_add_uint(tree, hf_rpc_authdes_window, tvb, offset+0, 4,
+                       window);
+               offset += 4;
+               break;
+
+       case AUTHDES_NAMEKIND_NICKNAME:
+               nickname = tvb_get_ntohl(tvb, offset+0);
+               proto_tree_add_uint(tree, hf_rpc_authdes_nickname, tvb, offset+0, 4,
+                       window);
+               offset += 4;
+               break;
+       }
+
+       return offset;
+}
+
+static int
+dissect_rpc_cred(tvbuff_t* tvb, proto_tree* tree, int offset)
 {
        guint flavor;
        guint length;
@@ -817,54 +892,52 @@ dissect_rpc_cred( const u_char *pd, int offset, frame_data *fd, proto_tree *tree
        proto_item *citem;
        proto_tree *ctree;
 
-       if (!BYTES_ARE_IN_FRAME(offset,8)) return offset;
-       flavor = EXTRACT_UINT(pd,offset+0);
-       length = EXTRACT_UINT(pd,offset+4);
+       flavor = tvb_get_ntohl(tvb,offset+0);
+       length = tvb_get_ntohl(tvb,offset+4);
        length = rpc_roundup(length);
-       if (!BYTES_ARE_IN_FRAME(offset+8,length)) return offset;
 
        if (tree) {
-               citem = proto_tree_add_text(tree, NullTVB, offset,
+               citem = proto_tree_add_text(tree, tvb, offset,
                                            8+length, "Credentials");
                ctree = proto_item_add_subtree(citem, ett_rpc_cred);
-               proto_tree_add_uint(ctree, hf_rpc_auth_flavor, NullTVB,
+               proto_tree_add_uint(ctree, hf_rpc_auth_flavor, tvb,
                                    offset+0, 4, flavor);
-               proto_tree_add_uint(ctree, hf_rpc_auth_length, NullTVB,
+               proto_tree_add_uint(ctree, hf_rpc_auth_length, tvb,
                                    offset+4, 4, length);
 
                switch (flavor) {
                case AUTH_UNIX:
-                       dissect_rpc_authunix_cred(pd, offset+8, fd, ctree);
+                       dissect_rpc_authunix_cred(tvb, ctree, offset+8);
                        break;
                /*
                case AUTH_SHORT:
 
                break;
                */
-               /* I have no tcpdump file with such a packet to verify the
-                       info from the RFC 1050 */
-               /*
                case AUTH_DES:
-
-               break;
-               */
-               case AUTH_GSS:
-                       dissect_rpc_authgss_cred(pd, offset+8, fd, ctree);
+                       dissect_rpc_authdes_cred(tvb, ctree, offset+8);
+                       break;
+                       
+               case RPCSEC_GSS:
+                       dissect_rpc_authgss_cred(tvb, ctree, offset+8);
                        break;
                default:
                        if (length)
-                               proto_tree_add_text(ctree, NullTVB, offset+8,
+                               proto_tree_add_text(ctree, tvb, offset+8,
                                                    length,"opaque data");
-                       break;
-       }
+               break;
+               }
        }
        offset += 8 + length;
 
        return offset;
 }
 
+/* AUTH_DES verifiers are asymmetrical, so we need to know what type of
+ * verifier we're decoding (CALL or REPLY).
+ */
 static int
-dissect_rpc_verf( const u_char *pd, int offset, frame_data *fd, proto_tree *tree )
+dissect_rpc_verf(tvbuff_t* tvb, proto_tree* tree, int offset, int msg_type)
 {
        guint flavor;
        guint length;
@@ -872,34 +945,58 @@ dissect_rpc_verf( const u_char *pd, int offset, frame_data *fd, proto_tree *tree
        proto_item *vitem;
        proto_tree *vtree;
 
-       if (!BYTES_ARE_IN_FRAME(offset,8)) return offset;
-       flavor = EXTRACT_UINT(pd,offset+0);
-       length = EXTRACT_UINT(pd,offset+4);
+       flavor = tvb_get_ntohl(tvb,offset+0);
+       length = tvb_get_ntohl(tvb,offset+4);
        length = rpc_roundup(length);
-       if (!BYTES_ARE_IN_FRAME(offset+8,length)) return offset;
 
        if (tree) {
-               vitem = proto_tree_add_text(tree, NullTVB, offset,
+               vitem = proto_tree_add_text(tree, tvb, offset,
                                            8+length, "Verifier");
                vtree = proto_item_add_subtree(vitem, ett_rpc_verf);
-               proto_tree_add_uint(vtree, hf_rpc_auth_flavor, NullTVB,
+               proto_tree_add_uint(vtree, hf_rpc_auth_flavor, tvb,
                                    offset+0, 4, flavor);
 
                switch (flavor) {
                case AUTH_UNIX:
-                       proto_tree_add_uint(vtree, hf_rpc_auth_length, NullTVB,
+                       proto_tree_add_uint(vtree, hf_rpc_auth_length, tvb,
                                            offset+4, 4, length);
-                       dissect_rpc_authunix_cred(pd, offset+8, fd, vtree);
+                       dissect_rpc_authunix_cred(tvb, vtree, offset+8);
+                       break;
+               case AUTH_DES:
+                       proto_tree_add_uint(vtree, hf_rpc_auth_length, tvb,
+                               offset+4, 4, length);
+
+                       if (msg_type == RPC_CALL)
+                       {
+                               guint window;
+
+                               dissect_rpc_authdes_desblock(tvb, vtree,
+                                       hf_rpc_authdes_timestamp, offset+8);
+                               window = tvb_get_ntohl(tvb, offset+16);
+                               proto_tree_add_uint(vtree, hf_rpc_authdes_windowverf, tvb, 
+                                       offset+16, 4, window);
+                       }
+                       else
+                       {
+                               /* must be an RPC_REPLY */
+                               guint nickname;
+
+                               dissect_rpc_authdes_desblock(tvb, vtree,
+                                       hf_rpc_authdes_timeverf, offset+8);
+                               nickname = tvb_get_ntohl(tvb, offset+16);
+                               proto_tree_add_uint(vtree, hf_rpc_authdes_nickname, tvb, 
+                                       offset+16, 4, nickname);
+                       }
                        break;
-               case AUTH_GSS:
-                       dissect_rpc_data(pd, offset+4, fd, vtree,
-                                        hf_rpc_authgss_checksum);
+               case RPCSEC_GSS:
+                       dissect_rpc_data(tvb, vtree,
+                               hf_rpc_authgss_checksum, offset+4);
                        break;
                default:
-                       proto_tree_add_uint(vtree, hf_rpc_auth_length, NullTVB,
+                       proto_tree_add_uint(vtree, hf_rpc_auth_length, tvb,
                                            offset+4, 4, length);
                        if (length)
-                               proto_tree_add_text(vtree, NullTVB, offset+8,
+                               proto_tree_add_text(vtree, tvb, offset+8,
                                                    length, "opaque data");
                        break;
                }
@@ -910,168 +1007,471 @@ dissect_rpc_verf( const u_char *pd, int offset, frame_data *fd, proto_tree *tree
 }
 
 static int
-dissect_rpc_authgss_initarg(const u_char *pd, int offset,
-                           frame_data *fd, proto_tree *tree)
+dissect_rpc_authgss_initarg(tvbuff_t* tvb, proto_tree* tree, int offset)
 {
-       offset = dissect_rpc_data(pd, offset, fd, tree, hf_rpc_authgss_token);
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_token,
+                       offset);
        return offset;
 }
 
 static int
-dissect_rpc_authgss_initres(const u_char *pd, int offset,
-                           frame_data *fd, proto_tree *tree)
+dissect_rpc_authgss_initres(tvbuff_t* tvb, proto_tree* tree, int offset)
 {
        int major, minor, window;
        
-       offset = dissect_rpc_data(pd, offset, fd, tree, hf_rpc_authgss_ctx);
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_ctx,
+                       offset);
        
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       major = EXTRACT_UINT(pd,offset+0);
+       major = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_authgss_major, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_authgss_major, tvb,
                                    offset+0, 4, major);
        offset += 4;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       minor = EXTRACT_UINT(pd,offset+0);
+       minor = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_authgss_minor, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_authgss_minor, tvb,
                                    offset+0, 4, minor);
        offset += 4;
 
-       if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
-       window = EXTRACT_UINT(pd,offset+0);
+       window = tvb_get_ntohl(tvb,offset+0);
        if (tree)
-               proto_tree_add_uint(tree, hf_rpc_authgss_window, NullTVB,
+               proto_tree_add_uint(tree, hf_rpc_authgss_window, tvb,
                                    offset+0, 4, window);
        offset += 4;
 
-       offset = dissect_rpc_data(pd, offset, fd, tree, hf_rpc_authgss_token);
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_token,
+                       offset);
+
+       return offset;
+}
+
+
+static int
+call_dissect_function(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+       int offset, dissect_function_t* dissect_function, const char *progname)
+{
+       const char *saved_proto;
+
+       if (dissect_function != NULL) {
+               /* set the current protocol name */
+               saved_proto = pinfo->current_proto;
+               if (progname != NULL)
+                       pinfo->current_proto = progname;
+
+               /* call the dissector for the next level */
+               offset = dissect_function(tvb, offset, pinfo, tree);
+
+               /* restore the protocol name */
+               pinfo->current_proto = saved_proto;
+       }
 
        return offset;
 }
 
+
 static int
-dissect_rpc_authgss_integ_data(const u_char *pd, int offset,
-                              frame_data *fd, proto_tree *tree,
-                              dissect_function_t *dissect_function)
+dissect_rpc_authgss_integ_data(tvbuff_t *tvb, packet_info *pinfo,
+       proto_tree *tree, int offset,
+       dissect_function_t* dissect_function,
+       const char *progname)
 {
        guint32 length, seq;
        
        proto_item *gitem;
-       proto_tree *gtree;
+       proto_tree *gtree = NULL;
 
-       if (!BYTES_ARE_IN_FRAME(offset, 8)) return offset;
-       length = EXTRACT_UINT(pd, offset+0);
+       length = tvb_get_ntohl(tvb, offset+0);
        length = rpc_roundup(length);
-       seq = EXTRACT_UINT(pd,offset+4);
+       seq = tvb_get_ntohl(tvb, offset+4);
 
        if (tree) {
-               gitem = proto_tree_add_text(tree, NullTVB, offset,
+               gitem = proto_tree_add_text(tree, tvb, offset,
                                            4+length, "GSS Data");
                gtree = proto_item_add_subtree(gitem, ett_rpc_gss_data);
                proto_tree_add_uint(gtree, hf_rpc_authgss_data_length,
-                                   NullTVB, offset+0, 4, length);
+                                   tvb, offset+0, 4, length);
                proto_tree_add_uint(gtree, hf_rpc_authgss_seq,
-                                   NullTVB, offset+4, 4, seq);
-               if (dissect_function != NULL)
-                       offset = dissect_function(pd, offset, fd, gtree);
+                                   tvb, offset+4, 4, seq);
        }
-       offset += 8 + length;
-       offset = dissect_rpc_data(pd, offset, fd, tree, hf_rpc_authgss_checksum);
+       offset += 8;
+
+       if (dissect_function != NULL) {
+               /* offset = */
+               call_dissect_function(tvb, pinfo, gtree, offset,
+                                     dissect_function, progname);
+       }
+       offset += length - 4;
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_checksum,
+                       offset);
        return offset;
 }
 
+
 static int
-dissect_rpc_authgss_priv_data(const u_char *pd, int offset,
-                        frame_data *fd, proto_tree *tree)
+dissect_rpc_authgss_priv_data(tvbuff_t *tvb, proto_tree *tree, int offset)
 {
-       offset = dissect_rpc_data(pd, offset, fd, tree, hf_rpc_authgss_data);
+       offset = dissect_rpc_data(tvb, tree, hf_rpc_authgss_data,
+                       offset);
        return offset;
 }
 
-gboolean
-dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+/*
+ * Dissect the arguments to an indirect call; used by the portmapper/RPCBIND
+ * dissector.
+ *
+ * Record this call in a hash table, similar to the hash table for
+ * direct calls, so we can find it when dissecting an indirect call reply.
+ */
+int
+dissect_rpc_indir_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+    int offset, int args_id, guint32 prog, guint32 vers, guint32 proc)
 {
-       guint32 msg_type;
-       rpc_call_info rpc_key;
-       rpc_call_info *rpc_call = NULL;
-       rpc_prog_info_value *rpc_prog = NULL;
-       rpc_prog_info_key rpc_prog_key;
+       conversation_t* conversation;
+       static address null_address = { AT_NONE, 0, NULL };
+       rpc_proc_info_key key;
+       rpc_proc_info_value *value;
+       rpc_call_info_value *rpc_call;
+       rpc_call_info_key rpc_call_key;
+       rpc_call_info_key *new_rpc_call_key;
+       dissect_function_t *dissect_function = NULL;
 
-       unsigned int xid;
-       unsigned int rpcvers;
-       unsigned int prog = 0;
-       unsigned int vers = 0;
-       unsigned int proc = 0;
-       unsigned int flavor = 0;
-       unsigned int gss_proc = 0;
-       unsigned int gss_svc = 0;
-       int     proto = 0;
-       int     ett = 0;
+       key.prog = prog;
+       key.vers = vers;
+       key.proc = proc;
+       if ((value = g_hash_table_lookup(rpc_procs,&key)) != NULL) {
+               dissect_function = value->dissect_call;
 
-       unsigned int reply_state;
-       unsigned int accept_state;
-       unsigned int reject_state;
+               /* Keep track of the address and port whence the call came,
+                  and the port to which the call is being sent, so that
+                  we can match up calls with replies.
 
-       char *msg_type_name = NULL;
-       char *progname;
-       char *procname = NULL;
-       static char procname_static[20];
+                  If the transport is connection-oriented (we check, for
+                  now, only for "pinfo->ptype" of PT_TCP), we take
+                  into account the address from which the call was sent
+                  and the address to which the call was sent, because
+                  the addresses of the two endpoints should be the same
+                  for all calls and replies.
 
-       unsigned int vers_low;
-       unsigned int vers_high;
+                  If the transport is connectionless, we don't worry
+                  about the address to which the call was sent and from
+                  which the reply was sent, because there's no
+                  guarantee that the reply will come from the address
+                  to which the call was sent. */
+               if (pinfo->ptype == PT_TCP) {
+                       conversation = find_conversation(&pinfo->src,
+                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               } else {
+                       /*
+                        * XXX - can we just use NO_ADDR_B?  Unfortunately,
+                        * you currently still have to pass a non-null
+                        * pointer for the second address argument even
+                        * if you do that.
+                        */
+                       conversation = find_conversation(&pinfo->src,
+                           &null_address, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               }
+               if (conversation == NULL) {
+                       /* It's not part of any conversation - create a new
+                          one.
+
+                          XXX - this should never happen, as we should've
+                          created a conversation for it in the RPC
+                          dissector. */
+                       if (pinfo->ptype == PT_TCP) {
+                               conversation = conversation_new(&pinfo->src,
+                                   &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                                   pinfo->destport, 0);
+                       } else {
+                               conversation = conversation_new(&pinfo->src,
+                                   &null_address, pinfo->ptype, pinfo->srcport,
+                                   pinfo->destport, 0);
+                       }
+               }
 
-       unsigned int auth_state;
+               /* Make the dissector for this conversation the non-heuristic
+                  RPC dissector. */
+               conversation_set_dissector(conversation,
+                   (pinfo->ptype == PT_TCP) ? rpc_tcp_handle : rpc_handle);
 
-       proto_item *rpc_item=NULL;
-       proto_tree *rpc_tree = NULL;
+               /* Prepare the key data.
 
-       proto_item *pitem=NULL;
-       proto_tree *ptree = NULL;
-       int offset_old = offset;
+                  Dissectors for RPC procedure calls and replies shouldn't
+                  create new tvbuffs, and we don't create one ourselves,
+                  so we should have been handed the tvbuff for this RPC call;
+                  as such, the XID is at offset 0 in this tvbuff. */
+               rpc_call_key.xid = tvb_get_ntohl(tvb, 0);
+               rpc_call_key.conversation = conversation;
 
-       int use_rm = 0;
-       guint32 rpc_rm = 0;
+               /* look up the request */
+               rpc_call = g_hash_table_lookup(rpc_indir_calls, &rpc_call_key);
+               if (rpc_call == NULL) {
+                       /* We didn't find it; create a new entry.
+                          Prepare the value data.
+                          Not all of it is needed for handling indirect
+                          calls, so we set a bunch of items to 0. */
+                       new_rpc_call_key = g_mem_chunk_alloc(rpc_call_info_key_chunk);
+                       *new_rpc_call_key = rpc_call_key;
+                       rpc_call = g_mem_chunk_alloc(rpc_call_info_value_chunk);
+                       rpc_call->req_num = 0;
+                       rpc_call->rep_num = 0;
+                       rpc_call->prog = prog;
+                       rpc_call->vers = vers;
+                       rpc_call->proc = proc;
+                       rpc_call->private_data = NULL;
+
+                       /*
+                        * XXX - what about RPCSEC_GSS?
+                        * Do we have to worry about it?
+                        */
+                       rpc_call->flavor = FLAVOR_NOT_GSSAPI;
+                       rpc_call->gss_proc = 0;
+                       rpc_call->gss_svc = 0;
+                       rpc_call->proc_info = value;
+                       /* store it */
+                       g_hash_table_insert(rpc_indir_calls, new_rpc_call_key,
+                           rpc_call);
+               }
+       }
+       else {
+               /* We don't know the procedure.
+                  Happens only with strange program versions or
+                  non-existing dissectors.
+                  Just show the arguments as opaque data. */
+               offset = dissect_rpc_data(tvb, tree, args_id,
+                   offset);
+               return offset;
+       }
 
-       rpc_call_info   rpc_call_msg;
-       rpc_proc_info_key       key;
-       rpc_proc_info_value     *value = NULL;
-       conversation_t* conversation;
-       static address null_address = { AT_NONE, 0, NULL };
+       if ( tree )
+       {
+               proto_tree_add_text(tree, tvb, offset, 4,
+                       "Argument length: %u",
+                       tvb_get_ntohl(tvb, offset));
+       }
+       offset += 4;
 
+       /* Dissect the arguments */
+       offset = call_dissect_function(tvb, pinfo, tree, offset,
+                       dissect_function, NULL);
+       return offset;
+}
+
+/*
+ * Dissect the results in an indirect reply; used by the portmapper/RPCBIND
+ * dissector.
+ */
+int
+dissect_rpc_indir_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+    int offset, int result_id, int prog_id, int vers_id, int proc_id)
+{
+       conversation_t* conversation;
+       static address null_address = { AT_NONE, 0, NULL };
+       rpc_call_info_key rpc_call_key;
+       rpc_call_info_value *rpc_call;
+       char *procname = NULL;
+       char procname_static[20];
        dissect_function_t *dissect_function = NULL;
 
-       if (!proto_is_protocol_enabled(proto_rpc))
-         return FALSE;
+       /* Look for the matching call in the hash table of indirect
+          calls.  A reply must match a call that we've seen, and the
+          reply must be sent to the same port and address that the
+          call came from, and must come from the port to which the
+          call was sent.
+
+          If the transport is connection-oriented (we check, for
+          now, only for "pinfo->ptype" of PT_TCP), we take
+          into account the address from which the call was sent
+          and the address to which the call was sent, because
+          the addresses of the two endpoints should be the same
+          for all calls and replies.
+
+          If the transport is connectionless, we don't worry
+          about the address to which the call was sent and from
+          which the reply was sent, because there's no
+          guarantee that the reply will come from the address
+          to which the call was sent. */
+       if (pinfo->ptype == PT_TCP) {
+               conversation = find_conversation(&pinfo->src, &pinfo->dst,
+                   pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
+       } else {
+               /*
+                * XXX - can we just use NO_ADDR_B?  Unfortunately,
+                * you currently still have to pass a non-null
+                * pointer for the second address argument even
+                * if you do that.
+                */
+               conversation = find_conversation(&null_address, &pinfo->dst,
+                   pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
+       }
+       if (conversation == NULL) {
+               /* We haven't seen an RPC call for that conversation,
+                  so we can't check for a reply to that call.
+                  Just show the reply stuff as opaque data. */
+               offset = dissect_rpc_data(tvb, tree, result_id,
+                   offset);
+               return offset;
+       }
 
-       /* TCP uses record marking */
-       use_rm = (pi.ptype == PT_TCP);
+       /* The XIDs of the call and reply must match. */
+       rpc_call_key.xid = tvb_get_ntohl(tvb, 0);
+       rpc_call_key.conversation = conversation;
+       rpc_call = g_hash_table_lookup(rpc_indir_calls, &rpc_call_key);
+       if (rpc_call == NULL) {
+               /* The XID doesn't match a call from that
+                  conversation, so it's probably not an RPC reply.
+                  Just show the reply stuff as opaque data. */
+               offset = dissect_rpc_data(tvb, tree, result_id,
+                   offset);
+               return offset;
+       }
 
-       /* the first 4 bytes are special in "record marking  mode" */
-       if (use_rm) {
-               if (!BYTES_ARE_IN_FRAME(offset,4))
-                       return FALSE;
-               rpc_rm = EXTRACT_UINT(pd,offset);
-               offset += 4;
+       if (rpc_call->proc_info != NULL) {
+               dissect_function = rpc_call->proc_info->dissect_reply;
+               if (rpc_call->proc_info->name != NULL) {
+                       procname = rpc_call->proc_info->name;
+               }
+               else {
+                       sprintf(procname_static, "proc-%u", rpc_call->proc);
+                       procname = procname_static;
+               }
+       }
+       else {
+#if 0
+               dissect_function = NULL;
+#endif
+               sprintf(procname_static, "proc-%u", rpc_call->proc);
+               procname = procname_static;
+       }
+
+       if ( tree )
+       {
+               /* Put the program, version, and procedure into the tree. */
+               proto_tree_add_uint_format(tree, prog_id, tvb,
+                       0, 0, rpc_call->prog, "Program: %s (%u)",
+                       rpc_prog_name(rpc_call->prog), rpc_call->prog);
+               proto_tree_add_uint(tree, vers_id, tvb, 0, 0, rpc_call->vers);
+               proto_tree_add_uint_format(tree, proc_id, tvb,
+                       0, 0, rpc_call->proc, "Procedure: %s (%u)",
+                       procname, rpc_call->proc);
+       }
+
+       if (dissect_function == NULL) {
+               /* We don't know how to dissect the reply procedure.
+                  Just show the reply stuff as opaque data. */
+               offset = dissect_rpc_data(tvb, tree, result_id,
+                   offset);
+               return offset;
+       }
+
+       if (tree) {
+               /* Put the length of the reply value into the tree. */
+               proto_tree_add_text(tree, tvb, offset, 4,
+                       "Argument length: %u",
+                       tvb_get_ntohl(tvb, offset));
        }
+       offset += 4;
+
+       /* Dissect the return value */
+       offset = call_dissect_function(tvb, pinfo, tree, offset,
+                       dissect_function, NULL);
+       return offset;
+}
+
+/*
+ * Just mark this as a continuation of an earlier packet.
+ */
+static void
+dissect_rpc_continuation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       proto_item *rpc_item;
+       proto_tree *rpc_tree;
+
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "RPC");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
+
+       if (tree) {
+               rpc_item = proto_tree_add_item(tree, proto_rpc, tvb, 0, -1,
+                               FALSE);
+               rpc_tree = proto_item_add_subtree(rpc_item, ett_rpc);
+               proto_tree_add_text(rpc_tree, tvb, 0, -1, "Continuation data");
+       }
+}
+
+static gboolean
+dissect_rpc_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+    tvbuff_t *frag_tvb, fragment_data *ipfd_head, gboolean is_tcp,
+    guint32 rpc_rm)
+{
+       guint32 msg_type;
+       rpc_call_info_key rpc_call_key;
+       rpc_call_info_value *rpc_call = NULL;
+       rpc_prog_info_value *rpc_prog = NULL;
+       rpc_prog_info_key rpc_prog_key;
+
+       unsigned int xid;
+       unsigned int rpcvers;
+       unsigned int prog = 0;
+       unsigned int vers = 0;
+       unsigned int proc = 0;
+       flavor_t flavor = FLAVOR_UNKNOWN;
+       unsigned int gss_proc = 0;
+       unsigned int gss_svc = 0;
+       int     proto = 0;
+       int     ett = 0;
+
+       unsigned int reply_state;
+       unsigned int accept_state;
+       unsigned int reject_state;
+
+       char *msg_type_name = NULL;
+       char *progname = NULL;
+       char *procname = NULL;
+       static char procname_static[20];
+
+       unsigned int vers_low;
+       unsigned int vers_high;
+
+       unsigned int auth_state;
+
+       proto_item *rpc_item = NULL;
+       proto_tree *rpc_tree = NULL;
+
+       proto_item *pitem = NULL;
+       proto_tree *ptree = NULL;
+       int offset = (is_tcp && tvb == frag_tvb) ? 4 : 0;
+       int offset_old = offset;
+
+       rpc_call_info_key       *new_rpc_call_key;
+       rpc_proc_info_key       key;
+       rpc_proc_info_value     *value = NULL;
+       conversation_t* conversation;
+       static address null_address = { AT_NONE, 0, NULL };
+       nstime_t ns;
+
+       dissect_function_t *dissect_function = NULL;
+       gboolean dissect_rpc = TRUE;
 
        /*
         * Check to see whether this looks like an RPC call or reply.
         */
-       if (!BYTES_ARE_IN_FRAME(offset,8)) {
+       if (!tvb_bytes_exist(tvb, offset, 8)) {
                /* Captured data in packet isn't enough to let us tell. */
                return FALSE;
        }
 
        /* both directions need at least this */
-       msg_type = EXTRACT_UINT(pd,offset+4);
+       msg_type = tvb_get_ntohl(tvb, offset + 4);
 
        switch (msg_type) {
 
        case RPC_CALL:
                /* check for RPC call */
-               if (!BYTES_ARE_IN_FRAME(offset,16)) {
+               if (!tvb_bytes_exist(tvb, offset, 16)) {
                        /* Captured data in packet isn't enough to let us
                           tell. */
                        return FALSE;
@@ -1081,9 +1481,9 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                   We already have the message type.
                   Check whether an RPC version number of 2 is in the
                   location where it would be, and that an RPC program
-                  number we know about is in the locaton where it would be. */
-               rpc_prog_key.prog = EXTRACT_UINT(pd,offset+12);
-               if (EXTRACT_UINT(pd,offset+8) != 2 ||
+                  number we know about is in the location where it would be. */
+               rpc_prog_key.prog = tvb_get_ntohl(tvb, offset + 12);
+               if (tvb_get_ntohl(tvb, offset + 8) != 2 ||
                    ((rpc_prog = g_hash_table_lookup(rpc_progs, &rpc_prog_key))
                       == NULL)) {
                        /* They're not, so it's probably not an RPC call. */
@@ -1095,13 +1495,35 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                /* Check for RPC reply.  A reply must match a call that
                   we've seen, and the reply must be sent to the same
                   port and address that the call came from, and must
-                  come from the port to which the call was sent.  (We
-                  don't worry about the address to which the call was
-                  sent and from which the reply was sent, because there's
-                  no guarantee that the reply will come from the address
-                  to which the call was sent.) */
-               conversation = find_conversation(&null_address, &pi.dst,
-                   pi.ptype, pi.srcport, pi.destport);
+                  come from the port to which the call was sent.
+
+                  If the transport is connection-oriented (we check, for
+                  now, only for "pinfo->ptype" of PT_TCP), we take
+                  into account the address from which the call was sent
+                  and the address to which the call was sent, because
+                  the addresses of the two endpoints should be the same
+                  for all calls and replies.
+
+                  If the transport is connectionless, we don't worry
+                  about the address to which the call was sent and from
+                  which the reply was sent, because there's no
+                  guarantee that the reply will come from the address
+                  to which the call was sent. */
+               if (pinfo->ptype == PT_TCP) {
+                       conversation = find_conversation(&pinfo->src,
+                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               } else {
+                       /*
+                        * XXX - can we just use NO_ADDR_B?  Unfortunately,
+                        * you currently still have to pass a non-null
+                        * pointer for the second address argument even
+                        * if you do that.
+                        */
+                       conversation = find_conversation(&null_address,
+                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               }
                if (conversation == NULL) {
                        /* We haven't seen an RPC call for that conversation,
                           so we can't check for a reply to that call. */
@@ -1109,13 +1531,17 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                }
 
                /* The XIDs of the call and reply must match. */
-               rpc_key.xid = EXTRACT_UINT(pd,offset+0);
-               rpc_key.conversation = conversation;
-               if ((rpc_call = rpc_call_lookup(&rpc_key)) == NULL) {
+               rpc_call_key.xid = tvb_get_ntohl(tvb, offset + 0);
+               rpc_call_key.conversation = conversation;
+               rpc_call = g_hash_table_lookup(rpc_calls, &rpc_call_key);
+               if (rpc_call == NULL) {
                        /* The XID doesn't match a call from that
                           conversation, so it's probably not an RPC reply. */
                        return FALSE;
                }
+               /* pass rpc_info to subdissectors */
+               rpc_call->request=FALSE;
+               pinfo->private_data=rpc_call;
                break;
 
        default:
@@ -1125,84 +1551,91 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                return FALSE;
        }
 
-       if (check_col(fd, COL_PROTOCOL))
-               col_add_str(fd, COL_PROTOCOL, "RPC");
-
-       if (tree) {
-               rpc_item = proto_tree_add_item(tree, proto_rpc, NullTVB, offset, END_OF_FRAME, FALSE);
-               if (rpc_item) {
-                       rpc_tree = proto_item_add_subtree(rpc_item, ett_rpc);
+       if (is_tcp) {
+               /*
+                * This is RPC-over-TCP; check if this is the last
+                * fragment.
+                */
+               if (!(rpc_rm & RPC_RM_LASTFRAG)) {
+                       /*
+                        * This isn't the last fragment.
+                        * If we're doing reassembly, just return
+                        * TRUE to indicate that this looks like
+                        * the beginning of an RPC message,
+                        * and let them do fragment reassembly.
+                        */
+                       if (rpc_defragment)
+                               return TRUE;
                }
        }
 
-       if (use_rm && rpc_tree) {
-               proto_tree_add_boolean(rpc_tree,hf_rpc_lastfrag, NullTVB,
-                       offset-4, 4, (rpc_rm >> 31) & 0x1);
-               proto_tree_add_uint(rpc_tree,hf_rpc_fraglen, NullTVB,
-                       offset-4, 4, rpc_rm & RPC_RM_FRAGLEN);
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "RPC");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
+
+       if (tree) {
+               rpc_item = proto_tree_add_item(tree, proto_rpc, tvb, 0, -1,
+                   FALSE);
+               rpc_tree = proto_item_add_subtree(rpc_item, ett_rpc);
+
+               if (is_tcp) {
+                       show_rpc_fraginfo(tvb, frag_tvb, rpc_tree, rpc_rm,
+                           ipfd_head, pinfo);
+               }
        }
 
-       xid      = EXTRACT_UINT(pd,offset+0);
+       xid      = tvb_get_ntohl(tvb, offset + 0);
        if (rpc_tree) {
-               proto_tree_add_uint_format(rpc_tree,hf_rpc_xid, NullTVB,
+               proto_tree_add_uint_format(rpc_tree,hf_rpc_xid, tvb,
                        offset+0, 4, xid, "XID: 0x%x (%u)", xid, xid);
        }
 
        msg_type_name = val_to_str(msg_type,rpc_msg_type,"%u");
        if (rpc_tree) {
-               proto_tree_add_uint(rpc_tree, hf_rpc_msgtype, NullTVB,
+               proto_tree_add_uint(rpc_tree, hf_rpc_msgtype, tvb,
                        offset+4, 4, msg_type);
        }
 
        offset += 8;
 
-       if (msg_type==RPC_CALL) {
+       switch (msg_type) {
+
+       case RPC_CALL:
                /* we know already the proto-entry, the ETT-const,
                   and "rpc_prog" */
                proto = rpc_prog->proto;
                ett = rpc_prog->ett;
                progname = rpc_prog->progname;
 
-               rpcvers = EXTRACT_UINT(pd,offset+0);
+               rpcvers = tvb_get_ntohl(tvb, offset + 0);
                if (rpc_tree) {
                        proto_tree_add_uint(rpc_tree,
-                               hf_rpc_version, NullTVB, offset+0, 4, rpcvers);
+                               hf_rpc_version, tvb, offset+0, 4, rpcvers);
                }
 
-               prog = EXTRACT_UINT(pd,offset+4);
+               prog = tvb_get_ntohl(tvb, offset + 4);
                
                if (rpc_tree) {
                        proto_tree_add_uint_format(rpc_tree,
-                               hf_rpc_program, NullTVB, offset+4, 4, prog,
+                               hf_rpc_program, tvb, offset+4, 4, prog,
                                "Program: %s (%u)", progname, prog);
                }
                
-               if (check_col(fd, COL_PROTOCOL)) {
+               if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
                        /* Set the protocol name to the underlying
                           program name. */
-                       col_add_fstr(fd, COL_PROTOCOL, "%s", progname);
+                       col_set_str(pinfo->cinfo, COL_PROTOCOL, progname);
                }
 
-               if (!BYTES_ARE_IN_FRAME(offset+8,4))
-                       return TRUE;
-               vers = EXTRACT_UINT(pd,offset+8);
+               vers = tvb_get_ntohl(tvb, offset+8);
                if (rpc_tree) {
                        proto_tree_add_uint(rpc_tree,
-                               hf_rpc_programversion, NullTVB, offset+8, 4, vers);
+                               hf_rpc_programversion, tvb, offset+8, 4, vers);
                }
 
-               if (!BYTES_ARE_IN_FRAME(offset+12,4))
-                       return TRUE;
-               proc = EXTRACT_UINT(pd,offset+12);
+               proc = tvb_get_ntohl(tvb, offset+12);
 
-               /* Check for RPCSEC_GSS */
-               if (proc == 0 && BYTES_ARE_IN_FRAME(offset+16,28)) {
-                       flavor = EXTRACT_UINT(pd, offset+16);
-                       if (flavor == AUTH_GSS) {
-                               gss_proc = EXTRACT_UINT(pd, offset+28);
-                               gss_svc = EXTRACT_UINT(pd, offset+34);
-                       }
-               }
                key.prog = prog;
                key.vers = vers;
                key.proc = proc;
@@ -1214,81 +1647,184 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                else {
                        /* happens only with strange program versions or
                           non-existing dissectors */
+#if 0
                        dissect_function = NULL;
+#endif
                        sprintf(procname_static, "proc-%u", proc);
                        procname = procname_static;
                }
                
                if (rpc_tree) {
                        proto_tree_add_uint_format(rpc_tree,
-                               hf_rpc_procedure, NullTVB, offset+12, 4, proc,
+                               hf_rpc_procedure, tvb, offset+12, 4, proc,
                                "Procedure: %s (%u)", procname, proc);
                }
 
-               if (check_col(fd, COL_INFO)) {
-                       col_add_fstr(fd, COL_INFO,"V%u %s %s XID 0x%x",
+               if (check_col(pinfo->cinfo, COL_INFO)) {
+                       col_add_fstr(pinfo->cinfo, COL_INFO,"V%u %s %s XID 0x%x",
                                vers,
                                procname,
                                msg_type_name,
                                xid);
                }
 
+               /* Check for RPCSEC_GSS */
+               if (tvb_bytes_exist(tvb, offset+16, 4)) {
+                       switch (tvb_get_ntohl(tvb, offset+16)) {
+
+                       case RPCSEC_GSS:
+                               /*
+                                * It's GSS-API authentication...
+                                */
+                               if (tvb_bytes_exist(tvb, offset+28, 8)) {
+                                       /*
+                                        * ...and we have the procedure
+                                        * and service information for it.
+                                        */
+                                       flavor = FLAVOR_GSSAPI;
+                                       gss_proc = tvb_get_ntohl(tvb, offset+28);
+                                       gss_svc = tvb_get_ntohl(tvb, offset+36);
+                               } else {
+                                       /*
+                                        * ...but the procedure and service
+                                        * information isn't available.
+                                        */
+                                       flavor = FLAVOR_GSSAPI_NO_INFO;
+                               }
+                               break;
+
+                       default:
+                               /*
+                                * It's not GSS-API authentication.
+                                */
+                               flavor = FLAVOR_NOT_GSSAPI;
+                               break;
+                       }
+               }
+
                /* Keep track of the address and port whence the call came,
                   and the port to which the call is being sent, so that
-                  we can match up calls wityh replies.  (We don't worry
+                  we can match up calls with replies.
+
+                  If the transport is connection-oriented (we check, for
+                  now, only for "pinfo->ptype" of PT_TCP), we take
+                  into account the address from which the call was sent
+                  and the address to which the call was sent, because
+                  the addresses of the two endpoints should be the same
+                  for all calls and replies.
+
+                  If the transport is connectionless, we don't worry
                   about the address to which the call was sent and from
                   which the reply was sent, because there's no
                   guarantee that the reply will come from the address
-                  to which the call was sent.) */
-               conversation = find_conversation(&pi.src, &null_address,
-                   pi.ptype, pi.srcport, pi.destport);
+                  to which the call was sent. */
+               if (pinfo->ptype == PT_TCP) {
+                       conversation = find_conversation(&pinfo->src,
+                           &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               } else {
+                       /*
+                        * XXX - can we just use NO_ADDR_B?  Unfortunately,
+                        * you currently still have to pass a non-null
+                        * pointer for the second address argument even
+                        * if you do that.
+                        */
+                       conversation = find_conversation(&pinfo->src,
+                           &null_address, pinfo->ptype, pinfo->srcport,
+                           pinfo->destport, 0);
+               }
                if (conversation == NULL) {
-                       /* It's not part of any conversation - create a new one. */
-                       conversation = conversation_new(&pi.src, &null_address,
-                           pi.ptype, pi.srcport, pi.destport, NULL);
+                       /* It's not part of any conversation - create a new
+                          one. */
+                       if (pinfo->ptype == PT_TCP) {
+                               conversation = conversation_new(&pinfo->src,
+                                   &pinfo->dst, pinfo->ptype, pinfo->srcport,
+                                   pinfo->destport, 0);
+                       } else {
+                               conversation = conversation_new(&pinfo->src,
+                                   &null_address, pinfo->ptype, pinfo->srcport,
+                                   pinfo->destport, 0);
+                       }
                }
 
+               /* Make the dissector for this conversation the non-heuristic
+                  RPC dissector. */
+               conversation_set_dissector(conversation,
+                   (pinfo->ptype == PT_TCP) ? rpc_tcp_handle : rpc_handle);
+
                /* prepare the key data */
-               rpc_call_msg.xid = xid;
-               rpc_call_msg.conversation = conversation;
+               rpc_call_key.xid = xid;
+               rpc_call_key.conversation = conversation;
 
                /* look up the request */
-               if (rpc_call_lookup(&rpc_call_msg)) {
-                       /* duplicate request */
-                       if (check_col(fd, COL_INFO)) {
-                               col_append_fstr(fd, COL_INFO, " dup XID 0x%x", xid);
-                               if (rpc_tree) {
-                                       proto_tree_add_uint_hidden(rpc_tree,
-                                               hf_rpc_dup, NullTVB, 0,0, xid);
-                                       proto_tree_add_uint_hidden(rpc_tree,
-                                               hf_rpc_call_dup, NullTVB, 0,0, xid);
+               rpc_call = g_hash_table_lookup(rpc_calls, &rpc_call_key);
+               if (rpc_call != NULL) {
+                       /* We've seen a request with this XID, with the same
+                          source and destination, before - but was it
+                          *this* request? */
+                       if (pinfo->fd->num != rpc_call->req_num) {
+                               /* No, so it's a duplicate request.
+                                  Mark it as such. */
+                               if (check_col(pinfo->cinfo, COL_INFO)) {
+                                       col_append_fstr(pinfo->cinfo, COL_INFO,
+                                               " dup XID 0x%x", xid);
+                                       if (rpc_tree) {
+                                               proto_tree_add_uint_hidden(rpc_tree,
+                                                       hf_rpc_dup, tvb, 0,0, xid);
+                                               proto_tree_add_uint_hidden(rpc_tree,
+                                                       hf_rpc_call_dup, tvb, 0,0, xid);
+                                       }
                                }
                        }
                }
                else {
-                       /* prepare the value data */
-                       rpc_call_msg.replies = 0;
-                       rpc_call_msg.prog = prog;
-                       rpc_call_msg.vers = vers;
-                       rpc_call_msg.proc = proc;
-                       rpc_call_msg.flavor = flavor;
-                       rpc_call_msg.gss_proc = gss_proc;
-                       rpc_call_msg.gss_svc = gss_svc;
-                       rpc_call_msg.proc_info = value;
+                       /* Prepare the value data.
+                          "req_num" and "rep_num" are frame numbers;
+                          frame numbers are 1-origin, so we use 0
+                          to mean "we don't yet know in which frame
+                          the reply for this call appears". */
+                       new_rpc_call_key = g_mem_chunk_alloc(rpc_call_info_key_chunk);
+                       *new_rpc_call_key = rpc_call_key;
+                       rpc_call = g_mem_chunk_alloc(rpc_call_info_value_chunk);
+                       rpc_call->req_num = pinfo->fd->num;
+                       rpc_call->rep_num = 0;
+                       rpc_call->prog = prog;
+                       rpc_call->vers = vers;
+                       rpc_call->proc = proc;
+                       rpc_call->private_data = NULL;
+                       rpc_call->xid = xid;
+                       rpc_call->flavor = flavor;
+                       rpc_call->gss_proc = gss_proc;
+                       rpc_call->gss_svc = gss_svc;
+                       rpc_call->proc_info = value;
+                       rpc_call->req_time.secs=pinfo->fd->abs_secs;
+                       rpc_call->req_time.nsecs=pinfo->fd->abs_usecs*1000;
+
                        /* store it */
-                       rpc_call_insert(&rpc_call_msg);
+                       g_hash_table_insert(rpc_calls, new_rpc_call_key,
+                           rpc_call);
+               }
+
+               if(rpc_call && rpc_call->rep_num){
+                       proto_tree_add_text(rpc_tree, tvb, 0, 0,
+                           "The reply to this request is in frame %u",
+                           rpc_call->rep_num);
                }
 
                offset += 16;
 
-               offset = dissect_rpc_cred(pd, offset, fd, rpc_tree);
-               offset = dissect_rpc_verf(pd, offset, fd, rpc_tree);
+               offset = dissect_rpc_cred(tvb, rpc_tree, offset);
+               offset = dissect_rpc_verf(tvb, rpc_tree, offset, msg_type);
+
+               /* pass rpc_info to subdissectors */
+               rpc_call->request=TRUE;
+               pinfo->private_data=rpc_call;
 
                /* go to the next dissector */
 
-       } /* end of RPC call */
-       else if (msg_type == RPC_REPLY)
-       {
+               break;  /* end of RPC call */
+
+       case RPC_REPLY:
                /* we know already the type from the calling routine,
                   and we already have "rpc_call" set above. */
                prog = rpc_call->prog;
@@ -1309,11 +1845,12 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                        }
                }
                else {
+#if 0
                        dissect_function = NULL;
+#endif
                        sprintf(procname_static, "proc-%u", proc);
                        procname = procname_static;
                }
-               rpc_call->replies++;
 
                rpc_prog_key.prog = prog;
                if ((rpc_prog = g_hash_table_lookup(rpc_progs,&rpc_prog_key)) == NULL) {
@@ -1326,16 +1863,15 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                        ett = rpc_prog->ett;
                        progname = rpc_prog->progname;
 
-                       if (check_col(fd, COL_PROTOCOL)) {
+                       if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
                                /* Set the protocol name to the underlying
                                   program name. */
-                               col_add_fstr(fd, COL_PROTOCOL, "%s",
-                                   progname);
+                               col_set_str(pinfo->cinfo, COL_PROTOCOL, progname);
                        }
                }
 
-               if (check_col(fd, COL_INFO)) {
-                       col_add_fstr(fd, COL_INFO,"V%u %s %s XID 0x%x",
+               if (check_col(pinfo->cinfo, COL_INFO)) {
+                       col_add_fstr(pinfo->cinfo, COL_INFO,"V%u %s %s XID 0x%x",
                                vers,
                                procname,
                                msg_type_name,
@@ -1344,183 +1880,947 @@ dissect_rpc( const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
 
                if (rpc_tree) {
                        proto_tree_add_uint_format(rpc_tree,
-                               hf_rpc_program, NullTVB, 0, 0, prog,
+                               hf_rpc_program, tvb, 0, 0, prog,
                                "Program: %s (%u)", progname, prog);
                        proto_tree_add_uint(rpc_tree,
-                               hf_rpc_programversion, NullTVB, 0, 0, vers);
+                               hf_rpc_programversion, tvb, 0, 0, vers);
                        proto_tree_add_uint_format(rpc_tree,
-                               hf_rpc_procedure, NullTVB, 0, 0, proc,
+                               hf_rpc_procedure, tvb, 0, 0, proc,
                                "Procedure: %s (%u)", procname, proc);
                }
 
-               if (rpc_call->replies>1) {
-                       if (check_col(fd, COL_INFO)) {
-                               col_append_fstr(fd, COL_INFO, " dup XID 0x%x", xid);
-                               if (rpc_tree) {
-                                       proto_tree_add_uint_hidden(rpc_tree,
-                                               hf_rpc_dup, NullTVB, 0,0, xid);
-                                       proto_tree_add_uint_hidden(rpc_tree,
-                                               hf_rpc_reply_dup, NullTVB, 0,0, xid);
-                               }
-                       }
-               }
-
-               if (!BYTES_ARE_IN_FRAME(offset,4))
-                       return TRUE;
-               reply_state = EXTRACT_UINT(pd,offset+0);
+               reply_state = tvb_get_ntohl(tvb,offset+0);
                if (rpc_tree) {
-                       proto_tree_add_uint(rpc_tree, hf_rpc_state_reply, NullTVB,
+                       proto_tree_add_uint(rpc_tree, hf_rpc_state_reply, tvb,
                                offset+0, 4, reply_state);
                }
                offset += 4;
 
-               if (reply_state == MSG_ACCEPTED) {
-                       offset = dissect_rpc_verf(pd, offset, fd, rpc_tree);
-                       if (!BYTES_ARE_IN_FRAME(offset,4))
-                               return TRUE;
-                       accept_state = EXTRACT_UINT(pd,offset+0);
+               /* Indicate the frame to which this is a reply. */
+               if(rpc_call && rpc_call->req_num){
+                       proto_tree_add_text(rpc_tree, tvb, 0, 0,
+                           "This is a reply to a request in frame %u",
+                           rpc_call->req_num);
+                       ns.secs= pinfo->fd->abs_secs-rpc_call->req_time.secs;
+                       ns.nsecs=pinfo->fd->abs_usecs*1000-rpc_call->req_time.nsecs;
+                       if(ns.nsecs<0){
+                               ns.nsecs+=1000000000;
+                               ns.secs--;
+                       }
+                       proto_tree_add_time(rpc_tree, hf_rpc_time, tvb, offset, 0,
+                               &ns);
+               }
+
+
+               if (rpc_call->rep_num == 0) {
+                       /* We have not yet seen a reply to that call, so
+                          this must be the first reply; remember its
+                          frame number. */
+                       rpc_call->rep_num = pinfo->fd->num;
+               } else {
+                       /* We have seen a reply to this call - but was it
+                          *this* reply? */
+                       if (rpc_call->rep_num != pinfo->fd->num) {
+                               /* No, so it's a duplicate reply.
+                                  Mark it as such. */
+                               if (check_col(pinfo->cinfo, COL_INFO)) {
+                                       col_append_fstr(pinfo->cinfo, COL_INFO,
+                                               " dup XID 0x%x", xid);
+                                       if (rpc_tree) {
+                                               proto_tree_add_uint_hidden(rpc_tree,
+                                                       hf_rpc_dup, tvb, 0,0, xid);
+                                               proto_tree_add_uint_hidden(rpc_tree,
+                                                       hf_rpc_reply_dup, tvb, 0,0, xid);
+                                       }
+                               }
+                       }
+               }
+
+               switch (reply_state) {
+
+               case MSG_ACCEPTED:
+                       offset = dissect_rpc_verf(tvb, rpc_tree, offset, msg_type);
+                       accept_state = tvb_get_ntohl(tvb,offset+0);
                        if (rpc_tree) {
-                               proto_tree_add_uint(rpc_tree, hf_rpc_state_accept, NullTVB,
+                               proto_tree_add_uint(rpc_tree, hf_rpc_state_accept, tvb,
                                        offset+0, 4, accept_state);
                        }
                        offset += 4;
                        switch (accept_state) {
-                               case SUCCESS:
-                                       /* go to the next dissector */
+
+                       case SUCCESS:
+                               /* go to the next dissector */
                                break;
-                               case PROG_MISMATCH:
-                                       if (!BYTES_ARE_IN_FRAME(offset,8))
-                                               return TRUE;
-                                       vers_low = EXTRACT_UINT(pd,offset+0);
-                                       vers_high = EXTRACT_UINT(pd,offset+4);
-                                       if (rpc_tree) {
-                                               proto_tree_add_uint(rpc_tree,
-                                                       hf_rpc_programversion_min,
-                                                       NullTVB, offset+0, 4, vers_low);
-                                               proto_tree_add_uint(rpc_tree,
-                                                       hf_rpc_programversion_max,
-                                                       NullTVB, offset+4, 4, vers_high);
-                                       }
-                                       offset += 8;
+
+                       case PROG_MISMATCH:
+                               vers_low = tvb_get_ntohl(tvb,offset+0);
+                               vers_high = tvb_get_ntohl(tvb,offset+4);
+                               if (rpc_tree) {
+                                       proto_tree_add_uint(rpc_tree,
+                                               hf_rpc_programversion_min,
+                                               tvb, offset+0, 4, vers_low);
+                                       proto_tree_add_uint(rpc_tree,
+                                               hf_rpc_programversion_max,
+                                               tvb, offset+4, 4, vers_high);
+                               }
+                               offset += 8;
+
+                               /*
+                                * There's no protocol reply, so don't
+                                * try to dissect it.
+                                */
+                               dissect_rpc = FALSE;
                                break;
-                               default:
-                                       /* void */
+
+                       default:
+                               /*
+                                * There's no protocol reply, so don't
+                                * try to dissect it.
+                                */
+                               dissect_rpc = FALSE;
                                break;
                        }
-               } else if (reply_state == MSG_DENIED) {
-                       if (!BYTES_ARE_IN_FRAME(offset,4))
-                               return TRUE;
-                       reject_state = EXTRACT_UINT(pd,offset+0);
+                       break;
+
+               case MSG_DENIED:
+                       reject_state = tvb_get_ntohl(tvb,offset+0);
                        if (rpc_tree) {
                                proto_tree_add_uint(rpc_tree,
-                                       hf_rpc_state_reject, NullTVB, offset+0, 4,
+                                       hf_rpc_state_reject, tvb, offset+0, 4,
                                        reject_state);
                        }
                        offset += 4;
 
                        if (reject_state==RPC_MISMATCH) {
-                               if (!BYTES_ARE_IN_FRAME(offset,8))
-                                       return TRUE;
-                               vers_low = EXTRACT_UINT(pd,offset+0);
-                               vers_high = EXTRACT_UINT(pd,offset+4);
+                               vers_low = tvb_get_ntohl(tvb,offset+0);
+                               vers_high = tvb_get_ntohl(tvb,offset+4);
                                if (rpc_tree) {
                                        proto_tree_add_uint(rpc_tree,
                                                hf_rpc_version_min,
-                                               NullTVB, offset+0, 4, vers_low);
+                                               tvb, offset+0, 4, vers_low);
                                        proto_tree_add_uint(rpc_tree,
                                                hf_rpc_version_max,
-                                               NullTVB, offset+4, 4, vers_high);
+                                               tvb, offset+4, 4, vers_high);
                                }
                                offset += 8;
                        } else if (reject_state==AUTH_ERROR) {
-                               if (!BYTES_ARE_IN_FRAME(offset,4))
-                                       return TRUE;
-                               auth_state = EXTRACT_UINT(pd,offset+0);
+                               auth_state = tvb_get_ntohl(tvb,offset+0);
                                if (rpc_tree) {
                                        proto_tree_add_uint(rpc_tree,
-                                               hf_rpc_state_auth, NullTVB, offset+0, 4,
+                                               hf_rpc_state_auth, tvb, offset+0, 4,
                                                auth_state);
                                }
                                offset += 4;
                        }
+
+                       /*
+                        * There's no protocol reply, so don't
+                        * try to dissect it.
+                        */
+                       dissect_rpc = FALSE;
+                       break;
+
+               default:
+                       /*
+                        * This isn't a valid reply state, so we have
+                        * no clue what's going on; don't try to dissect
+                        * the protocol reply.
+                        */
+                       dissect_rpc = FALSE;
+                       break;
                } 
-       } /* end of RPC reply */
+               break; /* end of RPC reply */
+
+       default:
+               /*
+                * The switch statement at the top returned if
+                * this was neither an RPC call nor a reply.
+                */
+               g_assert_not_reached();
+       }
 
        /* now we know, that RPC was shorter */
        if (rpc_item) {
                proto_item_set_len(rpc_item, offset - offset_old);
        }
 
+       if (!dissect_rpc) {
+               /*
+                * There's no RPC call or reply here; just dissect
+                * whatever's left as data.
+                */
+               call_dissector(data_handle,
+                   tvb_new_subset(tvb, offset, -1, -1), pinfo, rpc_tree);
+               return TRUE;
+       }
+
        /* create here the program specific sub-tree */
        if (tree) {
-               pitem = proto_tree_add_item(tree, proto, NullTVB, offset, END_OF_FRAME, FALSE);
+               pitem = proto_tree_add_item(tree, proto, tvb, offset, -1,
+                   FALSE);
                if (pitem) {
                        ptree = proto_item_add_subtree(pitem, ett);
                }
 
                if (ptree) {
                        proto_tree_add_uint(ptree,
-                               hf_rpc_programversion, NullTVB, 0, 0, vers);
+                               hf_rpc_programversion, tvb, 0, 0, vers);
                        proto_tree_add_uint_format(ptree,
-                               hf_rpc_procedure, NullTVB, 0, 0, proc,
+                               hf_rpc_procedure, tvb, 0, 0, proc,
                                "Procedure: %s (%u)", procname, proc);
                }
        }
 
-       /* RPCSEC_GSS processing. */
-       if (flavor == AUTH_GSS) {
+       if (!proto_is_protocol_enabled(proto))
+               dissect_function = NULL;
+
+       /*
+        * Handle RPCSEC_GSS specially.
+        */
+       switch (flavor) {
+
+       case FLAVOR_UNKNOWN:
+               /*
+                * We don't know the authentication flavor, so we can't
+                * dissect the payload.
+                */
+               proto_tree_add_text(ptree, tvb, offset, -1,
+                   "Unknown authentication flavor - cannot dissect");
+               return TRUE;
+
+       case FLAVOR_NOT_GSSAPI:
+               /*
+                * It's not GSS-API authentication.  Just dissect the
+                * payload.
+                */
+               offset = call_dissect_function(tvb, pinfo, ptree, offset,
+                               dissect_function, progname);
+               break;
+
+       case FLAVOR_GSSAPI_NO_INFO:
+               /*
+                * It's GSS-API authentication, but we don't have the
+                * procedure and service information, so we can't dissect
+                * the payload.
+                */
+               proto_tree_add_text(ptree, tvb, offset, -1,
+                   "GSS-API authentication, but procedure and service unknown - cannot dissect");
+               return TRUE;
+
+       case FLAVOR_GSSAPI:
+               /*
+                * It's GSS-API authentication, and we have the procedure
+                * and service information; process the GSS-API stuff,
+                * and process the payload if there is any.
+                */
                switch (gss_proc) {
-               case AUTH_GSS_INIT:
-               case AUTH_GSS_CONTINUE_INIT:
+
+               case RPCSEC_GSS_INIT:
+               case RPCSEC_GSS_CONTINUE_INIT:
                        if (msg_type == RPC_CALL) {
-                               offset = dissect_rpc_authgss_initarg(pd, offset, fd, ptree);
+                               offset = dissect_rpc_authgss_initarg(tvb,
+                                       ptree, offset);
                        }
                        else {
-                               offset = dissect_rpc_authgss_initres(pd, offset, fd, ptree);
+                               offset = dissect_rpc_authgss_initres(tvb,
+                                       ptree, offset);
                        }
                        break;
-               case AUTH_GSS_DATA:
-                       if (gss_svc == AUTH_GSS_SVC_NONE) {
-                               if (dissect_function != NULL && 
-                                       proto_is_protocol_enabled(proto))
-                                       offset = dissect_function(pd, offset, fd, ptree);
+
+               case RPCSEC_GSS_DATA:
+                       if (gss_svc == RPCSEC_GSS_SVC_NONE) {
+                               offset = call_dissect_function(tvb, 
+                                               pinfo, ptree, offset,
+                                               dissect_function,
+                                               progname);
                        }
-                       else if (gss_svc == AUTH_GSS_SVC_INTEGRITY) {
-                               offset = dissect_rpc_authgss_integ_data(pd, offset, fd, ptree, 
-                               (proto_is_protocol_enabled(proto) ? 
-                               dissect_function : NULL));
+                       else if (gss_svc == RPCSEC_GSS_SVC_INTEGRITY) {
+                               offset = dissect_rpc_authgss_integ_data(tvb,
+                                               pinfo, ptree, offset,
+                                               dissect_function,
+                                               progname);
                        }
-                       else if (gss_svc == AUTH_GSS_SVC_PRIVACY) {
-                               offset = dissect_rpc_authgss_priv_data(pd, offset, fd, ptree);
+                       else if (gss_svc == RPCSEC_GSS_SVC_PRIVACY) {
+                               offset = dissect_rpc_authgss_priv_data(tvb,
+                                               ptree, offset);
                        }
                        break;
+
                default:
-                       dissect_function = NULL;
                        break;
                }
        }
-       else if (dissect_function != NULL &&
-               proto_is_protocol_enabled(proto)) {
-               offset = dissect_function(pd, offset, fd, ptree);
-       }
 
        /* dissect any remaining bytes (incomplete dissection) as pure data in
           the ptree */
-       old_dissect_data(pd, offset, fd, ptree);
+       call_dissector(data_handle,
+           tvb_new_subset(tvb, offset, -1, -1), pinfo, ptree);
+
+
+       /* XXX this should really loop over all fhandles registred for the frame */
+       if(nfs_fhandle_reqrep_matching){
+               nfs_fhandle_data_t *fhd;
+               switch (msg_type) {
+               case RPC_CALL:
+                       if(rpc_call && rpc_call->rep_num){
+                               fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
+                                       nfs_fhandle_frame_table, 
+                                       (gconstpointer)rpc_call->rep_num);
+                               if(fhd){
+                                       dissect_fhandle_hidden(pinfo,
+                                               ptree, fhd);
+                               }
+                       }
+                       break;
+               case RPC_REPLY:
+                       if(rpc_call && rpc_call->req_num){
+                               fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
+                                       nfs_fhandle_frame_table, 
+                                       (gconstpointer)rpc_call->req_num);
+                               if(fhd){
+                                       dissect_fhandle_hidden(pinfo,
+                                               ptree, fhd);
+                               }
+                       }
+                       break;
+               }
+       }
 
        return TRUE;
 }
 
+static gboolean
+dissect_rpc_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       return dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0);
+}
+
+static void
+dissect_rpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       if (!dissect_rpc_message(tvb, pinfo, tree, NULL, NULL, FALSE, 0))
+               dissect_rpc_continuation(tvb, pinfo, tree);
+}
+
+/* Defragmentation of RPC-over-TCP records */
+/* table to hold defragmented RPC records */
+static GHashTable *rpc_fragment_table = NULL;
+
+static GHashTable *rpc_reassembly_table = NULL;
+static GMemChunk *rpc_fragment_key_chunk = NULL;
+static int rpc_fragment_init_count = 200;
+
+typedef struct _rpc_fragment_key {
+       guint32 conv_id;
+       guint32 seq;
+       guint32 offset;
+       /* xxx */
+       guint32 start_seq;
+} rpc_fragment_key;
+
+static guint
+rpc_fragment_hash(gconstpointer k)
+{
+       rpc_fragment_key *key = (rpc_fragment_key *)k;
+
+       return key->conv_id + key->seq;
+}
+
+static gint
+rpc_fragment_equal(gconstpointer k1, gconstpointer k2)
+{
+       rpc_fragment_key *key1 = (rpc_fragment_key *)k1;
+       rpc_fragment_key *key2 = (rpc_fragment_key *)k2;
+
+       return key1->conv_id == key2->conv_id &&
+           key1->seq == key2->seq;
+}
+
+static void
+show_rpc_fragheader(tvbuff_t *tvb, proto_tree *tree, guint32 rpc_rm)
+{
+       proto_item *hdr_item;
+       proto_tree *hdr_tree;
+       guint32 fraglen;
+
+       if (tree) {
+               fraglen = rpc_rm & RPC_RM_FRAGLEN;
+
+               hdr_item = proto_tree_add_text(tree, tvb, 0, 4,
+                   "Fragment header: %s%u %s",
+                   (rpc_rm & RPC_RM_LASTFRAG) ? "Last fragment, " : "",
+                   fraglen, plurality(fraglen, "byte", "bytes"));
+               hdr_tree = proto_item_add_subtree(hdr_item, ett_rpc_fraghdr);
+
+               proto_tree_add_boolean(hdr_tree, hf_rpc_lastfrag, tvb, 0, 4,
+                   rpc_rm);
+               proto_tree_add_uint(hdr_tree, hf_rpc_fraglen, tvb, 0, 4,
+                   rpc_rm);
+       }
+}
+
+static void
+show_rpc_fragment(tvbuff_t *tvb, proto_tree *tree, guint32 rpc_rm)
+{
+       if (tree) {
+               /*
+                * Show the fragment header and the data for the fragment.
+                */
+               show_rpc_fragheader(tvb, tree, rpc_rm);
+               proto_tree_add_text(tree, tvb, 4, -1, "Fragment Data");
+       }
+}
+
+static void
+make_frag_tree(tvbuff_t *tvb, proto_tree *tree, int proto, gint ett,
+    guint32 rpc_rm)
+{
+       proto_item *frag_item;
+       proto_tree *frag_tree;
+
+       if (tree == NULL)
+               return;         /* nothing to do */
+
+       frag_item = proto_tree_add_protocol_format(tree, proto, tvb, 0, -1,
+           "%s Fragment", proto_get_protocol_name(proto));
+       frag_tree = proto_item_add_subtree(frag_item, ett);
+       show_rpc_fragment(tvb, frag_tree, rpc_rm);
+}
+
+void
+show_rpc_fraginfo(tvbuff_t *tvb, tvbuff_t *frag_tvb, proto_tree *tree,
+    guint32 rpc_rm, fragment_data *ipfd_head, packet_info *pinfo)
+{
+       if (tree == NULL)
+               return;         /* don't do any work */
+
+       if (tvb != frag_tvb) {
+               /*
+                * This message was not all in one fragment,
+                * so show the fragment header *and* the data
+                * for the fragment (which is the last fragment),
+                * and a tree with information about all fragments.
+                */
+               show_rpc_fragment(frag_tvb, tree, rpc_rm);
+
+               /*
+                * Show a tree with information about all fragments.
+                */
+               show_fragment_tree(ipfd_head, &rpc_frag_items, tree, pinfo, tvb);
+       } else {
+               /*
+                * This message was all in one fragment, so just show
+                * the fragment header.
+                */
+               show_rpc_fragheader(tvb, tree, rpc_rm);
+       }
+}
+
+static gboolean
+call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo,
+    proto_tree *tree, tvbuff_t *frag_tvb, rec_dissector_t dissector,
+    fragment_data *ipfd_head, guint32 rpc_rm)
+{
+       const char *saved_proto;
+       volatile gboolean rpc_succeeded;
+
+       /*
+        * Catch the ReportedBoundsError exception; if
+        * this particular message happens to get a
+        * ReportedBoundsError exception, that doesn't
+        * mean that we should stop dissecting RPC
+        * messages within this frame or chunk of
+        * reassembled data.
+        *
+        * If it gets a BoundsError, we can stop, as there's
+        * nothing more to see, so we just re-throw it.
+        */
+       saved_proto = pinfo->current_proto;
+       rpc_succeeded = FALSE;
+       TRY {
+               rpc_succeeded = (*dissector)(rec_tvb, pinfo, tree,
+                   frag_tvb, ipfd_head, TRUE, rpc_rm);
+       }
+       CATCH(BoundsError) {
+               RETHROW;
+       }
+       CATCH(ReportedBoundsError) {
+               show_reported_bounds_error(tvb, pinfo, tree);
+               pinfo->current_proto = saved_proto;
+
+               /*
+                * We treat this as a "successful" dissection of
+                * an RPC packet, as "dissect_rpc_message()"
+                * *did* decide it was an RPC packet, throwing
+                * an exception while dissecting it as such.
+                */
+               rpc_succeeded = TRUE;
+       }
+       ENDTRY;
+       return rpc_succeeded;
+}
+
+int
+dissect_rpc_fragment(tvbuff_t *tvb, int offset, packet_info *pinfo,
+    proto_tree *tree, rec_dissector_t dissector, gboolean is_heur,
+    int proto, int ett, gboolean defragment)
+{
+       struct tcpinfo *tcpinfo = pinfo->private_data;
+       guint32 seq = tcpinfo->seq + offset;
+       guint32 rpc_rm;
+       volatile gint32 len;
+       gint32 seglen;
+       gint tvb_len, tvb_reported_len;
+       tvbuff_t *frag_tvb;
+       gboolean rpc_succeeded;
+       gboolean save_fragmented;
+       rpc_fragment_key old_rfk, *rfk, *new_rfk;
+       conversation_t *conversation;
+       fragment_data *ipfd_head;
+       tvbuff_t *rec_tvb;
+
+       /*
+        * Get the record mark.
+        */
+       if (!tvb_bytes_exist(tvb, offset, 4)) {
+               /*
+                * XXX - we should somehow arrange to handle
+                * a record mark split across TCP segments.
+                */
+               return 0;       /* not enough to tell if it's valid */
+       }
+       rpc_rm = tvb_get_ntohl(tvb, offset);
+
+       len = rpc_rm & RPC_RM_FRAGLEN;
+
+       /*
+        * Do TCP desegmentation, if enabled.
+        *
+        * XXX - reject fragments bigger than 2 megabytes.
+        * This is arbitrary, but should at least prevent
+        * some crashes from either packets with really
+        * large RPC-over-TCP fragments or from stuff that's
+        * not really valid for this protocol.
+        */
+       if (len > 2*1024*1024)
+               return 0;       /* pretend it's not valid */
+       if (rpc_desegment) {
+               seglen = tvb_length_remaining(tvb, offset + 4);
+
+               if (len > seglen && pinfo->can_desegment) {
+                       /*
+                        * This frame doesn't have all of the
+                        * data for this message, but we can do
+                        * reassembly on it.
+                        *
+                        * If this is a heuristic dissector, just
+                        * return 0 - we don't want to try to get
+                        * more data, as that's too likely to cause
+                        * us to misidentify this as valid.
+                        *
+                        * If this isn't a heuristic dissector,
+                        * we've already identified this conversation
+                        * as containing data for this protocol, as we
+                        * saw valid data in previous frames.  Try to
+                        * get more data.
+                        */
+                       if (is_heur)
+                               return 0;       /* not valid */
+                       else {
+                               pinfo->desegment_offset = offset;
+                               pinfo->desegment_len = len - seglen;
+                               return -pinfo->desegment_len;
+                       }
+               }
+       }
+       len += 4;       /* include record mark */
+       tvb_len = tvb_length_remaining(tvb, offset);
+       tvb_reported_len = tvb_reported_length_remaining(tvb, offset);
+       if (tvb_len > len)
+               tvb_len = len;
+       if (tvb_reported_len > len)
+               tvb_reported_len = len;
+       frag_tvb = tvb_new_subset(tvb, offset, tvb_len,
+           tvb_reported_len);
+
+       /*
+        * If we're not defragmenting, just hand this to the
+        * disssector.
+        */
+       if (!defragment) {
+               /*
+                * This is the first fragment we've seen, and it's also
+                * the last fragment; that means the record wasn't
+                * fragmented.  Hand the dissector the tvbuff for the
+                * fragment as the tvbuff for the record.
+                */
+               rec_tvb = frag_tvb;
+               ipfd_head = NULL;
+
+               /*
+                * Mark this as fragmented, so if somebody throws an
+                * exception, we don't report it as a malformed frame.
+                */
+               save_fragmented = pinfo->fragmented;
+               pinfo->fragmented = TRUE;
+               rpc_succeeded = call_message_dissector(tvb, rec_tvb, pinfo,
+                   tree, frag_tvb, dissector, ipfd_head, rpc_rm);
+               pinfo->fragmented = save_fragmented;
+               if (!rpc_succeeded)
+                       return 0;       /* not RPC */
+               return len;
+       }
+
+       /*
+        * First, we check to see if this fragment is part of a record
+        * that we're in the process of defragmenting.
+        *
+        * The key is the conversation ID for the conversation to which
+        * the packet belongs and the current sequence number.
+        * We must first find the conversation and, if we don't find
+        * one, create it.  We know this is running over TCP, so the
+        * conversation should not wildcard either address or port.
+        */
+       conversation = find_conversation(&pinfo->src, &pinfo->dst,
+           pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
+       if (conversation == NULL) {
+               /*
+                * It's not part of any conversation - create a new one.
+                */
+               conversation = conversation_new(&pinfo->src, &pinfo->dst,
+                   pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
+       }
+       old_rfk.conv_id = conversation->index;
+       old_rfk.seq = seq;
+       rfk = g_hash_table_lookup(rpc_reassembly_table, &old_rfk);
+
+       if (rfk == NULL) {
+               /*
+                * This fragment was not found in our table, so it doesn't
+                * contain a continuation of a higher-level PDU.
+                * Is it the last fragment?
+                */
+               if (!(rpc_rm & RPC_RM_LASTFRAG)) {
+                       /*
+                        * This isn't the last fragment, so we don't
+                        * have the complete record.
+                        *
+                        * It's the first fragment we've seen, so if
+                        * it's truly the first fragment of the record,
+                        * and it has enough data, the dissector can at
+                        * least check whether it looks like a valid
+                        * message, as it contains the start of the
+                        * message.
+                        *
+                        * The dissector should not dissect anything
+                        * if the "last fragment" flag isn't set in
+                        * the record marker, so it shouldn't throw
+                        * an exception.
+                        */
+                       if (!(*dissector)(frag_tvb, pinfo, tree, frag_tvb,
+                           NULL, TRUE, rpc_rm))
+                               return 0;       /* not valid */
+
+                       /*
+                        * OK, now start defragmentation with that
+                        * fragment.  Add this fragment, and set up
+                        * next packet/sequence number as well.
+                        *
+                        * We must remember this fragment.
+                        */
+
+                       rfk = g_mem_chunk_alloc(rpc_fragment_key_chunk);
+                       rfk->conv_id = conversation->index;
+                       rfk->seq = seq;
+                       rfk->offset = 0;
+                       rfk->start_seq = seq;
+                       g_hash_table_insert(rpc_reassembly_table, rfk, rfk);
+
+                       /*
+                        * Start defragmentation.
+                        */
+                       ipfd_head = fragment_add(tvb, offset + 4, pinfo,
+                           rfk->start_seq, rpc_fragment_table,
+                           rfk->offset, len - 4, TRUE);
+
+                       /*
+                        * Make sure that defragmentation isn't complete;
+                        * it shouldn't be, as this is the first fragment
+                        * we've seen, and the "last fragment" bit wasn't
+                        * set on it.
+                        */
+                       g_assert(ipfd_head == NULL);
+
+                       new_rfk = g_mem_chunk_alloc(rpc_fragment_key_chunk);
+                       new_rfk->conv_id = rfk->conv_id;
+                       new_rfk->seq = seq + len;
+                       new_rfk->offset = rfk->offset + len - 4;
+                       new_rfk->start_seq = rfk->start_seq;
+                       g_hash_table_insert(rpc_reassembly_table, new_rfk,
+                           new_rfk);
+
+                       /*
+                        * This is part of a fragmented record,
+                        * but it's not the first part.
+                        * Show it as a record marker plus data, under
+                        * a top-level tree for this protocol.
+                        */
+                       make_frag_tree(frag_tvb, tree, proto, ett,rpc_rm);
+
+                       /*
+                        * No more processing need be done, as we don't
+                        * have a complete record.
+                        */
+                       return len;
+               }
+
+               /*
+                * This is the first fragment we've seen, and it's also
+                * the last fragment; that means the record wasn't
+                * fragmented.  Hand the dissector the tvbuff for the
+                * fragment as the tvbuff for the record.
+                */
+               rec_tvb = frag_tvb;
+               ipfd_head = NULL;
+       } else {
+               /*
+                * OK, this fragment was found, which means it continues
+                * a record.  This means we must defragment it.
+                * Add it to the defragmentation lists.
+                */
+               ipfd_head = fragment_add(tvb, offset + 4, pinfo,
+                   rfk->start_seq, rpc_fragment_table,
+                   rfk->offset, len - 4, !(rpc_rm & RPC_RM_LASTFRAG));
+
+               if (ipfd_head == NULL) {
+                       /*
+                        * fragment_add() returned NULL, This means that 
+                        * defragmentation is not completed yet.
+                        *
+                        * We must add an entry to the hash table with
+                        * the sequence number following this fragment
+                        * as the starting sequence number, so that when
+                        * we see that fragment we'll find that entry.
+                        *
+                        * XXX - as TCP stream data is not currently
+                        * guaranteed to be provided in order to dissectors,
+                        * RPC fragments aren't guaranteed to be provided
+                        * in order, either.
+                        */
+                       new_rfk = g_mem_chunk_alloc(rpc_fragment_key_chunk);
+                       new_rfk->conv_id = rfk->conv_id;
+                       new_rfk->seq = seq + len;
+                       new_rfk->offset = rfk->offset + len - 4;
+                       new_rfk->start_seq = rfk->start_seq;
+                       g_hash_table_insert(rpc_reassembly_table, new_rfk,
+                           new_rfk);
+
+                       /*
+                        * This is part of a fragmented record,
+                        * but it's not the first part.
+                        * Show it as a record marker plus data, under
+                        * a top-level tree for this protocol,
+                        * but don't hand it to the dissector
+                        */
+                       make_frag_tree(frag_tvb, tree, proto, ett, rpc_rm);
+
+                       /*
+                        * No more processing need be done, as we don't
+                        * have a complete record.
+                        */
+                       return len;
+               }
+
+               /*
+                * It's completely defragmented.
+                *
+                * We only call subdissector for the last fragment.
+                * XXX - this assumes in-order delivery of RPC
+                * fragments, which requires in-order delivery of TCP
+                * segments.
+                */
+               if (!(rpc_rm & RPC_RM_LASTFRAG)) {
+                       /*
+                        * Well, it's defragmented, but this isn't
+                        * the last fragment; this probably means
+                        * this isn't the first pass, so we don't
+                        * need to start defragmentation.
+                        *
+                        * This is part of a fragmented record,
+                        * but it's not the first part.
+                        * Show it as a record marker plus data, under
+                        * a top-level tree for this protocol,
+                        * but don't show it to the dissector.
+                        */
+                       make_frag_tree(frag_tvb, tree, proto, ett, rpc_rm);
+
+                       /*
+                        * No more processing need be done, as we
+                        * only disssect the data with the last
+                        * fragment.
+                        */
+                       return len;
+               }
+
+               /*
+                * OK, this is the last segment.
+                * Create a tvbuff for the defragmented
+                * record.
+                */
+
+               /*
+                * Create a new TVB structure for
+                * defragmented data.
+                */
+               rec_tvb = tvb_new_real_data(ipfd_head->data,
+                   ipfd_head->datalen, ipfd_head->datalen);
+
+               /*
+                * Add this tvb as a child to the original
+                * one.
+                */
+               tvb_set_child_real_data_tvbuff(tvb, rec_tvb);
+
+               /*
+                * Add defragmented data to the data source list.
+                */
+               add_new_data_source(pinfo, rec_tvb, "Defragmented");
+       }
+
+       /*
+        * We have something to hand to the RPC message
+        * dissector.
+        */
+       if (!call_message_dissector(tvb, rec_tvb, pinfo, tree,
+           frag_tvb, dissector, ipfd_head, rpc_rm))
+               return 0;       /* not RPC */
+       return len;
+}
+
+/*
+ * Can return:
+ *
+ *     NEED_MORE_DATA, if we don't have enough data to dissect anything;
+ *
+ *     IS_RPC, if we dissected at least one message in its entirety
+ *     as RPC;
+ *
+ *     IS_NOT_RPC, if we found no RPC message.
+ */
+typedef enum {
+       NEED_MORE_DATA,
+       IS_RPC,
+       IS_NOT_RPC
+} rpc_tcp_return_t;
+
+static rpc_tcp_return_t
+dissect_rpc_tcp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+    gboolean is_heur)
+{
+       int offset = 0;
+       gboolean saw_rpc = FALSE;
+       int len;
+
+       while (tvb_reported_length_remaining(tvb, offset) != 0) {
+               /*
+                * Process this fragment.
+                */
+               len = dissect_rpc_fragment(tvb, offset, pinfo, tree,
+                   dissect_rpc_message, is_heur, proto_rpc, ett_rpc,
+                   rpc_defragment);
+               if (len < 0) {
+                       /*
+                        * We need more data from the TCP stream for
+                        * this fragment.
+                        */
+                       return NEED_MORE_DATA;
+               }
+               if (len == 0) {
+                       /*
+                        * It's not RPC.  Stop processing.
+                        */
+                       break;
+               }
+
+               offset += len;
+               saw_rpc = TRUE;
+       }
+       return saw_rpc ? IS_RPC : IS_NOT_RPC;
+}
+
+static gboolean
+dissect_rpc_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       switch (dissect_rpc_tcp_common(tvb, pinfo, tree, TRUE)) {
+
+       case IS_RPC:
+               return TRUE;
+
+       case IS_NOT_RPC:
+               return FALSE;
+
+       default:
+               /* "Can't happen" */
+               g_assert_not_reached();
+               return FALSE;
+       }
+}
+
+static void
+dissect_rpc_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       if (dissect_rpc_tcp_common(tvb, pinfo, tree, FALSE) == IS_NOT_RPC)
+               dissect_rpc_continuation(tvb, pinfo, tree);
+}
 
 /* Discard any state we've saved. */
 static void
 rpc_init_protocol(void)
 {
-       memset(rpc_call_table, '\0', sizeof rpc_call_table);
-       rpc_call_index = 0;
-       rpc_call_firstfree = 0;
-}
+       if (rpc_calls != NULL) {
+               g_hash_table_destroy(rpc_calls);
+               rpc_calls = NULL;
+       }
+       if (rpc_indir_calls != NULL) {
+               g_hash_table_destroy(rpc_indir_calls);
+               rpc_indir_calls = NULL;
+       }
+       if (rpc_call_info_key_chunk != NULL) {
+               g_mem_chunk_destroy(rpc_call_info_key_chunk);
+               rpc_call_info_key_chunk = NULL;
+       }
+       if (rpc_call_info_value_chunk != NULL) {
+               g_mem_chunk_destroy(rpc_call_info_value_chunk);
+               rpc_call_info_value_chunk = NULL;
+       }
+       if (rpc_fragment_key_chunk != NULL) {
+               g_mem_chunk_destroy(rpc_fragment_key_chunk);
+               rpc_fragment_key_chunk = NULL;
+       }
+       if (rpc_reassembly_table != NULL) {
+               g_hash_table_destroy(rpc_reassembly_table);
+               rpc_reassembly_table = NULL;
+       }
 
+       rpc_calls = g_hash_table_new(rpc_call_hash, rpc_call_equal);
+       rpc_indir_calls = g_hash_table_new(rpc_call_hash, rpc_call_equal);
+       rpc_call_info_key_chunk = g_mem_chunk_new("call_info_key_chunk",
+           sizeof(rpc_call_info_key),
+           200 * sizeof(rpc_call_info_key),
+           G_ALLOC_ONLY);
+       rpc_call_info_value_chunk = g_mem_chunk_new("call_info_value_chunk",
+           sizeof(rpc_call_info_value),
+           200 * sizeof(rpc_call_info_value),
+           G_ALLOC_ONLY);
+       rpc_fragment_key_chunk = g_mem_chunk_new("rpc_fragment_key_chunk",
+           sizeof(rpc_fragment_key),
+           rpc_fragment_init_count*sizeof(rpc_fragment_key),
+           G_ALLOC_ONLY);
+       rpc_reassembly_table = g_hash_table_new(rpc_fragment_hash,
+           rpc_fragment_equal);
+
+       fragment_table_init(&rpc_fragment_table);
+}
 
 /* will be called once from register.c at startup time */
 void
@@ -1528,133 +2828,214 @@ proto_register_rpc(void)
 {
        static hf_register_info hf[] = {
                { &hf_rpc_lastfrag, {
-                       "Last Fragment", "rpc.lastfrag", FT_BOOLEAN, BASE_NONE,
-                       &yesno, 0, "Last Fragment" }},
+                       "Last Fragment", "rpc.lastfrag", FT_BOOLEAN, 32,
+                       &yesno, RPC_RM_LASTFRAG, "Last Fragment", HFILL }},
                { &hf_rpc_fraglen, {
                        "Fragment Length", "rpc.fraglen", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Fragment Length" }},
+                       NULL, RPC_RM_FRAGLEN, "Fragment Length", HFILL }},
                { &hf_rpc_xid, {
                        "XID", "rpc.xid", FT_UINT32, BASE_HEX,
-                       NULL, 0, "XID" }},
+                       NULL, 0, "XID", HFILL }},
                { &hf_rpc_msgtype, {
                        "Message Type", "rpc.msgtyp", FT_UINT32, BASE_DEC,
-                       VALS(rpc_msg_type), 0, "Message Type" }},
+                       VALS(rpc_msg_type), 0, "Message Type", HFILL }},
                { &hf_rpc_state_reply, {
                        "Reply State", "rpc.replystat", FT_UINT32, BASE_DEC,
-                       VALS(rpc_reply_state), 0, "Reply State" }},
+                       VALS(rpc_reply_state), 0, "Reply State", HFILL }},
                { &hf_rpc_state_accept, {
                        "Accept State", "rpc.state_accept", FT_UINT32, BASE_DEC,
-                       VALS(rpc_accept_state), 0, "Accept State" }},
+                       VALS(rpc_accept_state), 0, "Accept State", HFILL }},
                { &hf_rpc_state_reject, {
                        "Reject State", "rpc.state_reject", FT_UINT32, BASE_DEC,
-                       VALS(rpc_reject_state), 0, "Reject State" }},
+                       VALS(rpc_reject_state), 0, "Reject State", HFILL }},
                { &hf_rpc_state_auth, {
                        "Auth State", "rpc.state_auth", FT_UINT32, BASE_DEC,
-                       VALS(rpc_auth_state), 0, "Auth State" }},
+                       VALS(rpc_auth_state), 0, "Auth State", HFILL }},
                { &hf_rpc_version, {
                        "RPC Version", "rpc.version", FT_UINT32, BASE_DEC,
-                       NULL, 0, "RPC Version" }},
+                       NULL, 0, "RPC Version", HFILL }},
                { &hf_rpc_version_min, {
                        "RPC Version (Minimum)", "rpc.version.min", FT_UINT32, 
-                       BASE_DEC, NULL, 0, "Program Version (Minimum)" }},
+                       BASE_DEC, NULL, 0, "Program Version (Minimum)", HFILL }},
                { &hf_rpc_version_max, {
                        "RPC Version (Maximum)", "rpc.version.max", FT_UINT32, 
-                       BASE_DEC, NULL, 0, "RPC Version (Maximum)" }},
+                       BASE_DEC, NULL, 0, "RPC Version (Maximum)", HFILL }},
                { &hf_rpc_program, {
                        "Program", "rpc.program", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Program" }},
+                       NULL, 0, "Program", HFILL }},
                { &hf_rpc_programversion, {
                        "Program Version", "rpc.programversion", FT_UINT32, 
-                       BASE_DEC, NULL, 0, "Program Version" }},
+                       BASE_DEC, NULL, 0, "Program Version", HFILL }},
                { &hf_rpc_programversion_min, {
                        "Program Version (Minimum)", "rpc.programversion.min", FT_UINT32, 
-                       BASE_DEC, NULL, 0, "Program Version (Minimum)" }},
+                       BASE_DEC, NULL, 0, "Program Version (Minimum)", HFILL }},
                { &hf_rpc_programversion_max, {
                        "Program Version (Maximum)", "rpc.programversion.max", FT_UINT32, 
-                       BASE_DEC, NULL, 0, "Program Version (Maximum)" }},
+                       BASE_DEC, NULL, 0, "Program Version (Maximum)", HFILL }},
                { &hf_rpc_procedure, {
                        "Procedure", "rpc.procedure", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Procedure" }},
+                       NULL, 0, "Procedure", HFILL }},
                { &hf_rpc_auth_flavor, {
                        "Flavor", "rpc.auth.flavor", FT_UINT32, BASE_DEC,
-                       VALS(rpc_auth_flavor), 0, "Flavor" }},
+                       VALS(rpc_auth_flavor), 0, "Flavor", HFILL }},
                { &hf_rpc_auth_length, {
                        "Length", "rpc.auth.length", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Length" }},
+                       NULL, 0, "Length", HFILL }},
                { &hf_rpc_auth_stamp, {
                        "Stamp", "rpc.auth.stamp", FT_UINT32, BASE_HEX,
-                       NULL, 0, "Stamp" }},
+                       NULL, 0, "Stamp", HFILL }},
                { &hf_rpc_auth_uid, {
                        "UID", "rpc.auth.uid", FT_UINT32, BASE_DEC,
-                       NULL, 0, "UID" }},
+                       NULL, 0, "UID", HFILL }},
                { &hf_rpc_auth_gid, {
                        "GID", "rpc.auth.gid", FT_UINT32, BASE_DEC,
-                       NULL, 0, "GID" }},
+                       NULL, 0, "GID", HFILL }},
                { &hf_rpc_authgss_v, {
                        "GSS Version", "rpc.authgss.version", FT_UINT32,
-                       BASE_DEC, NULL, 0, "GSS Version" }},
+                       BASE_DEC, NULL, 0, "GSS Version", HFILL }},
                { &hf_rpc_authgss_proc, {
                        "GSS Procedure", "rpc.authgss.procedure", FT_UINT32,
-                       BASE_DEC, VALS(rpc_authgss_proc), 0, "GSS Procedure" }},
+                       BASE_DEC, VALS(rpc_authgss_proc), 0, "GSS Procedure", HFILL }},
                { &hf_rpc_authgss_seq, {
                        "GSS Sequence Number", "rpc.authgss.seqnum", FT_UINT32,
-                       BASE_DEC, NULL, 0, "GSS Sequence Number" }},
+                       BASE_DEC, NULL, 0, "GSS Sequence Number", HFILL }},
                { &hf_rpc_authgss_svc, {
                        "GSS Service", "rpc.authgss.service", FT_UINT32,
-                       BASE_DEC, VALS(rpc_authgss_svc), 0, "GSS Service" }},
+                       BASE_DEC, VALS(rpc_authgss_svc), 0, "GSS Service", HFILL }},
                { &hf_rpc_authgss_ctx, {
                        "GSS Context", "rpc.authgss.context", FT_BYTES,
-                       BASE_HEX, NULL, 0, "GSS Context" }},
+                       BASE_HEX, NULL, 0, "GSS Context", HFILL }},
                { &hf_rpc_authgss_major, {
                        "GSS Major Status", "rpc.authgss.major", FT_UINT32,
-                       BASE_DEC, NULL, 0, "GSS Major Status" }},
+                       BASE_DEC, NULL, 0, "GSS Major Status", HFILL }},
                { &hf_rpc_authgss_minor, {
                        "GSS Minor Status", "rpc.authgss.minor", FT_UINT32,
-                       BASE_DEC, NULL, 0, "GSS Minor Status" }},
+                       BASE_DEC, NULL, 0, "GSS Minor Status", HFILL }},
                { &hf_rpc_authgss_window, {
                        "GSS Sequence Window", "rpc.authgss.window", FT_UINT32,
-                       BASE_DEC, NULL, 0, "GSS Sequence Window" }},
+                       BASE_DEC, NULL, 0, "GSS Sequence Window", HFILL }},
                { &hf_rpc_authgss_token, {
                        "GSS Token", "rpc.authgss.token", FT_BYTES,
-                       BASE_HEX, NULL, 0, "GSS Token" }},
+                       BASE_HEX, NULL, 0, "GSS Token", HFILL }},
                { &hf_rpc_authgss_data_length, {
                        "Length", "rpc.authgss.data.length", FT_UINT32,
-                       BASE_DEC, NULL, 0, "Length" }},
+                       BASE_DEC, NULL, 0, "Length", HFILL }},
                { &hf_rpc_authgss_data, {
                        "GSS Data", "rpc.authgss.data", FT_BYTES,
-                       BASE_HEX, NULL, 0, "GSS Data" }},
+                       BASE_HEX, NULL, 0, "GSS Data", HFILL }},
                { &hf_rpc_authgss_checksum, {
                        "GSS Checksum", "rpc.authgss.checksum", FT_BYTES,
-                       BASE_HEX, NULL, 0, "GSS Checksum" }},
+                       BASE_HEX, NULL, 0, "GSS Checksum", HFILL }},
+               { &hf_rpc_authdes_namekind, {
+                       "Namekind", "rpc.authdes.namekind", FT_UINT32, BASE_DEC,
+                       VALS(rpc_authdes_namekind), 0, "Namekind", HFILL }},
+               { &hf_rpc_authdes_netname, {
+                       "Netname", "rpc.authdes.netname", FT_STRING,
+                       BASE_DEC, NULL, 0, "Netname", HFILL }},
+               { &hf_rpc_authdes_convkey, {
+                       "Conversation Key (encrypted)", "rpc.authdes.convkey", FT_UINT32,
+                       BASE_HEX, NULL, 0, "Conversation Key (encrypted)", HFILL }},
+               { &hf_rpc_authdes_window, {
+                       "Window (encrypted)", "rpc.authdes.window", FT_UINT32,
+                       BASE_HEX, NULL, 0, "Windows (encrypted)", HFILL }},
+               { &hf_rpc_authdes_nickname, {
+                       "Nickname", "rpc.authdes.nickname", FT_UINT32, 
+                       BASE_HEX, NULL, 0, "Nickname", HFILL }},
+               { &hf_rpc_authdes_timestamp, {
+                       "Timestamp (encrypted)", "rpc.authdes.timestamp", FT_UINT32,
+                       BASE_HEX, NULL, 0, "Timestamp (encrypted)", HFILL }},
+               { &hf_rpc_authdes_windowverf, {
+                       "Window verifier (encrypted)", "rpc.authdes.windowverf", FT_UINT32,
+                       BASE_HEX, NULL, 0, "Window verifier (encrypted)", HFILL }},
+               { &hf_rpc_authdes_timeverf, {
+                       "Timestamp verifier (encrypted)", "rpc.authdes.timeverf", FT_UINT32,
+                       BASE_HEX, NULL, 0, "Timestamp verifier (encrypted)", HFILL }},
                { &hf_rpc_auth_machinename, {
                        "Machine Name", "rpc.auth.machinename", FT_STRING, 
-                       BASE_DEC, NULL, 0, "Machine Name" }},
+                       BASE_DEC, NULL, 0, "Machine Name", HFILL }},
                { &hf_rpc_dup, {
                        "Duplicate Transaction", "rpc.dup", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Duplicate Transaction" }},
+                       NULL, 0, "Duplicate Transaction", HFILL }},
                { &hf_rpc_call_dup, {
                        "Duplicate Call", "rpc.call.dup", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Duplicate Call" }},
+                       NULL, 0, "Duplicate Call", HFILL }},
                { &hf_rpc_reply_dup, {
                        "Duplicate Reply", "rpc.reply.dup", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Duplicate Reply" }},
+                       NULL, 0, "Duplicate Reply", HFILL }},
                { &hf_rpc_value_follows, {
                        "Value Follows", "rpc.value_follows", FT_BOOLEAN, BASE_NONE,
-                       &yesno, 0, "Value Follows" }}
+                       &yesno, 0, "Value Follows", HFILL }},
+               { &hf_rpc_array_len, {
+                       "num", "rpc.array.len", FT_UINT32, BASE_DEC,
+                       NULL, 0, "Length of RPC array", HFILL }},
+
+               { &hf_rpc_time, {
+                       "Time from request", "rpc.time", FT_RELATIVE_TIME, BASE_NONE,
+                       NULL, 0, "Time between Request and Reply for ONC-RPC calls", HFILL }},
+
+               { &hf_rpc_fragment_overlap,
+               { "Fragment overlap",   "rpc.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+                       "Fragment overlaps with other fragments", HFILL }},
+
+               { &hf_rpc_fragment_overlap_conflict,
+               { "Conflicting data in fragment overlap",       "rpc.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+                       "Overlapping fragments contained conflicting data", HFILL }},
+
+               { &hf_rpc_fragment_multiple_tails,
+               { "Multiple tail fragments found",      "rpc.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+                       "Several tails were found when defragmenting the packet", HFILL }},
+
+               { &hf_rpc_fragment_too_long_fragment,
+               { "Fragment too long",  "rpc.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+                       "Fragment contained data past end of packet", HFILL }},
+
+               { &hf_rpc_fragment_error,
+               { "Defragmentation error", "rpc.fragment.error", FT_NONE, BASE_NONE, NULL, 0x0,
+                       "Defragmentation error due to illegal fragments", HFILL }},
+
+               { &hf_rpc_fragment,
+               { "RPC Fragment", "rpc.fragment", FT_NONE, BASE_NONE, NULL, 0x0,
+                       "RPC Fragment", HFILL }},
+
+               { &hf_rpc_fragments,
+               { "RPC Fragments", "rpc.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
+                       "RPC Fragments", HFILL }},
        };
        static gint *ett[] = {
                &ett_rpc,
+               &ett_rpc_fragments,
+               &ett_rpc_fragment,
+               &ett_rpc_fraghdr,
                &ett_rpc_string,
                &ett_rpc_cred,
                &ett_rpc_verf,
                &ett_rpc_gids,
+               &ett_rpc_gss_data,
+               &ett_rpc_array,
        };
+       module_t *rpc_module;
 
-       proto_rpc = proto_register_protocol("Remote Procedure Call", "rpc");
+       proto_rpc = proto_register_protocol("Remote Procedure Call",
+           "RPC", "rpc");
        proto_register_field_array(proto_rpc, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
        register_init_routine(&rpc_init_protocol);
 
+       rpc_module = prefs_register_protocol(proto_rpc, NULL);
+       prefs_register_bool_preference(rpc_module, "desegment_rpc_over_tcp",
+               "Desegment all RPC-over-TCP messages",
+               "Whether the RPC dissector should desegment all RPC-over-TCP messages",
+               &rpc_desegment);
+       prefs_register_bool_preference(rpc_module, "defragment_rpc_over_tcp",
+               "Defragment all RPC-over-TCP messages",
+               "Whether the RPC dissector should defragment multi-fragment RPC-over-TCP messages",
+               &rpc_defragment);
+
+       register_dissector("rpc", dissect_rpc, proto_rpc);
+       rpc_handle = find_dissector("rpc");
+       register_dissector("rpc-tcp", dissect_rpc_tcp, proto_rpc);
+       rpc_tcp_handle = find_dissector("rpc-tcp");
+
        /*
         * Init the hash tables.  Dissectors for RPC protocols must
         * have a "handoff registration" routine that registers the
@@ -1670,12 +3051,10 @@ proto_register_rpc(void)
        rpc_procs = g_hash_table_new(rpc_proc_hash, rpc_proc_equal);
 }
 
-
 void
 proto_reg_handoff_rpc(void)
 {
-       old_heur_dissector_add("tcp", dissect_rpc);
-       old_heur_dissector_add("udp", dissect_rpc);
+       heur_dissector_add("tcp", dissect_rpc_tcp_heur, proto_rpc);
+       heur_dissector_add("udp", dissect_rpc_heur, proto_rpc);
+       data_handle = find_dissector("data");
 }
-
-