*
* Guy Harris <guy@alum.mit.edu>
*
- * $Id: packet-ipp.c,v 1.27 2001/12/10 00:25:29 guy Exp $
+ * $Id: packet-ipp.c,v 1.34 2003/01/28 22:02:26 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h"
#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
#include <string.h>
#include <ctype.h>
#include <glib.h>
-#include "packet.h"
-#include "strutil.h"
+#include <epan/packet.h>
+#include <epan/strutil.h>
#include "packet-http.h"
static int proto_ipp = -1;
static int parse_attributes(tvbuff_t *tvb, int offset, proto_tree *tree);
static proto_tree *add_integer_tree(proto_tree *tree, tvbuff_t *tvb,
- int offset, int name_length, int value_length);
-static void add_integer_value(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length);
+ int offset, int name_length, int value_length, guint8 tag);
+static void add_integer_value(gchar *tag_desc, proto_tree *tree,
+ tvbuff_t *tvb, int offset, int name_length, int value_length, guint8 tag);
static proto_tree *add_octetstring_tree(proto_tree *tree, tvbuff_t *tvb,
int offset, int name_length, int value_length);
-static void add_octetstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
+static void add_octetstring_value(gchar *tag_desc, proto_tree *tree,
tvbuff_t *tvb, int offset, int name_length, int value_length);
static proto_tree *add_charstring_tree(proto_tree *tree, tvbuff_t *tvb,
int offset, int name_length, int value_length);
-static void add_charstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length);
-static int add_value_head(guint tag, gchar *tag_desc, proto_tree *tree,
+static void add_charstring_value(gchar *tag_desc, proto_tree *tree,
tvbuff_t *tvb, int offset, int name_length, int value_length);
+static int add_value_head(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
+ int offset, int name_length, int value_length);
static void
dissect_ipp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
if (tree) {
- ti = proto_tree_add_item(tree, proto_ipp, tvb, offset,
- tvb_length_remaining(tvb, offset), FALSE);
+ ti = proto_tree_add_item(tree, proto_ipp, tvb, offset, -1,
+ FALSE);
ipp_tree = proto_item_add_subtree(ti, ett_ipp);
proto_tree_add_text(ipp_tree, tvb, offset, 2, "Version: %u.%u",
offset = parse_attributes(tvb, offset, ipp_tree);
- if (tvb_offset_exists(tvb, offset))
- call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, ipp_tree);
+ if (tvb_offset_exists(tvb, offset)) {
+ call_dissector(data_handle,
+ tvb_new_subset(tvb, offset, -1, -1), pinfo,
+ ipp_tree);
+ }
}
}
*/
attr_tree = add_integer_tree(as_tree,
tvb, offset, name_length,
- value_length);
+ value_length, tag);
}
- add_integer_value(tag, tag_desc, attr_tree, tvb,
- offset, name_length, value_length);
+ add_integer_value(tag_desc, attr_tree, tvb,
+ offset, name_length, value_length, tag);
break;
case TAG_TYPE_OCTETSTRING:
tvb, offset, name_length,
value_length);
}
- add_octetstring_value(tag, tag_desc,
- attr_tree, tvb, offset, name_length,
- value_length);
+ add_octetstring_value(tag_desc, attr_tree, tvb,
+ offset, name_length, value_length);
break;
case TAG_TYPE_CHARSTRING:
tvb, offset, name_length,
value_length);
}
- add_charstring_value(tag, tag_desc,
- attr_tree, tvb, offset, name_length,
- value_length);
+ add_charstring_value(tag_desc, attr_tree, tvb,
+ offset, name_length, value_length);
break;
}
offset += 1 + 2 + name_length + 2 + value_length;
return offset;
}
+static const value_string bool_vals[] = {
+ { 0x00, "false" },
+ { 0x01, "true" },
+ { 0, NULL }
+};
+
static proto_tree *
add_integer_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
- int name_length, int value_length)
+ int name_length, int value_length, guint8 tag)
{
proto_item *ti;
+ guint8 bool_val;
+
+ switch (tag) {
+
+ case TAG_BOOLEAN:
+ if (value_length != 1) {
+ ti = proto_tree_add_text(tree, tvb, offset,
+ 1 + 2 + name_length + 2 + value_length,
+ "%.*s: Invalid boolean (length is %u, should be 1)",
+ name_length,
+ tvb_get_ptr(tvb, offset + 1 + 2, name_length),
+ value_length);
+ } else {
+ bool_val = tvb_get_guint8(tvb,
+ offset + 1 + 2 + name_length + 2);
+ ti = proto_tree_add_text(tree, tvb, offset,
+ 1 + 2 + name_length + 2 + value_length,
+ "%.*s: %s",
+ name_length,
+ tvb_get_ptr(tvb, offset + 1 + 2, name_length),
+ val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
+ }
+ break;
+
+ case TAG_INTEGER:
+ case TAG_ENUM:
+ if (value_length != 4) {
+ ti = proto_tree_add_text(tree, tvb, offset,
+ 1 + 2 + name_length + 2 + value_length,
+ "%.*s: Invalid integer (length is %u, should be 4)",
+ name_length,
+ tvb_get_ptr(tvb, offset + 1 + 2, name_length),
+ value_length);
+ } else {
+ ti = proto_tree_add_text(tree, tvb, offset,
+ 1 + 2 + name_length + 2 + value_length,
+ "%.*s: %u",
+ name_length,
+ tvb_get_ptr(tvb, offset + 1 + 2, name_length),
+ tvb_get_ntohl(tvb, offset + 1 + 2 + name_length + 2));
+ }
+ break;
- if (value_length != 4) {
+ default:
ti = proto_tree_add_text(tree, tvb, offset,
1 + 2 + name_length + 2 + value_length,
- "%.*s: Invalid integer (length is %u, should be 4)",
+ "%.*s: Unknown integer type 0x%02x",
name_length,
tvb_get_ptr(tvb, offset + 1 + 2, name_length),
- value_length);
- } else {
- ti = proto_tree_add_text(tree, tvb, offset,
- 1 + 2 + name_length + 2 + value_length,
- "%.*s: %u",
- name_length,
- tvb_get_ptr(tvb, offset + 1 + 2, name_length),
- tvb_get_ntohl(tvb, offset + 1 + 2 + name_length + 2));
+ tag);
+ break;
}
return proto_item_add_subtree(ti, ett_ipp_attr);
}
static void
-add_integer_value(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length)
+add_integer_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
+ int offset, int name_length, int value_length, guint8 tag)
{
- offset = add_value_head(tag, tag_desc, tree, tvb, offset,
- name_length, value_length);
- if (value_length == 4) {
- proto_tree_add_text(tree, tvb, offset, value_length,
- "Value: %u", tvb_get_ntohl(tvb, offset));
+ guint8 bool_val;
+
+ offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
+ value_length);
+
+ switch (tag) {
+
+ case TAG_BOOLEAN:
+ if (value_length == 1) {
+ bool_val = tvb_get_guint8(tvb, offset);
+ proto_tree_add_text(tree, tvb, offset, value_length,
+ "Value: %s",
+ val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
+ }
+ break;
+
+ case TAG_INTEGER:
+ case TAG_ENUM:
+ if (value_length == 4) {
+ proto_tree_add_text(tree, tvb, offset, value_length,
+ "Value: %u", tvb_get_ntohl(tvb, offset));
+ }
+ break;
}
}
}
static void
-add_octetstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length)
+add_octetstring_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
+ int offset, int name_length, int value_length)
{
- offset = add_value_head(tag, tag_desc, tree, tvb, offset,
- name_length, value_length);
+ offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
+ value_length);
proto_tree_add_text(tree, tvb, offset, value_length,
"Value: %s", tvb_bytes_to_str(tvb, offset, value_length));
}
}
static void
-add_charstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length)
+add_charstring_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
+ int offset, int name_length, int value_length)
{
- offset = add_value_head(tag, tag_desc, tree, tvb, offset,
- name_length, value_length);
+ offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
+ value_length);
proto_tree_add_text(tree, tvb, offset, value_length,
"Value: %.*s", value_length, tvb_get_ptr(tvb, offset, value_length));
}
static int
-add_value_head(guint tag, gchar *tag_desc, proto_tree *tree,
- tvbuff_t *tvb, int offset, int name_length, int value_length)
+add_value_head(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb, int offset,
+ int name_length, int value_length)
{
proto_tree_add_text(tree, tvb, offset, 1, "Tag: %s", tag_desc);
offset += 1;