* $Id$
*
* 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
* as published by the Free Software Foundation; either version 2
dfvm_value_t *arg2;
dfvm_value_t *arg3;
dfvm_value_t *arg4;
+ char *value_str;
length = insns->len;
break;
case READ_TREE:
- fprintf(f, "%05d READ_TREE\t\t%s -> reg#%d\n",
+ fprintf(f, "%05d READ_TREE\t\t%s -> reg#%u\n",
id, arg1->value.hfinfo->abbrev,
arg2->value.numeric);
break;
case PUT_FVALUE:
- fprintf(f, "%05d PUT_FVALUE\t<%s> -> reg#%d\n",
- id, fvalue_type_name(arg1->value.fvalue),
+ value_str = fvalue_to_string_repr(arg1->value.fvalue,
+ FTREPR_DFILTER, NULL);
+ fprintf(f, "%05d PUT_FVALUE\t%s <%s> -> reg#%u\n",
+ id, value_str,
+ fvalue_type_name(arg1->value.fvalue),
arg2->value.numeric);
+ g_free(value_str);
break;
case MK_RANGE:
- fprintf(f, "%05d MK_RANGE\t\treg#%d[?] -> reg#%d\n",
+ fprintf(f, "%05d MK_RANGE\t\treg#%u[?] -> reg#%u\n",
id,
arg1->value.numeric,
arg2->value.numeric);
break;
case ANY_EQ:
- fprintf(f, "%05d ANY_EQ\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_EQ\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_NE:
- fprintf(f, "%05d ANY_NE\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_NE\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_GT:
- fprintf(f, "%05d ANY_GT\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_GT\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_GE:
- fprintf(f, "%05d ANY_GE\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_GE\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_LT:
- fprintf(f, "%05d ANY_LT\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_LT\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_LE:
- fprintf(f, "%05d ANY_LE\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_LE\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_BITWISE_AND:
- fprintf(f, "%05d ANY_BITWISE_AND\t\treg#%d == reg#%d\n",
+ fprintf(f, "%05d ANY_BITWISE_AND\t\treg#%u == reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_CONTAINS:
- fprintf(f, "%05d ANY_CONTAINS\treg#%d contains reg#%d\n",
+ fprintf(f, "%05d ANY_CONTAINS\treg#%u contains reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
case ANY_MATCHES:
- fprintf(f, "%05d ANY_MATCHES\treg#%d matches reg#%d\n",
+ fprintf(f, "%05d ANY_MATCHES\treg#%u matches reg#%u\n",
id, arg1->value.numeric, arg2->value.numeric);
break;
return TRUE;
}
+static int
+ipv6_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ /*
+ * 39 characters for "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX".
+ */
+ return 39;
+}
+
+static void
+ipv6_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ ip6_to_str_buf((struct e_in6_addr *)fv->value.bytes->data, buf);
+}
+
static gboolean
get_guid(char *s, guint8 *buf)
{
bytes_fvalue_free, /* free_value */
ipv6_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ ipv6_to_repr, /* val_to_string_repr */
+ ipv6_repr_len, /* len_string_repr */
ipv6_fvalue_set, /* set_value */
NULL, /* set_value_integer */
bytes_fvalue_free, /* free_value */
guid_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- guid_to_repr, /* val_to_string_repr */
- guid_repr_len, /* len_string_repr */
+ guid_to_repr, /* val_to_string_repr */
+ guid_repr_len, /* len_string_repr */
guid_fvalue_set, /* set_value */
NULL, /* set_value_integer */
return TRUE;
}
+static int
+integer_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ return 11; /* enough for 12^31-1, in decimal */
+}
+
+static void
+integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ sprintf(buf, "%d", fv->value.integer);
+}
+
+static int
+uinteger_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ return 10; /* enough for 2^32-1, in decimal */
+}
+
+static void
+uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ sprintf(buf, "%u", fv->value.integer);
+}
+
static gboolean
ipxnet_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFunc logfunc)
{
return FALSE;
}
+static int
+ipxnet_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ return 2+8; /* 0xXXXXXXXX */
+}
+
+static void
+ipxnet_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ sprintf(buf, "0x%08x", fv->value.integer);
+}
+
static gboolean
cmp_eq(fvalue_t *a, fvalue_t *b)
{
return TRUE;
}
+static int
+integer64_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ return 20; /* enough for -2^63-1, in decimal */
+}
+
+static void
+integer64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ sprintf(buf, PRId64, fv->value.integer64);
+}
+
+static int
+uinteger64_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
+{
+ return 20; /* enough for 2^64-1, in decimal */
+}
+
+static void
+uinteger64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
+{
+ sprintf(buf, PRIu64, fv->value.integer64);
+}
+
static gboolean
cmp_eq64(fvalue_t *a, fvalue_t *b)
{
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger_to_repr, /* val_to_string_repr */
+ uinteger_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger_to_repr, /* val_to_string_repr */
+ uinteger_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger_to_repr, /* val_to_string_repr */
+ uinteger_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger_to_repr, /* val_to_string_repr */
+ uinteger_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val64_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger64_to_repr, /* val_to_string_repr */
+ uinteger64_repr_len, /* len_string_repr */
NULL, /* set_value */
NULL, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ integer_to_repr, /* val_to_string_repr */
+ integer_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ integer_to_repr, /* val_to_string_repr */
+ integer_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ integer_to_repr, /* val_to_string_repr */
+ integer_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ integer_to_repr, /* val_to_string_repr */
+ integer_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val64_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ integer64_to_repr, /* val_to_string_repr */
+ integer64_repr_len, /* len_string_repr */
NULL, /* set_value */
NULL, /* set_value_integer */
NULL, /* free_value */
ipxnet_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ ipxnet_to_repr, /* val_to_string_repr */
+ ipxnet_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
NULL, /* free_value */
val_from_unparsed, /* val_from_unparsed */
NULL, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ uinteger_to_repr, /* val_to_string_repr */
+ uinteger_repr_len, /* len_string_repr */
NULL, /* set_value */
set_integer, /* set_value_integer */
* 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
* as published by the Free Software Foundation; either version 2
#include <ftypes-int.h>
#ifdef HAVE_LIBPCRE
+
+#include <string.h>
+
#include <pcre.h>
/* Create a pcre_tuple_t object based on the given string pattern */
return TRUE;
}
+static int
+pcre_repr_len(fvalue_t *fv, ftrepr_t rtype)
+{
+ g_assert(rtype == FTREPR_DFILTER);
+ return strlen(fv->value.re->string);
+}
+
+static void
+pcre_to_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
+{
+ g_assert(rtype == FTREPR_DFILTER);
+ strcpy(buf, fv->value.re->string);
+}
+
/* BEHOLD - value contains the string representation of the regular expression,
* and we want to store the compiled PCRE RE object into the value. */
static void
pcre_fvalue_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ pcre_to_repr, /* val_to_string_repr */
+ pcre_repr_len, /* len_string_repr */
pcre_fvalue_set, /* set_value */
NULL, /* set_value_integer */
string_fvalue_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ string_to_repr, /* val_to_string_repr */
+ string_repr_len, /* len_string_repr */
string_fvalue_set, /* set_value */
NULL, /* set_value_integer */
string_fvalue_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ string_to_repr, /* val_to_string_repr */
+ string_repr_len, /* len_string_repr */
string_fvalue_set, /* set_value */
NULL, /* set_value_integer */
g_assert_not_reached();
}
+static int
+val_repr_len(fvalue_t *fv, ftrepr_t rtype)
+{
+ guint length;
+
+ g_assert(rtype == FTREPR_DFILTER);
+ length = tvb_length(fv->value.tvb);
+ /* 3 bytes for each byte of the byte "NN:" minus 1 byte
+ * as there's no trailing ":". */
+ return length * 3 - 1;
+}
+
+static void
+val_to_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
+{
+ guint length;
+ const guint8 *c;
+ char *write_cursor;
+ unsigned int i;
+
+ g_assert(rtype == FTREPR_DFILTER);
+ length = tvb_length(fv->value.tvb);
+ c = tvb_get_ptr(fv->value.tvb, 0, length);
+ write_cursor = buf;
+
+ for (i = 0; i < length; i++) {
+ if (i == 0) {
+ sprintf(write_cursor, "%02x", *c++);
+ write_cursor += 2;
+ }
+ else {
+ sprintf(write_cursor, ":%02x", *c++);
+ write_cursor += 3;
+ }
+ }
+}
+
static gpointer
value_get(fvalue_t *fv)
{
tvbuff_t *tvb = fv_a->value.tvb;
pcre_tuple_t *pcre = fv_b->value.re;
int options = 0;
- int rc;
+ volatile int rc = 1;
const char *data = NULL; /* tvb data */
guint32 tvb_len; /* tvb length */
pcre->ex, /* PCRE extra from pcre_study() */
data, /* The data to check for the pattern... */
tvb_len, /* ... and its length */
- 0, /* Start offset within data */
+ 0, /* Start offset within data */
options, /* PCRE options */
NULL, /* We are not interested in the matched string */
- 0 /* of the pattern; only in success or failure. */
+ 0 /* of the pattern; only in success or failure. */
);
/* NOTE - DO NOT g_free(data) */
}
value_free, /* free_value */
val_from_unparsed, /* val_from_unparsed */
val_from_string, /* val_from_string */
- NULL, /* val_to_string_repr */
- NULL, /* len_string_repr */
+ val_to_repr, /* val_to_string_repr */
+ val_repr_len, /* len_string_repr */
value_set, /* set_value */
NULL, /* set_value_integer */
}
/* This function returns a string allocated with packet lifetime scope.
- * You do not need to [g_]free() this string since it willb e automatically
+ * You do not need to [g_]free() this string since it will be automatically
* freed once the next packet is dissected.
*/
char*
abbrev_len = strlen(hfinfo->abbrev);
/*
- * XXX - we should add "val_to_string_repr" and "string_repr_len"
- * functions for more types, and use them whenever possible.
- *
- * The FT_UINT and FT_INT types are the only tricky ones, as
- * we choose the base in the string expression based on the
- * display base of the field.
+ * XXX - we can't use the "val_to_string_repr" and "string_repr_len"
+ * functions for FT_UINT and FT_INT types, as we choose the base in
+ * the string expression based on the display base of the field.
*
* Note that the base does matter, as this is also used for
* the protocolinfo tap.
*
- * It might be nice to use that in "proto_item_fill_label()"
+ * It might be nice to use them in "proto_item_fill_label()"
* as well, although, there, you'd have to deal with the base
* *and* with resolved values for addresses.
*
g_snprintf(buf, dfilter_len, format, hfinfo->abbrev, fvalue_get_integer64(&finfo->value));
break;
- case FT_IPXNET:
- /*
- * 4 bytes for " == ".
- * 2 bytes for "0x".
- * 8 bytes for 8 digits of 32-bit hex number.
- * 1 byte for the trailing '\0'.
- */
- dfilter_len = abbrev_len + 4 + 2 + 8 + 1;
- buf = ep_alloc0(dfilter_len);
- g_snprintf(buf, dfilter_len, "%s == 0x%08x", hfinfo->abbrev,
- fvalue_get_integer(&finfo->value));
- break;
-
- case FT_IPv6:
- /*
- * 4 bytes for " == ".
- * N bytes for the string for the address.
- * 1 byte for the trailing '\0'.
- */
- stringified = ip6_to_str((struct e_in6_addr*) fvalue_get(&finfo->value));
- dfilter_len = abbrev_len + 4 + strlen(stringified) + 1;
- buf = ep_alloc0(dfilter_len);
- g_snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
- stringified);
- break;
-
/* These use the fvalue's "to_string_repr" method. */
+ case FT_IPXNET:
case FT_BOOLEAN:
case FT_STRING:
case FT_ETHER:
case FT_ABSOLUTE_TIME:
case FT_RELATIVE_TIME:
case FT_IPv4:
+ case FT_IPv6:
case FT_GUID:
/* Figure out the string length needed.
* The ft_repr length.
return scs_subscribe(c,buf);
}
-static gchar* scs_subscribe_int(SCS_collection* c, int i) {
- static gchar buf[SCS_SMALL_SIZE];
-
- g_snprintf(buf, SCS_SMALL_SIZE-1 ,"%i", i);
-
- return scs_subscribe(c,buf);
-}
-
-static gchar* scs_subscribe_float(SCS_collection* c, float f) {
- static gchar buf[SCS_SMALL_SIZE];
-
- g_snprintf(buf, SCS_SMALL_SIZE-1 ,"%f", f);
-
- return scs_subscribe(c,buf);
-}
-
/***************************************************************************
* AVPs & Co.
***************************************************************************
new->n = scs_subscribe(avp_strings, name);
- if (finfo->value.ftype->get_value_integer) {
- value = scs_subscribe_int(avp_strings, fvalue_get_integer(&finfo->value));
-#ifdef _AVP_DEBUGGING
- dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from integer: %s",value);
-#endif
- } else if (finfo->value.ftype->val_to_string_repr) {
+ if (finfo->value.ftype->val_to_string_repr) {
value = scs_subscribe(avp_strings, fvalue_to_string_repr(&finfo->value,FTREPR_DISPLAY,NULL));
#ifdef _AVP_DEBUGGING
dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from string: %s",value);
-#endif
- } else if (finfo->value.ftype->get_value_floating) {
- value = scs_subscribe_float(avp_strings, (float) fvalue_get_floating(&finfo->value));
-#ifdef _AVP_DEBUGGING
- dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from float: %s",value);
#endif
} else {
#ifdef _AVP_DEBUGGING