Include files from the "epan" directory and subdirectories thereof with
[obnox/wireshark/wip.git] / packet-dcerpc-ndr.c
1 /* packet-dcerpc-ndr.c
2  * Routines for DCERPC NDR dissection
3  * Copyright 2001, Todd Sabin <tas@webspan.net>
4  *
5  * $Id: packet-dcerpc-ndr.c,v 1.3 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 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34 #include <string.h>
35 #include <ctype.h>
36
37 #include <glib.h>
38 #include <epan/packet.h>
39 #include "packet-dcerpc.h"
40
41
42 /*
43  * The NDR routines are for use by dcerpc subdissetors.  They're
44  * primarily for making sure things are aligned properly according
45  * to the rules of NDR.
46  */
47
48 int
49 dissect_ndr_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
50                    proto_tree *tree, char *drep, 
51                    int hfindex, guint8 *pdata)
52 {
53     /* no alignment needed */
54     return dissect_dcerpc_uint8 (tvb, offset, pinfo, 
55                                  tree, drep, hfindex, pdata);
56 }
57
58 int
59 dissect_ndr_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
60                     proto_tree *tree, char *drep, 
61                     int hfindex, guint16 *pdata)
62 {
63     if (offset % 2) {
64         offset++;
65     }
66     return dissect_dcerpc_uint16 (tvb, offset, pinfo, 
67                                   tree, drep, hfindex, pdata);
68 }
69
70 int
71 dissect_ndr_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
72                     proto_tree *tree, char *drep, 
73                     int hfindex, guint32 *pdata)
74 {
75     if (offset % 4) {
76         offset += 4 - (offset % 4);
77     }
78     return dissect_dcerpc_uint32 (tvb, offset, pinfo, 
79                                   tree, drep, hfindex, pdata);
80 }
81
82 int
83 dissect_ndr_uuid_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
84                     proto_tree *tree, char *drep, 
85                     int hfindex, e_uuid_t *pdata)
86 {
87     e_uuid_t uuid;
88
89     /* uuid's are aligned to 4 bytes, due to initial uint32 in struct */
90     if (offset % 4) {
91         offset += 4 - (offset % 4);
92     }
93     dcerpc_tvb_get_uuid (tvb, offset, drep, &uuid);
94     if (tree) {
95         proto_tree_add_string_format (tree, hfindex, tvb, offset, 16, "",
96                                       "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
97                                       uuid.Data1, uuid.Data2, uuid.Data3,
98                                       uuid.Data4[0], uuid.Data4[1],
99                                       uuid.Data4[2], uuid.Data4[3],
100                                       uuid.Data4[4], uuid.Data4[5],
101                                       uuid.Data4[6], uuid.Data4[7]);
102     }
103     if (pdata) {
104         *pdata = uuid;
105     }
106     return offset + 16;
107 }
108
109
110 int
111 dissect_ndr_ctx_hnd (tvbuff_t *tvb, gint offset, packet_info *pinfo,
112                      proto_tree *tree, char *drep, 
113                      int hfindex, e_ctx_hnd *pdata)
114 {
115     e_ctx_hnd ctx_hnd;
116
117     if (offset % 4) {
118         offset += 4 - (offset % 4);
119     }
120     ctx_hnd.Data1 = dcerpc_tvb_get_ntohl (tvb, offset, drep);
121     dcerpc_tvb_get_uuid (tvb, offset+4, drep, &ctx_hnd.uuid);
122     if (tree) {
123         proto_tree_add_bytes (tree, hfindex, tvb, offset, 20,
124                               tvb_get_ptr (tvb, offset, 20));
125     }
126     if (pdata) {
127         *pdata = ctx_hnd;
128     }
129     return offset + 20;
130 }
131