regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / plugins / epan / transum / extractors.c
blob92c3a1444070e4e8e5a4044ac3a28f16f64a01fb
1 /* extractors.c
2 * Routines for the TRANSUM response time analyzer post-dissector
3 * By Paul Offord <paul.offord@advance7.com>
4 * Copyright 2016 Advance Seven Limited
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
13 #include <epan/prefs.h>
14 #include <wsutil/array.h>
15 #include "extractors.h"
18 This function extracts a field value (e.g. tcp.len) from a tree. Because a packet may contain
19 multiple values for the field, the extracted values are returned in a result_array. The
20 number of array entries is returned in element_count.
22 Return is 0 if all went well. If this function return -1 it is probably because the tree did not
23 include the field defined by the field_id.
25 int extract_uint(proto_tree *tree, int field_id, uint32_t *result_array, size_t *element_count)
27 GPtrArray *finfo_array;
29 *element_count = 0;
30 if (tree == NULL) {
31 return -1;
34 finfo_array = proto_get_finfo_ptr_array(tree, field_id);
36 if (finfo_array == NULL) {
37 return -1;
40 *element_count = g_ptr_array_len(finfo_array);
42 for (size_t i = 0; i < *element_count && i < MAX_RETURNED_ELEMENTS; i++)
44 result_array[i] = fvalue_get_uinteger(((field_info*)finfo_array->pdata[i])->value);
47 return 0;
50 int extract_ui64(proto_tree *tree, int field_id, uint64_t *result_array, size_t *element_count)
52 GPtrArray *finfo_array;
54 *element_count = 0;
55 if (tree == NULL) {
56 return -1;
59 finfo_array = proto_get_finfo_ptr_array(tree, field_id);
61 if (finfo_array == NULL) {
62 return -1;
65 *element_count = g_ptr_array_len(finfo_array);
67 for (size_t i = 0; i < *element_count && i < MAX_RETURNED_ELEMENTS; i++)
69 result_array[i] = fvalue_get_uinteger64(((field_info*)finfo_array->pdata[i])->value);
72 return 0;
75 int extract_si64(proto_tree *tree, int field_id, uint64_t *result_array, size_t *element_count)
77 GPtrArray *finfo_array;
79 *element_count = 0;
80 if (tree == NULL) {
81 return -1;
84 finfo_array = proto_get_finfo_ptr_array(tree, field_id);
86 if (finfo_array == NULL) {
87 return -1;
90 *element_count = g_ptr_array_len(finfo_array);
92 for (size_t i = 0; i < *element_count && i < MAX_RETURNED_ELEMENTS; i++)
94 result_array[i] = fvalue_get_sinteger64(((field_info*)finfo_array->pdata[i])->value);
97 return 0;
100 int extract_bool(proto_tree *tree, int field_id, bool *result_array, size_t *element_count)
102 GPtrArray *finfo_array;
104 *element_count = 0;
105 if (tree == NULL) {
106 return -1;
109 finfo_array = proto_get_finfo_ptr_array(tree, field_id);
111 if (finfo_array == NULL) {
112 return -1;
115 *element_count = g_ptr_array_len(finfo_array);
117 for (size_t i = 0; i < *element_count && i < MAX_RETURNED_ELEMENTS; i++)
119 fvalue_t *fv = ((field_info*)finfo_array->pdata[i])->value;
121 ws_assert(fvalue_type_ftenum(fv) == FT_BOOLEAN);
122 if (fvalue_get_uinteger64(fv))
123 result_array[i] = true;
124 else
125 result_array[i] = false;
128 return 0;
132 * Extract a count of the number of instances of a given field.
134 int extract_instance_count(proto_tree *tree, int field_id, size_t *element_count)
136 GPtrArray *finfo_array;
138 *element_count = 0;
139 if (tree == NULL) {
140 return -1;
143 finfo_array = proto_get_finfo_ptr_array(tree, field_id);
145 if (finfo_array == NULL) {
146 return -1;
149 *element_count = g_ptr_array_len(finfo_array);
151 return 0;
155 * Editor modelines - https://www.wireshark.org/tools/modelines.html
157 * Local variables:
158 * c-basic-offset: 4
159 * tab-width: 8
160 * indent-tabs-mode: nil
161 * End:
163 * vi: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: