ftype-double.c \
ftype-integer.c \
ftype-ipv4.c \
+ ftype-guid.c \
ftype-none.c \
ftype-pcre.c \
ftype-string.c \
ftype-double.obj \
ftype-integer.obj \
ftype-ipv4.obj \
+ ftype-guid.obj \
ftype-none.obj \
ftype-pcre.obj \
ftype-string.obj \
#define ETHER_LEN 6
#define IPv6_LEN 16
-#define GUID_LEN 16
static void
bytes_fvalue_new(fvalue_t *fv)
return fv->value.bytes->len * 3 - 1;
}
-static int
-guid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
-{
- return GUID_STR_LEN;
-}
-
-static void
-guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
-{
- guid_to_str_buf(fv->value.bytes->data, buf, GUID_STR_LEN);
-}
-
static int
oid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
{
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 void
oid_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
{
ip6_to_str_buf((struct e_in6_addr *)fv->value.bytes->data, buf);
}
-static gboolean
-get_guid(char *s, guint8 *buf)
-{
- size_t i, n;
- char *p, two_digits[3];
- static const char fmt[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
-
- n = strlen(s);
- if (n != strlen(fmt))
- return FALSE;
- for (i=0; i<n; i++) {
- if (fmt[i] == 'X') {
- if (!isxdigit((guchar)s[i]))
- return FALSE;
- } else {
- if (s[i] != fmt[i])
- return FALSE;
- }
- }
- for (p=s,i=0; i<GUID_LEN; i++) {
- if (*p == '-') p++;
- two_digits[0] = *(p++);
- two_digits[1] = *(p++);
- two_digits[2] = '\0';
- buf[i] = (guint8)strtoul(two_digits, NULL, 16);
- }
- return TRUE;
-}
-
-static gboolean
-guid_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value, LogFunc logfunc)
-{
- guint8 buffer[GUID_LEN];
-
- /*
- * 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;
- }
-
- if (!get_guid(s, buffer)) {
- logfunc("\"%s\" is not a valid GUID.", s);
- return FALSE;
- }
-
- guid_fvalue_set(fv, buffer, FALSE);
- return TRUE;
-}
-
static gboolean
oid_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFunc logfunc)
{
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 */
- guid_to_repr, /* val_to_string_repr */
- guid_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,
- };
-
static ftype_t oid_type = {
"OID", /* name */
"OBJECT IDENTIFIER", /* pretty_name */
ftype_register(FT_UINT_BYTES, &uint_bytes_type);
ftype_register(FT_ETHER, ðer_type);
ftype_register(FT_IPv6, &ipv6_type);
- ftype_register(FT_GUID, &guid_type);
ftype_register(FT_OID, &oid_type);
}
--- /dev/null
+/*\r
+ * $Id$\r
+ *\r
+ * Ethereal - Network traffic analyzer\r
+ * By Gerald Combs <gerald@ethereal.com>\r
+ * Copyright 2001 Gerald Combs\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif\r
+\r
+#include <string.h>\r
+\r
+#include <ftypes-int.h>\r
+#include <epan/guid-utils.h>\r
+\r
+#define GUID_LEN 16\r
+\r
+static void\r
+set_guid(fvalue_t *fv, e_guid_t *value)\r
+{\r
+ fv->value.guid = *value;\r
+}\r
+\r
+static gpointer\r
+value_get(fvalue_t *fv)\r
+{\r
+ return &(fv->value.guid);\r
+}\r
+\r
+static gboolean\r
+get_guid(char *s, e_guid_t *guid)\r
+{\r
+ size_t i, n;\r
+ char *p, digits[9];\r
+ static const char fmt[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";\r
+\r
+ n = strlen(s);\r
+ if (n != strlen(fmt))\r
+ return FALSE;\r
+ for (i=0; i<n; i++) {\r
+ if (fmt[i] == 'X') {\r
+ if (!isxdigit((guchar)s[i]))\r
+ return FALSE;\r
+ } else {\r
+ if (s[i] != fmt[i])\r
+ return FALSE;\r
+ }\r
+ }\r
+ \r
+ p = s;\r
+ strncpy(digits, p, 8); \r
+ digits[8] = '\0';\r
+ guid->data1 = strtoul(digits, NULL, 16);\r
+ p += 9;\r
+ strncpy(digits, p, 4); \r
+ digits[4] = '\0';\r
+ guid->data2 = (guint16)strtoul(digits, NULL, 16);\r
+ p += 5;\r
+ strncpy(digits, p, 4); \r
+ digits[4] = '\0';\r
+ guid->data3 = (guint16)strtoul(digits, NULL, 16);\r
+ p += 5;\r
+ for (i=0; i < sizeof(guid->data4); i++) {\r
+ if (*p == '-') p++;\r
+ digits[0] = *(p++);\r
+ digits[1] = *(p++);\r
+ digits[2] = '\0';\r
+ guid->data4[i] = (guint8)strtoul(digits, NULL, 16);\r
+ }\r
+ return TRUE;\r
+}\r
+\r
+static gboolean\r
+guid_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value, LogFunc logfunc)\r
+{\r
+ e_guid_t guid;\r
+\r
+ if (!get_guid(s, &guid)) {\r
+ logfunc("\"%s\" is not a valid GUID.", s);\r
+ return FALSE;\r
+ }\r
+\r
+ set_guid(fv, &guid);\r
+ return TRUE;\r
+}\r
+\r
+static int\r
+guid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)\r
+{\r
+ return GUID_STR_LEN;\r
+}\r
+\r
+static void\r
+guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)\r
+{\r
+ guid_to_str_buf(&fv->value.guid, buf, GUID_STR_LEN);\r
+}\r
+\r
+static gboolean\r
+cmp_eq(fvalue_t *a, fvalue_t *b)\r
+{\r
+ return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) == 0;\r
+}\r
+\r
+static gboolean\r
+cmp_ne(fvalue_t *a, fvalue_t *b)\r
+{\r
+ return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) != 0;\r
+}\r
+\r
+void\r
+ftype_register_guid(void)\r
+{\r
+\r
+ static ftype_t guid_type = {\r
+ "GUID", /* name */\r
+ "Globally Unique Identifier", /* pretty_name */\r
+ GUID_LEN, /* wire_size */\r
+ NULL, /* new_value */\r
+ NULL, /* free_value */\r
+ guid_from_unparsed, /* val_from_unparsed */\r
+ NULL, /* val_from_string */\r
+ guid_to_repr, /* val_to_string_repr */\r
+ guid_repr_len, /* len_string_repr */\r
+\r
+ set_guid, /* set_value */\r
+ NULL, /* set_value_integer */\r
+ NULL, /* set_value_integer64 */\r
+ NULL, /* set_value_floating */\r
+\r
+ value_get, /* get_value */\r
+ NULL, /* get_value_integer */\r
+ NULL, /* get_value_integer64 */\r
+ NULL, /* get_value_floating */\r
+\r
+ cmp_eq,\r
+ cmp_ne,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ NULL, /* cmp_matches */\r
+\r
+ NULL,\r
+ NULL,\r
+ };\r
+\r
+ ftype_register(FT_GUID, &guid_type);\r
+}\r
void ftype_register_double(void);
void ftype_register_integers(void);
void ftype_register_ipv4(void);
+void ftype_register_guid(void);
void ftype_register_none(void);
void ftype_register_string(void);
void ftype_register_time(void);
ftype_register_double();
ftype_register_integers();
ftype_register_ipv4();
+ ftype_register_guid();
ftype_register_none();
ftype_register_string();
ftype_register_time();
/* ---------------- FVALUE ----------------- */
#include <epan/ipv4.h>
+#include <epan/guid-utils.h>
#include <epan/tvbuff.h>
#include <epan/nstime.h>
GByteArray *bytes;
GString *gstring;
ipv4_addr ipv4;
+ e_guid_t guid;
nstime_t time;
tvbuff_t *tvb;
#ifdef HAVE_LIBPCRE
--- /dev/null
+/* guid-utils.h\r
+ * Definitions for GUID handling\r
+ *\r
+ * $Id$\r
+ *\r
+ * Ethereal - Network traffic analyzer\r
+ * By Gerald Combs <gerald@ethereal.com>\r
+ *\r
+ * Copyright 1998 Gerald Combs\r
+ *\r
+ * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifndef __GUID_UTILS_H__\r
+#define __GUID_UTILS_H__\r
+\r
+typedef struct _e_guid_t {\r
+ guint32 data1;\r
+ guint16 data2;\r
+ guint16 data3;\r
+ guint8 data4[8];\r
+} e_guid_t;\r
+\r
+#endif /* __GUID_UTILS_H__ */\r
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);
+proto_tree_set_guid(field_info *fi, const e_guid_t *value_ptr);
static void
-proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, gint start);
+proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, gint start, gboolean little_endian);
static void
proto_tree_set_oid(field_info *fi, const guint8* value_ptr, gint length);
static void
case FT_GUID:
DISSECTOR_ASSERT(length == 16);
- proto_tree_set_guid_tvb(new_fi, tvb, start);
+ proto_tree_set_guid_tvb(new_fi, tvb, start, little_endian);
break;
case FT_OID:
/* 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)
+ const e_guid_t *value_ptr)
{
proto_item *pi;
field_info *new_fi;
proto_item *
proto_tree_add_guid_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length,
- const guint8* value_ptr)
+ const e_guid_t *value_ptr)
{
proto_item *pi;
proto_item *
proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
- gint start, gint length, const guint8* value_ptr,
+ gint start, gint length, const e_guid_t *value_ptr,
const char *format, ...)
{
proto_item *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, ...)
+ const e_guid_t *value_ptr, const char *format, ...)
{
proto_item *pi;
va_list ap;
/* Set the FT_GUID value */
static void
-proto_tree_set_guid(field_info *fi, const guint8* value_ptr)
+proto_tree_set_guid(field_info *fi, const e_guid_t *value_ptr)
{
DISSECTOR_ASSERT(value_ptr != NULL);
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_tvb(field_info *fi, tvbuff_t *tvb, gint start, gboolean little_endian)
{
- proto_tree_set_guid(fi, tvb_get_ptr(tvb, start, 16));
+ e_guid_t guid;
+
+ tvb_get_guid(tvb, start, &guid, little_endian);
+ proto_tree_set_guid(fi, &guid);
}
/* Add a FT_OID to a proto_tree */
guint8 *bytes;
guint32 integer;
ipv4_addr *ipv4;
+ e_guid_t *guid;
guint32 n_addr; /* network-order IPv4 address */
const gchar *name;
int ret; /*tmp return value */
break;
case FT_GUID:
- bytes = fvalue_get(&fi->value);
+ guid = fvalue_get(&fi->value);
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
"%s: %s", hfinfo->name,
- guid_to_str(bytes));
+ guid_to_str(guid));
if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
label_str[ITEM_LABEL_LENGTH - 1] = '\0';
break;
@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);
+ gint length, const e_guid_t *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);
+ gint length, const e_guid_t *value_ptr);
/** Add a formatted FT_GUID to a proto_tree, with the format generating
the string for the value and with the field name being included
@return the newly created item */
extern proto_item *
proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
- gint start, gint length, const guint8* value_ptr, const char *format,
+ gint start, gint length, const e_guid_t *value_ptr, const char *format,
...) GNUC_FORMAT_CHECK(printf,7,8);
/** Add a formatted FT_GUID to a proto_tree, with the format generating
@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);
+ gint length, const e_guid_t *value_ptr, const char *format, ...) GNUC_FORMAT_CHECK(printf,7,8);
/** Add a FT_OID to a proto_tree.
@param tree the tree to append this item to
gint length, const guint8* value_ptr);
/** Add a hidden FT_OID to a proto_tree.
- @deprecated use proto_tree_add_guid() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
+ @deprecated use proto_tree_add_oid() and a subsequent call to PROTO_ITEM_SET_HIDDEN() instead */
extern proto_item *
proto_tree_add_oid_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
gint length, const guint8* value_ptr);
return buf;
}
-gchar* guid_to_str(const guint8 *guid) {
+gchar* guid_to_str(const e_guid_t *guid) {
gchar *buf;
buf=ep_alloc(GUID_STR_LEN);
return guid_to_str_buf(guid, buf, GUID_STR_LEN);
}
-gchar* guid_to_str_buf(const guint8 *guid, gchar *buf, int buf_len) {
- g_snprintf(buf, buf_len, "%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]);
+gchar* guid_to_str_buf(const e_guid_t *guid, gchar *buf, int buf_len) {
+ g_snprintf(buf, buf_len, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ guid->data1, guid->data2, guid->data3,
+ guid->data4[0], guid->data4[1], guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5], guid->data4[6], guid->data4[7]);
return buf;
}
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*, int);
-extern gchar* guid_to_str(const guint8*);
-extern gchar* guid_to_str_buf(const guint8*, gchar*, int);
+extern gchar* guid_to_str(const e_guid_t*);
+extern gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
void tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len);
memcpy(addr, ptr, sizeof *addr);
}
+/* Fetch a GUID. */
+void
+tvb_get_ntohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid)
+{
+ const guint8* ptr;
+
+ ensure_contiguous(tvb, offset, sizeof(*guid));
+ guid->data1 = tvb_get_ntohl(tvb, offset);
+ guid->data2 = tvb_get_ntohs(tvb, offset + 4);
+ guid->data3 = tvb_get_ntohs(tvb, offset + 6);
+ tvb_memcpy(tvb, guid->data4, offset + 8, sizeof guid->data4);
+}
+
+void
+tvb_get_letohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid)
+{
+ const guint8* ptr;
+
+ ensure_contiguous(tvb, offset, sizeof(*guid));
+ guid->data1 = tvb_get_letohl(tvb, offset);
+ guid->data2 = tvb_get_letohs(tvb, offset + 4);
+ guid->data3 = tvb_get_letohs(tvb, offset + 6);
+ tvb_memcpy(tvb, guid->data4, offset + 8, sizeof guid->data4);
+}
+
+void
+tvb_get_guid(tvbuff_t *tvb, gint offset, e_guid_t *guid, gboolean little_endian)
+{
+ if (little_endian) {
+ tvb_get_letohguid(tvb, offset, guid);
+ } else {
+ tvb_get_ntohguid(tvb, offset, guid);
+ }
+}
+
/* Find first occurence of needle in tvbuff, starting at offset. Searches
* at most maxlength number of bytes; if maxlength is -1, searches to
* end of tvbuff.
#include <glib.h>
#include <epan/ipv6-utils.h>
+#include <epan/guid-utils.h>
#include "exceptions.h"
/** @file
/* Fetch an IPv6 address. */
extern void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
+/* Fetch a GUID. */
+extern void tvb_get_ntohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid);
+extern void tvb_get_letohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid);
+extern void tvb_get_guid(tvbuff_t *tvb, gint offset, e_guid_t *guid, gboolean little_endian);
+
+
/** Returns target for convenience. Does not suffer from possible
* expense of tvb_get_ptr(), since this routine is smart enough
* to copy data in chunks if the request range actually exists in