2006-03-11 01:45:42 +00:00
|
|
|
/*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2006-03-11 01:45:42 +00:00
|
|
|
* Copyright 2001 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2006-03-11 01:45:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <stdlib.h>
|
2006-03-11 01:45:42 +00:00
|
|
|
|
|
|
|
#include <ftypes-int.h>
|
|
|
|
#include <epan/guid-utils.h>
|
2013-11-09 13:41:10 +00:00
|
|
|
#include <epan/to_str.h>
|
2006-03-11 01:45:42 +00:00
|
|
|
|
|
|
|
static void
|
2014-01-15 01:05:03 +00:00
|
|
|
guid_fvalue_set_guid(fvalue_t *fv, const e_guid_t *value)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2014-01-15 01:05:03 +00:00
|
|
|
fv->value.guid = *value;
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
value_get(fvalue_t *fv)
|
|
|
|
{
|
2006-03-19 20:45:45 +00:00
|
|
|
return &(fv->value.guid);
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-01-15 01:05:03 +00:00
|
|
|
get_guid(const char *s, e_guid_t *guid)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2006-03-19 20:45:45 +00:00
|
|
|
size_t i, n;
|
2014-01-15 01:05:03 +00:00
|
|
|
const char *p;
|
2019-04-17 04:35:08 +00:00
|
|
|
char digits[3];
|
2006-03-19 20:45:45 +00:00
|
|
|
static const char fmt[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
|
2019-04-17 04:35:08 +00:00
|
|
|
const size_t fmtchars = sizeof(fmt) - 1;
|
2006-03-19 20:45:45 +00:00
|
|
|
|
2019-04-17 04:35:08 +00:00
|
|
|
n = strnlen(s, fmtchars);
|
|
|
|
if (n != fmtchars)
|
2006-03-19 20:45:45 +00:00
|
|
|
return FALSE;
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
if (fmt[i] == 'X') {
|
2014-10-17 01:26:03 +00:00
|
|
|
if (!g_ascii_isxdigit(s[i]))
|
2006-03-19 20:45:45 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (s[i] != fmt[i])
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-03-19 20:45:45 +00:00
|
|
|
p = s;
|
2019-04-17 04:35:08 +00:00
|
|
|
guid->data1 = (guint32)strtoul(p, NULL, 16);
|
2006-03-11 01:45:42 +00:00
|
|
|
p += 9;
|
2019-04-17 04:35:08 +00:00
|
|
|
guid->data2 = (guint16)strtoul(p, NULL, 16);
|
2006-03-11 01:45:42 +00:00
|
|
|
p += 5;
|
2019-04-17 04:35:08 +00:00
|
|
|
guid->data3 = (guint16)strtoul(p, NULL, 16);
|
2006-03-11 01:45:42 +00:00
|
|
|
p += 5;
|
2006-03-19 20:45:45 +00:00
|
|
|
for (i=0; i < sizeof(guid->data4); i++) {
|
|
|
|
if (*p == '-') p++;
|
|
|
|
digits[0] = *(p++);
|
|
|
|
digits[1] = *(p++);
|
|
|
|
digits[2] = '\0';
|
|
|
|
guid->data4[i] = (guint8)strtoul(digits, NULL, 16);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-01-18 10:22:19 +00:00
|
|
|
guid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2006-03-19 20:45:45 +00:00
|
|
|
e_guid_t guid;
|
2006-03-11 01:45:42 +00:00
|
|
|
|
2006-03-19 20:45:45 +00:00
|
|
|
if (!get_guid(s, &guid)) {
|
2015-01-18 10:22:19 +00:00
|
|
|
if (err_msg != NULL)
|
|
|
|
*err_msg = g_strdup_printf("\"%s\" is not a valid GUID.", s);
|
2006-03-19 20:45:45 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-03-11 01:45:42 +00:00
|
|
|
|
2006-03-19 20:45:45 +00:00
|
|
|
fv->value.guid = guid;
|
|
|
|
return TRUE;
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-04 02:56:16 +00:00
|
|
|
guid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2006-03-19 20:45:45 +00:00
|
|
|
return GUID_STR_LEN;
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-10 20:37:44 +00:00
|
|
|
guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2016-05-10 20:37:44 +00:00
|
|
|
guid_to_str_buf(&fv->value.guid, buf, size);
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 15:00:51 +00:00
|
|
|
static int
|
|
|
|
cmp_order(const fvalue_t *a, const fvalue_t *b)
|
2006-03-11 01:45:42 +00:00
|
|
|
{
|
2021-10-10 15:00:51 +00:00
|
|
|
return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t));
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ftype_register_guid(void)
|
|
|
|
{
|
|
|
|
|
2006-03-19 20:45:45 +00:00
|
|
|
static ftype_t guid_type = {
|
2006-05-02 14:26:17 +00:00
|
|
|
FT_GUID, /* ftype */
|
2010-05-11 21:46:17 +00:00
|
|
|
"FT_GUID", /* name */
|
2006-03-19 20:45:45 +00:00
|
|
|
"Globally Unique Identifier", /* pretty_name */
|
|
|
|
GUID_LEN, /* wire_size */
|
|
|
|
NULL, /* new_value */
|
|
|
|
NULL, /* 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 */
|
|
|
|
|
2017-03-07 21:35:45 +00:00
|
|
|
{ .set_value_guid = guid_fvalue_set_guid }, /* union set_value */
|
2017-03-19 20:16:03 +00:00
|
|
|
{ .get_value_ptr = value_get }, /* union get_value */
|
2006-03-19 20:45:45 +00:00
|
|
|
|
2021-10-10 15:00:51 +00:00
|
|
|
cmp_order,
|
2006-03-19 20:45:45 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL, /* cmp_matches */
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
ftype_register(FT_GUID, &guid_type);
|
2006-03-11 01:45:42 +00:00
|
|
|
}
|
2015-02-15 03:31:53 +00:00
|
|
|
|
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2015-02-15 03:31:53 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|