2 * Common routines for smb packet dissection
3 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
5 * $Id: packet-smb-common.c,v 1.8 2002/01/24 09:20:51 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-pop.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "packet-smb-common.h"
30 int display_ms_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int hf_index)
35 /* display a string from the tree and return the new offset */
37 len = tvb_strnlen(tvb, offset, -1);
40 * XXX - throw an exception?
42 len = tvb_length_remaining(tvb, offset);
44 str = g_malloc(len+1);
45 tvb_memcpy(tvb, (guint8 *)str, offset, len);
48 proto_tree_add_string(tree, hf_index, tvb, offset, len+1, str);
51 * XXX - "proto_tree_add_string()" mallocates a copy; it'd
52 * be nice not to have it copy the string, but just to
53 * make it the value, avoiding both the copy and the free
62 int display_unicode_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int hf_index)
64 /* display a unicode string from the tree and return new offset */
66 char Temp[100], *OutPtr;
69 /* this will crash if composite tvbuffs are used */
70 /* XXX - need tvbuff routine to extract DBCS string lengths */
71 InPtr = tvb_get_ptr(tvb, offset, 1);
72 OutPtr = Temp; /* point to temp space */
74 while ( *InPtr){ /* copy every other byte */
78 *OutPtr = 0; /* terminate out string */
80 proto_tree_add_string(tree, hf_index, tvb,
81 offset, strlen(Temp)*2+2, Temp);
83 return offset+strlen(Temp)*2+2;
87 dissect_smb_unknown(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
89 /* display data as unknown */
91 proto_tree_add_text(tree, tvb, offset, -1, "Data (%u bytes)",
92 tvb_reported_length_remaining(tvb, offset));
94 return offset+tvb_length_remaining(tvb, offset);