aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorTomas Kukosa <tomas.kukosa@siemens.com>2005-07-04 13:04:53 +0000
committerTomas Kukosa <tomas.kukosa@siemens.com>2005-07-04 13:04:53 +0000
commitbab34b522b46bd46d47dc4cb448aed9ce4423d9f (patch)
treeaf5815fc3606f36fa87c2bcaed9c471aef9e5c57 /epan
parent5f2fd433abc60c0e5f97613fbb18a00090dddc26 (diff)
new field type FT_GUID
svn path=/trunk/; revision=14845
Diffstat (limited to 'epan')
-rw-r--r--epan/dfilter/semcheck.c5
-rw-r--r--epan/ftypes/ftype-bytes.c69
-rw-r--r--epan/ftypes/ftypes.h1
-rw-r--r--epan/proto.c89
-rw-r--r--epan/proto.h32
-rw-r--r--epan/to_str.c19
-rw-r--r--epan/to_str.h3
7 files changed, 217 insertions, 1 deletions
diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c
index 8672e07906..8d6e8205b7 100644
--- a/epan/dfilter/semcheck.c
+++ b/epan/dfilter/semcheck.c
@@ -73,7 +73,8 @@ compatible_ftypes(ftenum_t a, ftenum_t b)
case FT_ETHER:
case FT_BYTES:
case FT_UINT_BYTES:
- return (b == FT_ETHER || b == FT_BYTES || b == FT_UINT_BYTES);
+ case FT_GUID:
+ return (b == FT_ETHER || b == FT_BYTES || b == FT_UINT_BYTES || b == FT_GUID);
case FT_BOOLEAN:
case FT_FRAMENUM:
@@ -164,6 +165,7 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s)
case FT_UINT64:
case FT_INT64:
case FT_PCRE:
+ case FT_GUID:
return FALSE;
case FT_BOOLEAN:
@@ -233,6 +235,7 @@ is_bytes_type(enum ftenum type)
case FT_BYTES:
case FT_UINT_BYTES:
case FT_IPv6:
+ case FT_GUID:
return TRUE;
case FT_NONE:
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c
index 0284fa41d7..867c1008b1 100644
--- a/epan/ftypes/ftype-bytes.c
+++ b/epan/ftypes/ftype-bytes.c
@@ -39,6 +39,7 @@
#define ETHER_LEN 6
#define IPv6_LEN 16
+#define GUID_LEN 16
static void
bytes_fvalue_new(fvalue_t *fv)
@@ -121,6 +122,13 @@ ipv6_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
common_fvalue_set(fv, value, IPv6_LEN);
}
+static void
+guid_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
+{
+ g_assert(!already_copied);
+ common_fvalue_set(fv, value, GUID_LEN);
+}
+
static gpointer
value_get(fvalue_t *fv)
{
@@ -218,6 +226,31 @@ ipv6_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogF
return TRUE;
}
+static gboolean
+guid_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value, LogFunc logfunc)
+{
+ /*
+ * Don't log a message if this fails; we'll try looking it
+ * up as an GUID if it does, and if that fails,
+ * we'll log a message.
+ */
+ if (bytes_from_unparsed(fv, s, TRUE, NULL)) {
+ if (fv->value.bytes->len > GUID_LEN) {
+ logfunc("\"%s\" contains too many bytes to be a valid Globally Unique Identifier.",
+ s);
+ return FALSE;
+ }
+ else if (fv->value.bytes->len < GUID_LEN && !allow_partial_value) {
+ logfunc("\"%s\" contains too few bytes to be a valid Globally Unique Identifier.",
+ s);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
static guint
len(fvalue_t *fv)
{
@@ -547,8 +580,44 @@ ftype_register_bytes(void)
slice,
};
+ static ftype_t guid_type = {
+ "GUID", /* name */
+ "Globally Unique Identifier", /* pretty_name */
+ GUID_LEN, /* wire_size */
+ bytes_fvalue_new, /* new_value */
+ bytes_fvalue_free, /* free_value */
+ guid_from_unparsed, /* val_from_unparsed */
+ NULL, /* val_from_string */
+ bytes_to_repr, /* val_to_string_repr */
+ bytes_repr_len, /* len_string_repr */
+
+ guid_fvalue_set, /* set_value */
+ NULL, /* set_value_integer */
+ NULL, /* set_value_integer64 */
+ NULL, /* set_value_floating */
+
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_integer64 */
+ NULL, /* get_value_floating */
+
+ cmp_eq,
+ cmp_ne,
+ cmp_gt,
+ cmp_ge,
+ cmp_lt,
+ cmp_le,
+ cmp_bytes_bitwise_and,
+ cmp_contains,
+ NULL, /* cmp_matches */
+
+ len,
+ slice,
+ };
+
ftype_register(FT_BYTES, &bytes_type);
ftype_register(FT_UINT_BYTES, &uint_bytes_type);
ftype_register(FT_ETHER, &ether_type);
ftype_register(FT_IPv6, &ipv6_type);
+ ftype_register(FT_GUID, &guid_type);
}
diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h
index e328af5aac..ddb7515537 100644
--- a/epan/ftypes/ftypes.h
+++ b/epan/ftypes/ftypes.h
@@ -60,6 +60,7 @@ enum ftenum {
FT_IPXNET,
FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that numbe */
FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */
+ FT_GUID, /* GUID, UUID */
FT_NUM_TYPES /* last item number plus one */
};
diff --git a/epan/proto.c b/epan/proto.c
index 08bc611043..04281e9dff 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -137,6 +137,10 @@ proto_tree_set_ipv6(field_info *fi, const guint8* value_ptr);
static void
proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, gint start);
static void
+proto_tree_set_guid(field_info *fi, const guint8* value_ptr);
+static void
+proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, gint start);
+static void
proto_tree_set_boolean(field_info *fi, guint32 value);
static void
proto_tree_set_float(field_info *fi, float value);
@@ -842,6 +846,11 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
proto_tree_set_ether_tvb(new_fi, tvb, start);
break;
+ case FT_GUID:
+ DISSECTOR_ASSERT(length == 16);
+ proto_tree_set_guid_tvb(new_fi, tvb, start);
+ break;
+
case FT_FLOAT:
DISSECTOR_ASSERT(length == 4);
if (little_endian)
@@ -1390,6 +1399,75 @@ proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, gint start)
proto_tree_set_ipv6(fi, tvb_get_ptr(tvb, start, 16));
}
+/* Add a FT_GUID to a proto_tree */
+proto_item *
+proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
+ const guint8* value_ptr)
+{
+ proto_item *pi;
+ field_info *new_fi;
+ header_field_info *hfinfo;
+
+ if (!tree)
+ return (NULL);
+
+ TRY_TO_FAKE_THIS_ITEM(tree, hfindex);
+
+ PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo);
+ DISSECTOR_ASSERT(hfinfo->type == FT_GUID);
+
+ pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
+ proto_tree_set_guid(new_fi, value_ptr);
+
+ return pi;
+}
+
+proto_item *
+proto_tree_add_guid_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
+ const guint8* value_ptr)
+{
+ proto_item *pi;
+
+ pi = proto_tree_add_guid(tree, hfindex, tvb, start, length, value_ptr);
+ if (pi == NULL)
+ return (NULL);
+
+ PROTO_ITEM_SET_HIDDEN(pi);
+
+ return pi;
+}
+
+proto_item *
+proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
+ const guint8* value_ptr, const char *format, ...)
+{
+ proto_item *pi;
+ va_list ap;
+
+ pi = proto_tree_add_guid(tree, hfindex, tvb, start, length, value_ptr);
+ if (pi == NULL)
+ return (NULL);
+
+ va_start(ap, format);
+ proto_tree_set_representation(pi, format, ap);
+ va_end(ap);
+
+ return pi;
+}
+
+/* Set the FT_GUID value */
+static void
+proto_tree_set_guid(field_info *fi, const guint8* value_ptr)
+{
+ fvalue_set(&fi->value, (gpointer) value_ptr, FALSE);
+}
+
+static void
+proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, gint start)
+{
+ proto_tree_set_guid(fi, tvb_get_ptr(tvb, start, 16));
+}
+
static void
proto_tree_set_uint64(field_info *fi, guint64 value)
{
@@ -3143,6 +3221,15 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
label_str[ITEM_LABEL_LENGTH - 1] = '\0';
break;
+ case FT_GUID:
+ bytes = fvalue_get(&fi->value);
+ ret = snprintf(label_str, ITEM_LABEL_LENGTH,
+ "%s: %s", hfinfo->name,
+ guid_to_str(bytes));
+ if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
+ label_str[ITEM_LABEL_LENGTH - 1] = '\0';
+ break;
+
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
@@ -4231,6 +4318,7 @@ proto_can_match_selected(field_info *finfo, epan_dissect_t *edt)
case FT_BYTES:
case FT_UINT_BYTES:
case FT_PROTOCOL:
+ case FT_GUID:
/*
* These all have values, so we can match.
*/
@@ -4413,6 +4501,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
case FT_ABSOLUTE_TIME:
case FT_RELATIVE_TIME:
case FT_IPv4:
+ case FT_GUID:
/* Figure out the string length needed.
* The ft_repr length.
* 4 bytes for " == ".
diff --git a/epan/proto.h b/epan/proto.h
index 4deaad954c..3d6a14a09e 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -651,6 +651,38 @@ extern proto_item *
proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
gint length, const guint8* value, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
+/** Add a FT_GUID to a proto_tree.
+ @param tree the tree to append this item to
+ @param hfindex field index
+ @param tvb the tv buffer of the current data
+ @param start start of data in tvb
+ @param length length of data in tvb
+ @param value_ptr data to display
+ @return the newly created item */
+extern proto_item *
+proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
+ gint length, const guint8* value_ptr);
+
+/** Add a hidden FT_GUID to a proto_tree.
+ @deprecated use proto_tree_add_guid() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
+extern proto_item *
+proto_tree_add_guid_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
+ gint length, const guint8* value_ptr);
+
+/** Add a formatted FT_GUID to a proto_tree.
+ @param tree the tree to append this item to
+ @param hfindex field index
+ @param tvb the tv buffer of the current data
+ @param start start of data in tvb
+ @param length length of data in tvb
+ @param value_ptr data to display
+ @param format printf like format string
+ @param ... printf like parameters
+ @return the newly created item */
+extern proto_item *
+proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
+ gint length, const guint8* value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
+
/** Add a FT_STRING to a proto_tree.
@param tree the tree to append this item to
@param hfindex field index
diff --git a/epan/to_str.c b/epan/to_str.c
index b820ab2e74..55832da4db 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -934,3 +934,22 @@ gchar* oid_to_str_buf(const guint8 *oid, gint oid_len, gchar *buf) {
return buf;
}
+
+gchar* guid_to_str(const guint8 *guid) {
+ /* static buffer */
+ static int cnt = 0;
+ static gchar strbuf[8][GUID_STR_LEN];
+
+ cnt = (cnt + 1) % 8;
+ return guid_to_str_buf(guid, strbuf[cnt]);
+}
+
+gchar* guid_to_str_buf(const guint8 *guid, gchar *buf) {
+ sprintf(buf, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
+ guid[0], guid[1], guid[2], guid[3],
+ guid[4], guid[5],
+ guid[6], guid[7],
+ guid[8], guid[9],
+ guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
+ return buf;
+}
diff --git a/epan/to_str.h b/epan/to_str.h
index 15c9aae813..0035ac1b71 100644
--- a/epan/to_str.h
+++ b/epan/to_str.h
@@ -31,6 +31,7 @@
#include "epan/packet_info.h"
#define MAX_OID_STR_LEN 256
+#define GUID_STR_LEN 37
/*
* Resolution of a time stamp.
@@ -71,6 +72,8 @@ extern gchar* rel_time_to_str(nstime_t*);
extern gchar* rel_time_to_secs_str(nstime_t*);
extern gchar* oid_to_str(const guint8*, gint);
extern gchar* oid_to_str_buf(const guint8*, gint, gchar*);
+extern gchar* guid_to_str(const guint8*);
+extern gchar* guid_to_str_buf(const guint8*, gchar*);
extern char *other_decode_bitfield_value(char *buf, guint32 val, guint32 mask,