diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-11-02 10:09:51 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-11-02 10:09:51 +0000 |
commit | 5511e79593f44ea7fc40cb4b2e830c11cacd7571 (patch) | |
tree | 1b55e03b0e64e0881fe25858e58b811f7942dba1 /epan/ftypes/ftype-bytes.c | |
parent | f1b98e60bcd6614ade2fc9d28da7f4b7636e4aed (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/ftypes/ftype-bytes.c')
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 219 |
1 files changed, 216 insertions, 3 deletions
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, ðer_type); ftype_register(FT_IPv6, &ipv6_type); ftype_register(FT_UINT64, &u64_type); + ftype_register(FT_INT64, &i64_type); } |