proto_registrar_get_nth(hfinfo->id) == hfinfo, so use the latter rather
[obnox/wireshark/wip.git] / packet-dcerpc-epm.c
1 /* packet-dcerpc-epm.c
2  * Routines for dcerpc endpoint mapper dissection
3  * Copyright 2001, Todd Sabin <tas@webspan.net>
4  *
5  * $Id: packet-dcerpc-epm.c,v 1.4 2002/01/21 07:36:33 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #include <string.h>
36
37 #include <glib.h>
38 #include <epan/packet.h>
39 #include "packet-dcerpc.h"
40
41
42 static int proto_epm = -1;
43
44 static int hf_epm_inquiry_type = -1;
45 static int hf_epm_object_p = -1;
46 static int hf_epm_object = -1;
47 static int hf_epm_if_id_p = -1;
48 static int hf_epm_if_id = -1;
49 static int hf_epm_ver_maj = -1;
50 static int hf_epm_ver_min = -1;
51 static int hf_epm_ver_opt = -1;
52 static int hf_epm_lookup_hnd = -1;
53 static int hf_epm_max_ents = -1;
54 static int hf_epm_num_ents = -1;
55
56 static gint ett_epm = -1;
57
58
59 static e_uuid_t uuid_epm = { 0xe1af8308, 0x5d1f, 0x11c9, { 0x91, 0xa4, 0x08, 0x00, 0x2b, 0x14, 0xa0, 0xfa } };
60 static guint16  ver_epm = 3;
61
62
63 static int
64 epm_dissect_ept_lookup_rqst (tvbuff_t *tvb, int offset, 
65                              packet_info *pinfo, proto_tree *tree, 
66                              char *drep)
67 {
68     guint32 dummy;
69     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
70                                  hf_epm_inquiry_type, NULL);
71     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
72                                  hf_epm_object_p, &dummy);
73     if (dummy) {
74         offset = dissect_ndr_uuid_t (tvb, offset, pinfo, tree, drep,
75                                      hf_epm_object, NULL);
76     }
77     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
78                                  hf_epm_if_id_p, &dummy);
79     if (dummy) {
80         offset = dissect_ndr_uuid_t (tvb, offset, pinfo, tree, drep,
81                                      hf_epm_if_id, NULL);
82         offset = dissect_ndr_uint16 (tvb, offset, pinfo, tree, drep,
83                                      hf_epm_ver_maj, NULL);
84         offset = dissect_ndr_uint16 (tvb, offset, pinfo, tree, drep,
85                                      hf_epm_ver_min, NULL);
86     }
87     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
88                                  hf_epm_ver_opt, NULL);
89     if (tree) {
90         proto_tree_add_bytes (tree, hf_epm_lookup_hnd, tvb, offset, 20,
91                               tvb_get_ptr (tvb, offset, 20));
92     }
93     offset += 20;
94
95     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
96                                  hf_epm_max_ents, NULL);
97     return offset;
98 }
99
100
101 static int
102 epm_dissect_ept_lookup_resp (tvbuff_t *tvb, int offset, 
103                              packet_info *pinfo, proto_tree *tree, 
104                              char *drep)
105 {
106     guint32 dummy;
107
108
109     offset = dissect_ndr_ctx_hnd (tvb, offset, pinfo, tree, drep,
110                                   hf_epm_lookup_hnd, NULL);
111
112     offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
113                                  hf_epm_num_ents, NULL);
114     /* FIXME: more to do here */
115     return offset;
116 }
117
118
119 static dcerpc_sub_dissector epm_dissectors[] = {
120     { 0, "ept_insert", NULL, NULL },
121     { 1, "ept_delete", NULL, NULL },
122     { 2, "ept_lookup", epm_dissect_ept_lookup_rqst, epm_dissect_ept_lookup_resp },
123     { 3, "ept_map", NULL, NULL },
124     { 4, "ept_lookup_handle_free", NULL, NULL },
125     { 5, "ept_inq_object", NULL, NULL },
126     { 6, "ept_mgmt_delete", NULL, NULL },
127     { 0, NULL, NULL, NULL },
128 };
129
130
131 void
132 proto_register_epm (void)
133 {
134         static hf_register_info hf[] = {
135         { &hf_epm_inquiry_type,
136           { "Inquiry type", "epm.inq_type", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
137         { &hf_epm_object_p,
138           { "Object pointer", "epm.object_p", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
139         { &hf_epm_object,
140           { "Object", "epm.object", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
141         { &hf_epm_if_id_p,
142           { "Interface pointer", "epm.if_id_p", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
143         { &hf_epm_if_id,
144           { "Interface", "epm.if_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
145         { &hf_epm_ver_maj,
146           { "Version Major", "epm.ver_maj", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
147         { &hf_epm_ver_min,
148           { "Version Minor", "epm.ver_min", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
149         { &hf_epm_ver_opt,
150           { "Version Option", "epm.ver_opt", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},      
151         { &hf_epm_lookup_hnd,
152           { "Lookup Handle", "epm.lookup_hnd", FT_BYTES, BASE_NONE, NULL, 0x0, "", HFILL }},    
153         { &hf_epm_max_ents,
154           { "Max entries", "epm.max_ents", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
155         { &hf_epm_num_ents,
156           { "Num entries", "epm.num_ents", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
157     };
158
159         static gint *ett[] = {
160                 &ett_epm,
161         };
162         proto_epm = proto_register_protocol ("DCE/RPC Endpoint Mapper", "EPM", "epm");
163         proto_register_field_array (proto_epm, hf, array_length (hf));
164         proto_register_subtree_array (ett, array_length (ett));
165 }
166
167 void
168 proto_reg_handoff_epm (void)
169 {
170         /* Register the protocol as dcerpc */
171         dcerpc_init_uuid (proto_epm, ett_epm, &uuid_epm, ver_epm, epm_dissectors);
172 }