/*
- * $Id: ftype-bytes.c,v 1.13 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-bytes.c,v 1.14 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
fv->value.bytes = value;
}
+static int
+bytes_strlen(fvalue_t *fv)
+{
+ /* 3 bytes for each byte of the byte "NN:" minus 1 byte
+ * as there's no trailing ":" */
+ return fv->value.bytes->len * 3 - 1;
+}
+
+static char *
+bytes_to_string(fvalue_t *fv)
+{
+ guint8 *c;
+ char *buf;
+ char *write_cursor;
+ unsigned int i;
+
+ c = fv->value.bytes->data;
+ buf = g_malloc0(bytes_strlen(fv));
+ write_cursor = buf;
+
+ for (i = 0; i < fv->value.bytes->len; i++) {
+ if (i == 0) {
+ sprintf(write_cursor, "%02x", *c++);
+ write_cursor += 2;
+
+ }
+ else {
+ sprintf(write_cursor, ":%02x", *c++);
+ write_cursor += 3;
+ }
+ }
+ return buf;
+}
+
static void
common_fvalue_set(fvalue_t *fv, guint8* data, guint len)
{
bytes_fvalue_new, /* new_value */
bytes_fvalue_free, /* free_value */
val_from_string, /* val_from_string */
+ bytes_to_string, /* val_to_string_repr */
+ bytes_strlen, /* len_string_repr */
bytes_fvalue_set, /* set_value */
NULL, /* set_value_integer */
value_get, /* get_value */
NULL, /* get_value_integer */
- NULL,
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
bytes_fvalue_new, /* new_value */
bytes_fvalue_free, /* free_value */
val_from_string, /* val_from_string */
+ bytes_to_string, /* val_to_string_repr */
+ bytes_strlen, /* len_string_repr */
bytes_fvalue_set, /* set_value */
NULL, /* set_value_integer */
value_get, /* get_value */
NULL, /* get_value_integer */
- NULL,
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
};
static ftype_t ether_type = {
- "FT_ETHER",
- "Ethernet or other MAC address",
- ETHER_LEN,
- bytes_fvalue_new,
- bytes_fvalue_free,
- ether_from_string,
+ "FT_ETHER", /* name */
+ "Ethernet or other MAC address",/* pretty_name */
+ ETHER_LEN, /* wire_size */
+ bytes_fvalue_new, /* new_value */
+ bytes_fvalue_free, /* free_value */
+ ether_from_string, /* val_from_string */
+ bytes_to_string, /* val_to_string_repr */
+ bytes_strlen, /* len_string_repr */
- ether_fvalue_set,
- NULL,
- NULL,
+ ether_fvalue_set, /* set_value */
+ NULL, /* set_value_integer */
+ NULL, /* set_value_floating */
- value_get,
- NULL,
- NULL,
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
};
static ftype_t ipv6_type = {
- "FT_IPv6",
- "IPv6 address",
- IPv6_LEN,
- bytes_fvalue_new,
- bytes_fvalue_free,
- ipv6_from_string,
+ "FT_IPv6", /* name */
+ "IPv6 address", /* pretty_name */
+ IPv6_LEN, /* wire_size */
+ bytes_fvalue_new, /* new_value */
+ bytes_fvalue_free, /* free_value */
+ ipv6_from_string, /* val_from_string */
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
- ipv6_fvalue_set,
- NULL,
- NULL,
+ ipv6_fvalue_set, /* set_value */
+ NULL, /* set_value_integer */
+ NULL, /* set_value_floating */
- value_get,
- NULL,
- NULL,
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
};
static ftype_t u64_type = {
- "FT_UINT64",
- "Unsigned 64-bit integer",
- U64_LEN,
- bytes_fvalue_new,
- bytes_fvalue_free,
- u64_from_string,
+ "FT_UINT64", /* name */
+ "Unsigned 64-bit integer", /* pretty_name */
+ U64_LEN, /* wire_size */
+ bytes_fvalue_new, /* new_value */
+ bytes_fvalue_free, /* free_value */
+ u64_from_string, /* val_from_string */
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
- u64_fvalue_set,
- NULL,
- NULL,
+ u64_fvalue_set, /* set_value */
+ NULL, /* set_value_integer */
+ NULL, /* set_value_floating */
- value_get,
- NULL,
- NULL,
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
};
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,
+ "FT_INT64", /* name */
+ "Signed 64-bit integer", /* pretty_name */
+ U64_LEN, /* wire_size */
+ bytes_fvalue_new, /* new_value */
+ bytes_fvalue_free, /* free_value */
+ i64_from_string, /* val_from_string */
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
+
+ u64_fvalue_set, /* set_value */
+ NULL, /* set_value_integer */
+ NULL, /* set_value_floating */
+
+ value_get, /* get_value */
+ NULL, /* get_value_integer */
+ NULL, /* get_value_floating */
cmp_eq,
cmp_ne,
/*
- * $Id: ftype-double.c,v 1.7 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-double.c,v 1.8 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
double_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
NULL,
double_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
NULL,
/*
- * $Id: ftype-integer.c,v 1.11 2002/12/19 02:58:51 guy Exp $
+ * $Id: ftype-integer.c,v 1.12 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
boolean_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
ipxnet_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
int_fvalue_new,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
/*
- * $Id: ftype-ipv4.c,v 1.9 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-ipv4.c,v 1.10 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
NULL,
NULL,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
set_integer,
/*
- * $Id: ftype-none.c,v 1.4 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-none.c,v 1.5 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
NULL,
NULL,
NULL,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
NULL,
NULL,
/*
- * $Id: ftype-string.c,v 1.7 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-string.c,v 1.8 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
string_fvalue_new,
string_fvalue_free,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
string_fvalue_set,
NULL,
string_fvalue_new,
string_fvalue_free,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
string_fvalue_set,
NULL,
string_fvalue_new,
string_fvalue_free,
val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
string_fvalue_set,
NULL,
/*
- * $Id: ftype-time.c,v 1.17 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-time.c,v 1.18 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
time_fvalue_new,
NULL,
absolute_val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
time_fvalue_set,
NULL,
time_fvalue_new,
NULL,
relative_val_from_string,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
time_fvalue_set,
NULL,
/*
- * $Id: ftype-tvbuff.c,v 1.7 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftype-tvbuff.c,v 1.8 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
value_new,
NULL,
NULL,
+ NULL, /* val_to_string_repr */
+ NULL, /* len_string_repr */
value_set,
NULL,
/*
- * $Id: ftypes-int.h,v 1.6 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftypes-int.h,v 1.7 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
typedef void (*FvalueFreeFunc)(fvalue_t*);
typedef gboolean (*FvalueFromString)(fvalue_t*, char*, LogFunc);
+typedef char* (*FvalueToStringRepr)(fvalue_t*);
+typedef int (*FvalueStringReprLen)(fvalue_t*);
typedef void (*FvalueSetFunc)(fvalue_t*, gpointer, gboolean);
typedef void (*FvalueSetIntegerFunc)(fvalue_t*, guint32);
FvalueNewFunc new_value;
FvalueFreeFunc free_value;
FvalueFromString val_from_string;
+ FvalueToStringRepr val_to_string_repr;
+ FvalueStringReprLen len_string_repr;
/* could be union */
FvalueSetFunc set_value;
/*
- * $Id: ftypes.c,v 1.7 2002/08/28 20:41:00 jmayer Exp $
+ * $Id: ftypes.c,v 1.8 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
return fv->ftype->wire_size;
}
+int
+fvalue_string_repr_len(fvalue_t *fv)
+{
+ g_assert(fv->ftype->len_string_repr);
+ return fv->ftype->len_string_repr(fv);
+}
+
+char *
+fvalue_to_string_repr(fvalue_t *fv)
+{
+ g_assert(fv->ftype->val_to_string_repr);
+ return fv->ftype->val_to_string_repr(fv);
+}
+
typedef struct {
fvalue_t *fv;
GByteArray *bytes;
/* ftypes.h
* Definitions for field types
*
- * $Id: ftypes.h,v 1.15 2002/12/19 02:58:51 guy Exp $
+ * $Id: ftypes.h,v 1.16 2003/02/08 04:22:37 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
fvalue_t*
fvalue_from_string(ftenum_t ftype, char *s, LogFunc log);
+int
+fvalue_string_repr_len(fvalue_t *fv);
+
+char *
+fvalue_to_string_repr(fvalue_t *fv);
+
const char*
fvalue_type_name(fvalue_t *fv);
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.81 2003/01/31 03:17:52 guy Exp $
+ * $Id: proto.c,v 1.82 2003/02/08 04:22:30 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
fvalue_get_floating(finfo->value));
break;
- case FT_ETHER:
- /*
- * 4 bytes for " == ".
- * 17 bytes for "NN:NN:NN:NN:NN:NN".
- * 1 byte for the trailing '\0'.
- */
- dfilter_len = abbrev_len + 4 + 17 + 1;
- buf = g_malloc0(dfilter_len);
- snprintf(buf, dfilter_len, "%s == %s",
- hfinfo->abbrev,
- ether_to_str(fvalue_get(finfo->value)));
- break;
case FT_ABSOLUTE_TIME:
/*
hfinfo->abbrev, value_str);
break;
+ case FT_ETHER:
case FT_BYTES:
case FT_UINT_BYTES:
/*
* 4 bytes for " == ".
- * 3 bytes for each byte of the byte string, as
- * "NN:", minus 1 byte as there's no trailing ":".
* 1 byte for the trailing '\0'.
*
- * XXX - what are the other 2 bytes for?
*/
- dfilter_len = fvalue_length(finfo->value)*3 - 1;
- dfilter_len += abbrev_len + 4 + 2 + 1;
+ dfilter_len = fvalue_string_repr_len(finfo->value);
+ dfilter_len += abbrev_len + 4 + 1;
buf = g_malloc0(dfilter_len);
- snprintf(buf, dfilter_len, "%s == %s",
- hfinfo->abbrev,
- /* XXX - bytes_to_str_punct() will truncate long strings with '...' */
- bytes_to_str_punct(fvalue_get(finfo->value),
- fvalue_length(finfo->value),':'));
+ snprintf(buf, dfilter_len, "%s == ", hfinfo->abbrev);
+ stringified = fvalue_to_string_repr(finfo->value);
+ strcat(buf, stringified);
+ g_free(stringified);
break;
default: