2 * Wireshark - Network traffic analyzer
3 * By Gerald Combs <gerald@wireshark.org>
4 * Copyright 2001 Gerald Combs
6 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <ftypes-int.h>
15 #include <epan/guid-utils.h>
16 #include <epan/to_str.h>
17 #include <wsutil/array.h>
20 guid_fvalue_set_guid(fvalue_t
*fv
, const e_guid_t
*value
)
22 fv
->value
.guid
= *value
;
25 static const e_guid_t
*
26 value_get(fvalue_t
*fv
)
28 return &(fv
->value
.guid
);
32 get_guid(const char *s
, e_guid_t
*guid
)
37 static const char fmt
[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
38 const size_t fmtchars
= sizeof(fmt
) - 1;
40 n
= strnlen(s
, fmtchars
);
45 if (!g_ascii_isxdigit(s
[i
]))
54 guid
->data1
= (uint32_t)strtoul(p
, NULL
, 16);
56 guid
->data2
= (uint16_t)strtoul(p
, NULL
, 16);
58 guid
->data3
= (uint16_t)strtoul(p
, NULL
, 16);
60 for (i
=0; i
< sizeof(guid
->data4
); i
++) {
65 guid
->data4
[i
] = (uint8_t)strtoul(digits
, NULL
, 16);
71 guid_from_literal(fvalue_t
*fv
, const char *s
, bool allow_partial_value _U_
, char **err_msg
)
75 if (!get_guid(s
, &guid
)) {
77 *err_msg
= ws_strdup_printf("\"%s\" is not a valid GUID.", s
);
81 fv
->value
.guid
= guid
;
86 guid_to_repr(wmem_allocator_t
*scope
, const fvalue_t
*fv
, ftrepr_t rtype _U_
, int field_display _U_
)
88 return guid_to_str(scope
, &fv
->value
.guid
);
92 cmp_order(const fvalue_t
*a
, const fvalue_t
*b
, int *cmp
)
94 *cmp
= memcmp(&a
->value
.guid
, &b
->value
.guid
, sizeof(e_guid_t
));
99 value_hash(const fvalue_t
*fv
)
101 return guid_hash(&fv
->value
.guid
);
105 ftype_register_guid(void)
108 static const ftype_t guid_type
= {
110 GUID_LEN
, /* wire_size */
111 NULL
, /* new_value */
112 NULL
, /* copy_value */
113 NULL
, /* free_value */
114 guid_from_literal
, /* val_from_literal */
115 NULL
, /* val_from_string */
116 NULL
, /* val_from_charconst */
117 NULL
, /* val_from_uinteger64 */
118 NULL
, /* val_from_sinteger64 */
119 NULL
, /* val_from_double */
120 guid_to_repr
, /* val_to_string_repr */
122 NULL
, /* val_to_uinteger64 */
123 NULL
, /* val_to_sinteger64 */
124 NULL
, /* val_to_double */
126 { .set_value_guid
= guid_fvalue_set_guid
}, /* union set_value */
127 { .get_value_guid
= value_get
}, /* union get_value */
131 NULL
, /* cmp_matches */
133 value_hash
, /* hash */
139 NULL
, /* unary_minus */
147 ftype_register(FT_GUID
, &guid_type
);
151 ftype_register_pseudofields_guid(int proto
)
153 static int hf_ft_guid
;
155 static hf_register_info hf_ftypes
[] = {
157 { "FT_GUID", "_ws.ftypes.guid",
158 FT_GUID
, BASE_NONE
, NULL
, 0x00,
163 proto_register_field_array(proto
, hf_ftypes
, array_length(hf_ftypes
));
167 * Editor modelines - https://www.wireshark.org/tools/modelines.html
172 * indent-tabs-mode: nil
175 * vi: set shiftwidth=4 tabstop=8 expandtab:
176 * :indentSize=4:tabSize=8:noTabs=true: