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
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
;
34 finfo_array
= proto_get_finfo_ptr_array(tree
, field_id
);
36 if (finfo_array
== NULL
) {
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
);
50 int extract_ui64(proto_tree
*tree
, int field_id
, uint64_t *result_array
, size_t *element_count
)
52 GPtrArray
*finfo_array
;
59 finfo_array
= proto_get_finfo_ptr_array(tree
, field_id
);
61 if (finfo_array
== NULL
) {
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
);
75 int extract_si64(proto_tree
*tree
, int field_id
, uint64_t *result_array
, size_t *element_count
)
77 GPtrArray
*finfo_array
;
84 finfo_array
= proto_get_finfo_ptr_array(tree
, field_id
);
86 if (finfo_array
== NULL
) {
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
);
100 int extract_bool(proto_tree
*tree
, int field_id
, bool *result_array
, size_t *element_count
)
102 GPtrArray
*finfo_array
;
109 finfo_array
= proto_get_finfo_ptr_array(tree
, field_id
);
111 if (finfo_array
== NULL
) {
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;
125 result_array
[i
] = false;
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
;
143 finfo_array
= proto_get_finfo_ptr_array(tree
, field_id
);
145 if (finfo_array
== NULL
) {
149 *element_count
= g_ptr_array_len(finfo_array
);
155 * Editor modelines - https://www.wireshark.org/tools/modelines.html
160 * indent-tabs-mode: nil
163 * vi: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: