Call subdissectors even if we're not building a protocol tree.
[obnox/wireshark/wip.git] / packet-bootparams.c
index 2d90e99f053bb6e3a4f56f37bb0b3df2eefda2a3..22f63a650e52e936fda2e7ced454a336c5b43763 100644 (file)
@@ -1,10 +1,10 @@
 /* packet-bootparams.c
  * Routines for bootparams dissection
  *
- * $Id: packet-bootparams.c,v 1.3 1999/11/11 16:20:24 nneul Exp $
+ * $Id: packet-bootparams.c,v 1.24 2002/11/01 00:48:38 sahlberg Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@unicom.net>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-smb.c
 #include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
 
 #include "packet-bootparams.h"
 
 static int proto_bootparams = -1;
+static int hf_bootparams_procedure_v1 = -1;
 static int hf_bootparams_host = -1;
+static int hf_bootparams_domain = -1;
 static int hf_bootparams_fileid = -1;
 static int hf_bootparams_filepath = -1;
+static int hf_bootparams_hostaddr = -1;
+static int hf_bootparams_routeraddr = -1;
 static int hf_bootparams_addresstype = -1;
-static int hf_bootparams_address = -1;
 
-/* Dissect a getfile call */
-int dissect_getfile_call(const u_char *pd, int offset, frame_data *fd,
-       proto_tree *tree)
+static gint ett_bootparams = -1;
+
+
+static const value_string addr_type[] =
+{
+       {       1,      "IPv4-ADDR"     },
+       {       0,      NULL            }
+};
+
+static int
+dissect_bp_address(tvbuff_t *tvb, int offset, proto_tree *tree, int hfindex)
+{
+       guint32 type;
+       guint32 ipaddr;
+
+
+       type = tvb_get_ntohl(tvb, offset);
+
+       offset = dissect_rpc_uint32(tvb, tree, hf_bootparams_addresstype, offset);
+
+       switch(type){
+       case 1:
+               ipaddr = ((tvb_get_guint8(tvb, offset+3 )&0xff)<<24)
+                       |((tvb_get_guint8(tvb, offset+7 )&0xff)<<16)
+                       |((tvb_get_guint8(tvb, offset+11)&0xff)<<8 )
+                       |((tvb_get_guint8(tvb, offset+15)&0xff) );
+               proto_tree_add_ipv4(tree, hfindex, tvb,
+                       offset, 16, g_ntohl(ipaddr));
+               offset += 16;
+               break;
+
+       default:
+               break;
+       }
+
+       return offset;
+}
+
+
+static int
+dissect_getfile_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
        if ( tree )
        {
-               offset = dissect_rpc_string_item(pd,offset,fd,tree,hf_bootparams_host);
-               offset = dissect_rpc_string_item(pd,offset,fd,tree,hf_bootparams_fileid);
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_fileid, offset, NULL);
        }
-       
+
        return offset;
 }
 
-/* Dissect a getfile reply */
-int dissect_getfile_reply(const u_char *pd, int offset, frame_data *fd,
-       proto_tree *tree)
+static int
+dissect_getfile_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-       guint32 type;
-       guint32 ipaddr;
+       if ( tree )
+       {
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
+               offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_hostaddr);
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_filepath, offset, NULL);
+       }
 
+       return offset;
+}
+
+static int
+dissect_whoami_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
+{
        if ( tree )
        {
-               offset = dissect_rpc_string_item(pd,offset,fd,tree,hf_bootparams_host);
-
-               /* get the address type */
-               if ( !BYTES_ARE_IN_FRAME(offset, 1)) return offset;
-               type = pntohl(&pd[offset]); /* type of address */
-               proto_tree_add_item(tree, hf_bootparams_addresstype,
-                       offset, 4, type);
-               offset += 4;
-
-               if ( type != 1 ) /* only know how to handle this type of address */
-               {
-                       return offset;
-               }
-
-               /* get the address itself - weird ass format */
-               if ( ! BYTES_ARE_IN_FRAME(offset, 16)) return offset;
-               ipaddr = (pd[offset+3]<<24) + (pd[offset+7]<<16) +
-                       (pd[offset+11]<<8) + (pd[offset+15]);
-               proto_tree_add_item(tree, hf_bootparams_address, 
-                       offset, 16, ntohl(ipaddr));
-               offset += 16;
+               offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_hostaddr);
+       }
 
-               offset = dissect_rpc_string_item(pd,offset,fd,tree,hf_bootparams_filepath);
+       return offset;
+}
+
+static int
+dissect_whoami_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
+{
+       if ( tree )
+       {
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
+               offset = dissect_rpc_string(tvb, tree, hf_bootparams_domain, offset, NULL);
+               offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_routeraddr);
        }
-       
+
        return offset;
 }
 
 /* proc number, "proc name", dissect_request, dissect_reply */
-/* NULL as function pointer means: take the generic one. */
-const vsff bootparams1_proc[] = {
+/* NULL as function pointer means: type of arguments is "void". */
+static const vsff bootparams1_proc[] = {
        { BOOTPARAMSPROC_NULL, "NULL",
                NULL, NULL },
-       { BOOTPARAMSPROC_WHOAMI, "WHOAMI", 
-               NULL, NULL },
-       { BOOTPARAMSPROC_GETFILE, "GETFILE", 
+       { BOOTPARAMSPROC_WHOAMI, "WHOAMI",
+               dissect_whoami_call, dissect_whoami_reply },
+       { BOOTPARAMSPROC_GETFILE, "GETFILE",
                dissect_getfile_call, dissect_getfile_reply },
        { 0, NULL, NULL, NULL }
 };
 /* end of Bootparams version 1 */
 
+static const value_string bootparams1_proc_vals[] = {
+       { BOOTPARAMSPROC_NULL, "NULL" },
+       { BOOTPARAMSPROC_WHOAMI, "WHOAMI" },
+       { BOOTPARAMSPROC_GETFILE, "GETFILE" },
+       { 0, NULL }
+};
 
 void
 proto_register_bootparams(void)
 {
        static hf_register_info hf[] = {
+               { &hf_bootparams_procedure_v1, {
+                       "V1 Procedure", "bootparams.procedure_v1", FT_UINT32, BASE_DEC,
+                       VALS(bootparams1_proc_vals), 0, "V1 Procedure", HFILL }},
                { &hf_bootparams_host, {
-                       "Host", "bootparams.host", FT_STRING, BASE_DEC,
-                       NULL, 0, "Host" }},
+                       "Client Host", "bootparams.host", FT_STRING, BASE_DEC,
+                       NULL, 0, "Client Host", HFILL }},
+               { &hf_bootparams_domain, {
+                       "Client Domain", "bootparams.domain", FT_STRING, BASE_DEC,
+                       NULL, 0, "Client Domain", HFILL }},
                { &hf_bootparams_fileid, {
                        "File ID", "bootparams.fileid", FT_STRING, BASE_DEC,
-                       NULL, 0, "File ID" }},
+                       NULL, 0, "File ID", HFILL }},
                { &hf_bootparams_filepath, {
                        "File Path", "bootparams.filepath", FT_STRING, BASE_DEC,
-                       NULL, 0, "File Path" }},
+                       NULL, 0, "File Path", HFILL }},
+               { &hf_bootparams_hostaddr, {
+                       "Client Address", "bootparams.hostaddr", FT_IPv4, BASE_DEC,
+                       NULL, 0, "Address", HFILL }},
+               { &hf_bootparams_routeraddr, {
+                       "Router Address", "bootparams.routeraddr", FT_IPv4, BASE_DEC,
+                       NULL, 0, "Router Address", HFILL }},
                { &hf_bootparams_addresstype, {
-                       "Address Type", "bootparams.addresstype", FT_UINT32, BASE_DEC,
-                       NULL, 0, "Address Type" }},
-               { &hf_bootparams_address, {
-                       "Address", "bootparams.address", FT_IPv4, BASE_DEC,
-                       NULL, 0, "Address" }},
+                       "Address Type", "bootparams.type", FT_UINT32, BASE_DEC,
+                       VALS(addr_type), 0, "Address Type", HFILL }},
+       };
+       static gint *ett[] = {
+               &ett_bootparams,
        };
 
-       proto_bootparams = proto_register_protocol("Boot Parameters", "bootparams");
+       proto_bootparams = proto_register_protocol("Boot Parameters",
+           "BOOTPARAMS", "bootparams");
        proto_register_field_array(proto_bootparams, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
+}
 
+void
+proto_reg_handoff_bootparams(void)
+{
        /* Register the protocol as RPC */
-       rpc_init_prog(proto_bootparams, BOOTPARAMS_PROGRAM, ETT_BOOTPARAMS);
+       rpc_init_prog(proto_bootparams, BOOTPARAMS_PROGRAM, ett_bootparams);
        /* Register the procedure tables */
-       rpc_init_proc_table(BOOTPARAMS_PROGRAM, 1, bootparams1_proc);
+       rpc_init_proc_table(BOOTPARAMS_PROGRAM, 1, bootparams1_proc, hf_bootparams_procedure_v1);
 }
-