aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-11-02 10:09:51 +0000
committerGuy Harris <guy@alum.mit.edu>2001-11-02 10:09:51 +0000
commit5511e79593f44ea7fc40cb4b2e830c11cacd7571 (patch)
tree1b55e03b0e64e0881fe25858e58b811f7942dba1 /epan
parentf1b98e60bcd6614ade2fc9d28da7f4b7636e4aed (diff)
Add support for 64-bit signed integers in "int-64bit.[ch]", add an
FT_INT64 type, and make the Diameter dissector use it. Handle the 64-bit integer types in the display filter semantics checks. svn path=/trunk/; revision=4125
Diffstat (limited to 'epan')
-rw-r--r--epan/dfilter/semcheck.c10
-rw-r--r--epan/ftypes/ftype-bytes.c219
-rw-r--r--epan/ftypes/ftypes.h8
-rw-r--r--epan/proto.c41
4 files changed, 267 insertions, 11 deletions
diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c
index d63911f0dc..025d471baa 100644
--- a/epan/dfilter/semcheck.c
+++ b/epan/dfilter/semcheck.c
@@ -1,10 +1,9 @@
/*
- * $Id: semcheck.c,v 1.5 2001/10/29 21:13:12 guy Exp $
+ * $Id: semcheck.c,v 1.6 2001/11/02 10:09:49 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 2001 Gerald Combs
- *
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -53,6 +52,7 @@ compatible_ftypes(ftenum_t a, ftenum_t b)
case FT_IPv4:
case FT_IPv6:
case FT_IPXNET:
+ case FT_INT64:
case FT_UINT64:
return a == b;
@@ -142,6 +142,8 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s)
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
+ case FT_UINT64:
+ case FT_INT64:
return FALSE;
case FT_BOOLEAN:
@@ -227,10 +229,12 @@ is_bytes_type(enum ftenum type)
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
+ case FT_UINT64:
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
+ case FT_INT64:
return FALSE;
case FT_NUM_TYPES:
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c
index 66073e636b..ce43828130 100644
--- a/epan/ftypes/ftype-bytes.c
+++ b/epan/ftypes/ftype-bytes.c
@@ -1,10 +1,9 @@
/*
- * $Id: ftype-bytes.c,v 1.6 2001/10/29 21:13:13 guy Exp $
+ * $Id: ftype-bytes.c,v 1.7 2001/11/02 10:09:51 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 2001 Gerald Combs
- *
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -247,6 +246,20 @@ u64_from_string(fvalue_t *fv, char *s, LogFunc log)
return TRUE;
}
+static gboolean
+i64_from_string(fvalue_t *fv, char *s, LogFunc log)
+{
+ guint8 buffer[8];
+
+ if (atoi64(s, buffer) == NULL) {
+ log("\"%s\" is not a valid integer", s);
+ return FALSE;
+ }
+
+ u64_fvalue_set(fv, buffer, FALSE);
+ return TRUE;
+}
+
static guint
len(fvalue_t *fv)
{
@@ -360,6 +373,178 @@ cmp_le(fvalue_t *fv_a, fvalue_t *fv_b)
return (memcmp(a->data, b->data, a->len) <= 0);
}
+static gboolean
+cmp_gt_i64(fvalue_t *fv_a, fvalue_t *fv_b)
+{
+ GByteArray *a = fv_a->value.bytes;
+ GByteArray *b = fv_b->value.bytes;
+
+ if (a->len > b->len) {
+ return TRUE;
+ }
+
+ if (a->len < b->len) {
+ return FALSE;
+ }
+
+ if ((a->data[0] & 0x80) == 0) {
+ /*
+ * "a" is positive.
+ */
+ if (b->data[0] & 0x80) {
+ /*
+ * "b" is negative, so a > b.
+ */
+ return TRUE;
+ }
+ } else {
+ /*
+ * "a" is negative.
+ */
+ if ((b->data[0] & 0x80) == 0) {
+ /*
+ * "b" is positive, so a < b.
+ */
+ return FALSE;
+ }
+ }
+
+ /*
+ * "a" and "b" have the same sign, so "memcmp()" should
+ * give the right answer.
+ */
+ return (memcmp(a->data, b->data, a->len) > 0);
+}
+
+static gboolean
+cmp_ge_i64(fvalue_t *fv_a, fvalue_t *fv_b)
+{
+ GByteArray *a = fv_a->value.bytes;
+ GByteArray *b = fv_b->value.bytes;
+
+ if (a->len > b->len) {
+ return TRUE;
+ }
+
+ if (a->len < b->len) {
+ return FALSE;
+ }
+
+ if ((a->data[0] & 0x80) == 0) {
+ /*
+ * "a" is positive.
+ */
+ if (b->data[0] & 0x80) {
+ /*
+ * "b" is negative, so a > b.
+ */
+ return TRUE;
+ }
+ } else {
+ /*
+ * "a" is negative.
+ */
+ if ((b->data[0] & 0x80) == 0) {
+ /*
+ * "b" is positive, so a < b.
+ */
+ return FALSE;
+ }
+ }
+
+ /*
+ * "a" and "b" have the same sign, so "memcmp()" should
+ * give the right answer.
+ */
+ return (memcmp(a->data, b->data, a->len) >= 0);
+}
+
+static gboolean
+cmp_lt_i64(fvalue_t *fv_a, fvalue_t *fv_b)
+{
+ GByteArray *a = fv_a->value.bytes;
+ GByteArray *b = fv_b->value.bytes;
+
+ if (a->len < b->len) {
+ return TRUE;
+ }
+
+ if (a->len > b->len) {
+ return FALSE;
+ }
+
+ if (a->data[0] & 0x80) {
+ /*
+ * "a" is negative.
+ */
+ if ((b->data[0] & 0x80) == 0) {
+ /*
+ * "b" is positive, so a < b.
+ */
+ return TRUE;
+ }
+ } else {
+ /*
+ * "a" is positive.
+ */
+ if (b->data[0] & 0x80) {
+ /*
+ * "b" is negative, so a > b.
+ */
+ return FALSE;
+ }
+ }
+
+ /*
+ * "a" and "b" have the same sign, so "memcmp()" should
+ * give the right answer.
+ */
+ return (memcmp(a->data, b->data, a->len) < 0);
+}
+
+static gboolean
+cmp_le_i64(fvalue_t *fv_a, fvalue_t *fv_b)
+{
+ GByteArray *a = fv_a->value.bytes;
+ GByteArray *b = fv_b->value.bytes;
+
+ if (a->len < b->len) {
+ return TRUE;
+ }
+
+ if (a->len > b->len) {
+ return FALSE;
+ }
+
+ if (a->data[0] & 0x80) {
+ /*
+ * "a" is negative.
+ */
+ if ((b->data[0] & 0x80) == 0) {
+ /*
+ * "b" is positive, so a < b.
+ */
+ return TRUE;
+ }
+ } else {
+ /*
+ * "a" is positive.
+ */
+ if (b->data[0] & 0x80) {
+ /*
+ * "b" is negative, so a > b.
+ */
+ return FALSE;
+ }
+ }
+
+ /*
+ * "a" and "b" have the same sign, so "memcmp()" should
+ * give the right answer.
+ */
+ return (memcmp(a->data, b->data, a->len) <= 0);
+}
+
void
ftype_register_bytes(void)
{
@@ -472,8 +657,36 @@ ftype_register_bytes(void)
slice,
};
+ static ftype_t i64_type = {
+ "FT_INT64",
+ "Signed 64-bit integer",
+ U64_LEN,
+ bytes_fvalue_new,
+ bytes_fvalue_free,
+ i64_from_string,
+
+ u64_fvalue_set,
+ NULL,
+ NULL,
+
+ value_get,
+ NULL,
+ NULL,
+
+ cmp_eq,
+ cmp_ne,
+ cmp_gt_i64,
+ cmp_ge_i64,
+ cmp_lt_i64,
+ cmp_le_i64,
+
+ len,
+ slice,
+ };
+
ftype_register(FT_BYTES, &bytes_type);
ftype_register(FT_ETHER, &ether_type);
ftype_register(FT_IPv6, &ipv6_type);
ftype_register(FT_UINT64, &u64_type);
+ ftype_register(FT_INT64, &i64_type);
}
diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h
index 78f30ce7d8..0bf117944a 100644
--- a/epan/ftypes/ftypes.h
+++ b/epan/ftypes/ftypes.h
@@ -1,12 +1,11 @@
/* ftypes.h
* Definitions for field types
*
- * $Id: ftypes.h,v 1.6 2001/10/29 21:13:13 guy Exp $
+ * $Id: ftypes.h,v 1.7 2001/11/02 10:09:51 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 2001 Gerald Combs
- *
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -42,8 +41,9 @@ enum ftenum {
FT_UINT64,
FT_INT8,
FT_INT16,
- FT_INT24,
+ FT_INT24, /* same as for UINT24 */
FT_INT32,
+ FT_INT64,
FT_DOUBLE,
FT_ABSOLUTE_TIME,
FT_RELATIVE_TIME,
diff --git a/epan/proto.c b/epan/proto.c
index 3811826ddb..298848ed45 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.38 2001/10/29 21:13:10 guy Exp $
+ * $Id: proto.c,v 1.39 2001/11/02 10:09:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -54,6 +54,7 @@ proto_tree_free_node(GNode *node, gpointer data);
static void fill_label_boolean(field_info *fi, gchar *label_str);
static void fill_label_uint(field_info *fi, gchar *label_str);
static void fill_label_uint64(field_info *fi, gchar *label_str);
+static void fill_label_int64(field_info *fi, gchar *label_str);
static void fill_label_enumerated_uint(field_info *fi, gchar *label_str);
static void fill_label_enumerated_bitfield(field_info *fi, gchar *label_str);
static void fill_label_numeric_bitfield(field_info *fi, gchar *label_str);
@@ -491,6 +492,7 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
get_uint_value(tvb, start, length, little_endian));
break;
+ case FT_INT64:
case FT_UINT64:
g_assert(length == 8);
proto_tree_set_uint64_tvb(new_fi, tvb, start, little_endian);
@@ -2006,6 +2008,10 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
}
break;
+ case FT_INT64:
+ fill_label_int64(fi, label_str);
+ break;
+
case FT_DOUBLE:
snprintf(label_str, ITEM_LABEL_LENGTH,
"%s: %g", hfinfo->name, fvalue_get_floating(fi->value));
@@ -2096,6 +2102,30 @@ fill_label_uint64(field_info *fi, gchar *label_str)
}
static void
+fill_label_int64(field_info *fi, gchar *label_str)
+{
+ unsigned char *bytes;
+ header_field_info *hfinfo = fi->hfinfo;
+
+ bytes=fvalue_get(fi->value);
+ switch(hfinfo->display){
+ case BASE_DEC:
+ snprintf(label_str, ITEM_LABEL_LENGTH,
+ "%s: %s", hfinfo->name,
+ i64toa(bytes));
+ break;
+ case BASE_HEX:
+ snprintf(label_str, ITEM_LABEL_LENGTH,
+ "%s: %s", hfinfo->name,
+ u64toh(bytes));
+ break;
+ default:
+ g_assert_not_reached();
+ ;
+ }
+}
+
+static void
fill_label_boolean(field_info *fi, gchar *label_str)
{
char *p = label_str;
@@ -2943,6 +2973,7 @@ proto_can_match_selected(field_info *finfo)
case FT_INT16:
case FT_INT24:
case FT_INT32:
+ case FT_INT64:
case FT_IPv4:
case FT_IPXNET:
case FT_IPv6:
@@ -3013,6 +3044,14 @@ proto_alloc_dfilter_string(field_info *finfo, guint8 *pd)
stringified);
break;
+ case FT_INT64:
+ stringified = i64toa(fvalue_get(finfo->value));
+ dfilter_len = abbrev_len + 4 + strlen(stringified) +1;
+ buf = g_malloc0(dfilter_len);
+ snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
+ stringified);
+ break;
+
case FT_IPv4:
dfilter_len = abbrev_len + 4 + 15 + 1;
buf = g_malloc0(dfilter_len);