aboutsummaryrefslogtreecommitdiffstats
path: root/proto.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-01-22 04:59:55 +0000
committerGuy Harris <guy@alum.mit.edu>2000-01-22 04:59:55 +0000
commit0b41709f86e069cb8b94a9fadec050eb6a0514dd (patch)
tree502a5ad1571c24b090b3258cdac69594997058f2 /proto.c
parent5b5f2271cd73724314f49be784c4b56672722b43 (diff)
Add "proto_item_set_text()", which sets the "representation" field of an
existing protocol tree item. Add "proto_tree_add_notext()"; it's just like "proto_tree_add_text()", but without the text, and it sets the "representation" field to NULL; that field would be set later with "proto_item_set_text()". Those routines let you construct, for example, an interior node of the protocol tree whose text can't be determined until all the nodes under it have been dissected - it's similar to "proto_item_set_len()" in that fashion. Use that when dissecting address TLVs in the CDP dissector - create the item for an address in an "Addresses" TLV with no text, and then fill in the items under it one at a time; if we get cut off before we get to the actual address, set the text to "Truncated address", otherwise set it to a description of the address. Also, set the length of the item for the entire address TLV correctly. svn path=/trunk/; revision=1520
Diffstat (limited to 'proto.c')
-rw-r--r--proto.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/proto.c b/proto.c
index cf152f7bd9..50d2b99a83 100644
--- a/proto.c
+++ b/proto.c
@@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.51 1999/12/05 02:33:52 guy Exp $
+ * $Id: proto.c,v 1.52 2000/01/22 04:59:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -268,6 +268,19 @@ proto_tree_add_item_format(proto_tree *tree, int hfindex, gint start, gint lengt
}
proto_item *
+proto_tree_add_notext(proto_tree *tree, gint start, gint length, ...)
+{
+ proto_item *pi;
+ va_list ap;
+
+ va_start(ap, length);
+ pi = proto_tree_add_item_value(tree, hf_text_only, start, length, 0, 1, ap);
+ va_end(ap);
+
+ return pi;
+}
+
+proto_item *
proto_tree_add_text(proto_tree *tree, gint start, gint length, ...)
{
proto_item *pi;
@@ -400,8 +413,8 @@ NOTES
/* are there any formatting arguments? */
if (visible && include_format) {
- fi->representation = g_mem_chunk_alloc(gmc_item_labels);
format = va_arg(ap, char*);
+ fi->representation = g_mem_chunk_alloc(gmc_item_labels);
vsnprintf(fi->representation, ITEM_LABEL_LENGTH,
format, ap);
}
@@ -413,6 +426,24 @@ NOTES
}
void
+proto_item_set_text(proto_item *pi, ...)
+{
+ field_info *fi = (field_info*) (((GNode*)pi)->data);
+ va_list ap;
+ char *format;
+
+ if (fi->representation)
+ g_mem_chunk_free(gmc_item_labels, fi->representation);
+
+ fi->representation = g_mem_chunk_alloc(gmc_item_labels);
+ va_start(ap, pi);
+ format = va_arg(ap, char*);
+ vsnprintf(fi->representation, ITEM_LABEL_LENGTH,
+ format, ap);
+ va_end(ap);
+}
+
+void
proto_item_set_len(proto_item *pi, gint length)
{
field_info *fi = (field_info*) (((GNode*)pi)->data);