Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ftypes.h
Go to the documentation of this file.
1
12#ifndef __FTYPES_H__
13#define __FTYPES_H__
14
15#include <wireshark.h>
16
17#include <wsutil/regex.h>
18#include <epan/wmem_scopes.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif /* __cplusplus */
23
24#define ASSERT_FTYPE_NOT_REACHED(ft) \
25 ws_error("Invalid field type '%s'.", ftype_name(ft))
26
27/* field types */
28enum ftenum {
29 FT_NONE, /* used for text labels with no value */
30 FT_PROTOCOL,
31 FT_BOOLEAN, /* true and false come from <glib.h> */
32 FT_CHAR, /* 1-octet character as 0-255 */
33 FT_UINT8,
34 FT_UINT16,
35 FT_UINT24, /* really a UINT32, but displayed as 6 hex-digits if FD_HEX*/
36 FT_UINT32,
37 FT_UINT40, /* really a UINT64, but displayed as 10 hex-digits if FD_HEX*/
38 FT_UINT48, /* really a UINT64, but displayed as 12 hex-digits if FD_HEX*/
39 FT_UINT56, /* really a UINT64, but displayed as 14 hex-digits if FD_HEX*/
40 FT_UINT64,
41 FT_INT8,
42 FT_INT16,
43 FT_INT24, /* same as for UINT24 */
44 FT_INT32,
45 FT_INT40, /* same as for UINT40 */
46 FT_INT48, /* same as for UINT48 */
47 FT_INT56, /* same as for UINT56 */
48 FT_INT64,
49 FT_IEEE_11073_SFLOAT,
50 FT_IEEE_11073_FLOAT,
51 FT_FLOAT,
52 FT_DOUBLE,
53 FT_ABSOLUTE_TIME,
54 FT_RELATIVE_TIME,
55 FT_STRING, /* counted string, with no null terminator */
56 FT_STRINGZ, /* null-terminated string */
57 FT_UINT_STRING, /* counted string, with count being the first part of the value */
58 FT_ETHER,
59 FT_BYTES,
60 FT_UINT_BYTES,
61 FT_IPv4,
62 FT_IPv6,
63 FT_IPXNET,
64 FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that number */
65 FT_GUID, /* GUID, UUID */
66 FT_OID, /* OBJECT IDENTIFIER */
67 FT_EUI64,
68 FT_AX25,
69 FT_VINES,
70 FT_REL_OID, /* RELATIVE-OID */
71 FT_SYSTEM_ID,
72 FT_STRINGZPAD, /* null-padded string */
73 FT_FCWWN,
74 FT_STRINGZTRUNC, /* null-truncated string */
75 FT_NUM_TYPES, /* last item number plus one */
76 FT_SCALAR, /* Pseudo-type used only internally for certain
77 * arithmetic operations. */
78 FT_ENUM_SIZE = FT_SCALAR /* Must be equal to last enumeration */
79};
80
81#define FT_IS_INT32(ft) \
82 ((ft) == FT_INT8 || \
83 (ft) == FT_INT16 || \
84 (ft) == FT_INT24 || \
85 (ft) == FT_INT32)
86
87#define FT_IS_INT64(ft) \
88 ((ft) == FT_INT40 || \
89 (ft) == FT_INT48 || \
90 (ft) == FT_INT56 || \
91 (ft) == FT_INT64)
92
93#define FT_IS_INT(ft) (FT_IS_INT32(ft) || FT_IS_INT64(ft))
94
95#define FT_IS_UINT32(ft) \
96 ((ft) == FT_CHAR || \
97 (ft) == FT_UINT8 || \
98 (ft) == FT_UINT16 || \
99 (ft) == FT_UINT24 || \
100 (ft) == FT_UINT32 || \
101 (ft) == FT_FRAMENUM)
102
103#define FT_IS_UINT64(ft) \
104 ((ft) == FT_UINT40 || \
105 (ft) == FT_UINT48 || \
106 (ft) == FT_UINT56 || \
107 (ft) == FT_UINT64)
108
109#define FT_IS_UINT(ft) (FT_IS_UINT32(ft) || FT_IS_UINT64(ft))
110
111#define FT_IS_INTEGER(ft) (FT_IS_INT(ft) || FT_IS_UINT(ft))
112
113#define FT_IS_FLOATING(ft) ((ft) == FT_FLOAT || (ft) == FT_DOUBLE)
114
115#define FT_IS_TIME(ft) \
116 ((ft) == FT_ABSOLUTE_TIME || (ft) == FT_RELATIVE_TIME)
117
118#define FT_IS_STRING(ft) \
119 ((ft) == FT_STRING || (ft) == FT_STRINGZ || (ft) == FT_STRINGZPAD || \
120 (ft) == FT_STRINGZTRUNC || (ft) == FT_UINT_STRING || (ft) == FT_AX25)
121
122#define FT_IS_SCALAR(ft) ((ft) == FT_INT64 || (ft) == FT_DOUBLE)
123
124/* field types lengths */
125#define FT_ETHER_LEN 6
126#define FT_GUID_LEN 16
127#define FT_IPv4_LEN 4
128#define FT_IPv6_LEN 16
129#define FT_IPXNET_LEN 4
130#define FT_EUI64_LEN 8
131#define FT_AX25_ADDR_LEN 7
132#define FT_VINES_ADDR_LEN 6
133#define FT_FCWWN_LEN 8
134#define FT_VARINT_MAX_LEN 10 /* Because 64 / 7 = 9 and 64 % 7 = 1, get an uint64 varint need reads up to 10 bytes. */
135
136typedef enum ftenum ftenum_t;
137
138enum ft_framenum_type {
139 FT_FRAMENUM_NONE,
140 FT_FRAMENUM_REQUEST,
141 FT_FRAMENUM_RESPONSE,
142 FT_FRAMENUM_ACK,
143 FT_FRAMENUM_DUP_ACK,
144 FT_FRAMENUM_RETRANS_PREV,
145 FT_FRAMENUM_RETRANS_NEXT,
146 FT_FRAMENUM_NUM_TYPES /* last item number plus one */
147};
148
149typedef enum ft_framenum_type ft_framenum_type_t;
150
151struct _ftype_t;
152typedef struct _ftype_t ftype_t;
153
154enum ft_result {
155 FT_OK = 0,
156 FT_OVERFLOW,
157 FT_UNDERFLOW,
158 FT_BADARG,
159 FT_ERROR, /* Generic. */
160};
161
162/*
163 * True, false or error if negative.
164 * Note that
165 * ft_bool == FT_FALSE
166 * and
167 * ft_bool != FT_TRUE
168 * are different results (three-state logic).
169 */
170typedef int ft_bool_t;
171#define FT_TRUE 1
172#define FT_FALSE 0
173
174/* String representation types. */
175enum ftrepr {
176 FTREPR_DISPLAY,
177 FTREPR_DFILTER,
178 FTREPR_JSON,
179 FTREPR_RAW,
180 FTREPR_EK, /* ElasticSearch/OpenSearch JSON */
181};
182
183typedef enum ftrepr ftrepr_t;
184
185/* Initialize the ftypes subsystem. Called once. */
186void
187ftypes_initialize(void);
188
189void
190ftypes_register_pseudofields(void);
191
192/* ---------------- FTYPE ----------------- */
193
194/* given two types, are they similar - for example can two
195 * duplicate fields be registered of these two types. */
196bool
197ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
198
199/* Return a string representing the name of the type */
200WS_DLL_PUBLIC
201const char*
202ftype_name(ftenum_t ftype);
203
204/* Return a string presenting a "pretty" representation of the
205 * name of the type. The pretty name means more to the user than
206 * that "FT_*" name. */
207WS_DLL_PUBLIC
208const char*
209ftype_pretty_name(ftenum_t ftype);
210
211/* Returns length of field in packet, or 0 if not determinable/defined. */
212WS_DLL_PUBLIC
213int
214ftype_wire_size(ftenum_t ftype);
215
216WS_DLL_PUBLIC
217bool
218ftype_can_length(enum ftenum ftype);
219
220WS_DLL_PUBLIC
221bool
222ftype_can_slice(enum ftenum ftype);
223
224WS_DLL_PUBLIC
225bool
226ftype_can_eq(enum ftenum ftype);
227
228WS_DLL_PUBLIC
229bool
230ftype_can_cmp(enum ftenum ftype);
231
232WS_DLL_PUBLIC
233bool
234ftype_can_bitwise_and(enum ftenum ftype);
235
236WS_DLL_PUBLIC
237bool
238ftype_can_unary_minus(enum ftenum ftype);
239
240WS_DLL_PUBLIC
241bool
242ftype_can_add(enum ftenum ftype);
243
244WS_DLL_PUBLIC
245bool
246ftype_can_subtract(enum ftenum ftype);
247
248WS_DLL_PUBLIC
249bool
250ftype_can_multiply(enum ftenum ftype);
251
252WS_DLL_PUBLIC
253bool
254ftype_can_divide(enum ftenum ftype);
255
256WS_DLL_PUBLIC
257bool
258ftype_can_modulo(enum ftenum ftype);
259
260WS_DLL_PUBLIC
261bool
262ftype_can_contains(enum ftenum ftype);
263
264WS_DLL_PUBLIC
265bool
266ftype_can_matches(enum ftenum ftype);
267
268WS_DLL_PUBLIC
269bool
270ftype_can_is_zero(enum ftenum ftype);
271
272WS_DLL_PUBLIC
273bool
274ftype_can_is_negative(enum ftenum ftype);
275
276WS_DLL_PUBLIC
277bool
278ftype_can_is_nan(enum ftenum ftype);
279
280WS_DLL_PUBLIC
281bool
282ftype_can_val_to_sinteger(enum ftenum ftype);
283
284WS_DLL_PUBLIC
285bool
286ftype_can_val_to_uinteger(enum ftenum ftype);
287
288WS_DLL_PUBLIC
289bool
290ftype_can_val_to_sinteger64(enum ftenum ftype);
291
292WS_DLL_PUBLIC
293bool
294ftype_can_val_to_uinteger64(enum ftenum ftype);
295
296WS_DLL_PUBLIC
297bool
298ftype_can_val_to_double(enum ftenum ftype);
299
300/* ---------------- FVALUE ----------------- */
301
302#include <wsutil/inet_cidr.h>
303#include <epan/guid-utils.h>
304
305#include <epan/tvbuff.h>
306#include <wsutil/nstime.h>
307#include <epan/dfilter/drange.h>
308
309typedef struct _protocol_value_t
310{
311 tvbuff_t *tvb;
312 int length;
313 char *proto_string;
314 bool tvb_is_private;
316
317typedef struct _fvalue_t fvalue_t;
318
319WS_DLL_PUBLIC
321fvalue_new(ftenum_t ftype);
322
323WS_DLL_PUBLIC
325fvalue_dup(const fvalue_t *fv);
326
327WS_DLL_PUBLIC
328void
329fvalue_init(fvalue_t *fv, ftenum_t ftype);
330
331WS_DLL_PUBLIC
332void
333fvalue_cleanup(fvalue_t *fv);
334
335WS_DLL_PUBLIC
336void
337fvalue_free(fvalue_t *fv);
338
339WS_DLL_PUBLIC
341fvalue_from_literal(ftenum_t ftype, const char *s, bool allow_partial_value, char **err_msg);
342
343/* String *MUST* be null-terminated. Length is optional (pass zero) and does not include the null terminator. */
345fvalue_from_string(ftenum_t ftype, const char *s, size_t len, char **err_msg);
346
348fvalue_from_charconst(ftenum_t ftype, unsigned long number, char **err_msg);
349
351fvalue_from_sinteger64(ftenum_t ftype, const char *s, int64_t number, char **err_msg);
352
354fvalue_from_uinteger64(ftenum_t ftype, const char *s, uint64_t number, char **err_msg);
355
357fvalue_from_floating(ftenum_t ftype, const char *s, double number, char **err_msg);
358
359/* Creates the string representation of the field value.
360 * Memory for the buffer is allocated based on wmem allocator
361 * provided.
362 *
363 * field_display parameter should be a BASE_ value (enum field_display_e)
364 * BASE_NONE should be used if field information isn't available.
365 *
366 * Returns NULL if the string cannot be represented in the given rtype.*/
367WS_DLL_PUBLIC char *
368fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display);
369
370#define fvalue_to_debug_repr(scope, fv) \
371 fvalue_to_string_repr(scope, fv, FTREPR_DFILTER, 0)
372
373WS_DLL_PUBLIC enum ft_result
374fvalue_to_uinteger(const fvalue_t *fv, uint32_t *repr);
375
376WS_DLL_PUBLIC enum ft_result
377fvalue_to_sinteger(const fvalue_t *fv, int32_t *repr);
378
379WS_DLL_PUBLIC enum ft_result
380fvalue_to_uinteger64(const fvalue_t *fv, uint64_t *repr);
381
382WS_DLL_PUBLIC enum ft_result
383fvalue_to_sinteger64(const fvalue_t *fv, int64_t *repr);
384
385WS_DLL_PUBLIC enum ft_result
386fvalue_to_double(const fvalue_t *fv, double *repr);
387
388WS_DLL_PUBLIC ftenum_t
389fvalue_type_ftenum(const fvalue_t *fv);
390
391WS_DLL_PUBLIC
392const char*
393fvalue_type_name(const fvalue_t *fv);
394
395/* GBytes reference count is automatically incremented. */
396WS_DLL_PUBLIC
397void
398fvalue_set_bytes(fvalue_t *fv, GBytes *value);
399
400WS_DLL_PUBLIC
401void
402fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
403
404WS_DLL_PUBLIC
405void
406fvalue_set_bytes_data(fvalue_t *fv, const void *data, size_t size);
407
408WS_DLL_PUBLIC
409void
410fvalue_set_fcwwn(fvalue_t *fv, const uint8_t *value);
411
412WS_DLL_PUBLIC
413void
414fvalue_set_ax25(fvalue_t *fv, const uint8_t *value);
415
416WS_DLL_PUBLIC
417void
418fvalue_set_vines(fvalue_t *fv, const uint8_t *value);
419
420WS_DLL_PUBLIC
421void
422fvalue_set_ether(fvalue_t *fv, const uint8_t *value);
423
424WS_DLL_PUBLIC
425void
426fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
427
428WS_DLL_PUBLIC
429void
430fvalue_set_time(fvalue_t *fv, const nstime_t *value);
431
432WS_DLL_PUBLIC
433void
434fvalue_set_string(fvalue_t *fv, const char *value);
435
436WS_DLL_PUBLIC
437void
438fvalue_set_strbuf(fvalue_t *fv, wmem_strbuf_t *value);
439
440WS_DLL_PUBLIC
441void
442fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const char *name, int length);
443
444WS_DLL_PUBLIC
445void
446fvalue_set_protocol_length(fvalue_t *fv, int length);
447
448WS_DLL_PUBLIC
449void
450fvalue_set_uinteger(fvalue_t *fv, uint32_t value);
451
452WS_DLL_PUBLIC
453void
454fvalue_set_sinteger(fvalue_t *fv, int32_t value);
455
456WS_DLL_PUBLIC
457void
458fvalue_set_uinteger64(fvalue_t *fv, uint64_t value);
459
460WS_DLL_PUBLIC
461void
462fvalue_set_sinteger64(fvalue_t *fv, int64_t value);
463
464WS_DLL_PUBLIC
465void
466fvalue_set_floating(fvalue_t *fv, double value);
467
468WS_DLL_PUBLIC
469void
470fvalue_set_ipv4(fvalue_t *fv, const ipv4_addr_and_mask *value);
471
472WS_DLL_PUBLIC
473void
474fvalue_set_ipv6(fvalue_t *fv, const ipv6_addr_and_prefix *value);
475
476/* GBytes reference count is automatically incremented. */
477WS_DLL_PUBLIC
478GBytes *
479fvalue_get_bytes(fvalue_t *fv);
480
481WS_DLL_PUBLIC
482size_t
483fvalue_get_bytes_size(fvalue_t *fv);
484
485/* Same as fvalue_length() */
486WS_DLL_PUBLIC
487const void *
488fvalue_get_bytes_data(fvalue_t *fv);
489
490WS_DLL_PUBLIC
491const e_guid_t *
492fvalue_get_guid(fvalue_t *fv);
493
494WS_DLL_PUBLIC
495const nstime_t *
496fvalue_get_time(fvalue_t *fv);
497
498WS_DLL_PUBLIC
499const char *
500fvalue_get_string(fvalue_t *fv);
501
502WS_DLL_PUBLIC
503const wmem_strbuf_t *
504fvalue_get_strbuf(fvalue_t *fv);
505
506WS_DLL_PUBLIC
507tvbuff_t *
508fvalue_get_protocol(fvalue_t *fv);
509
510WS_DLL_PUBLIC
511uint32_t
512fvalue_get_uinteger(fvalue_t *fv);
513
514WS_DLL_PUBLIC
515int32_t
516fvalue_get_sinteger(fvalue_t *fv);
517
518WS_DLL_PUBLIC
519uint64_t
520fvalue_get_uinteger64(fvalue_t *fv);
521
522WS_DLL_PUBLIC
523int64_t
524fvalue_get_sinteger64(fvalue_t *fv);
525
526WS_DLL_PUBLIC
527double
528fvalue_get_floating(fvalue_t *fv);
529
530WS_DLL_PUBLIC
531const ipv4_addr_and_mask *
532fvalue_get_ipv4(fvalue_t *fv);
533
534WS_DLL_PUBLIC
536fvalue_get_ipv6(fvalue_t *fv);
537
538WS_DLL_PUBLIC
539ft_bool_t
540fvalue_eq(const fvalue_t *a, const fvalue_t *b);
541
542WS_DLL_PUBLIC
543ft_bool_t
544fvalue_ne(const fvalue_t *a, const fvalue_t *b);
545
546WS_DLL_PUBLIC
547ft_bool_t
548fvalue_gt(const fvalue_t *a, const fvalue_t *b);
549
550WS_DLL_PUBLIC
551ft_bool_t
552fvalue_ge(const fvalue_t *a, const fvalue_t *b);
553
554WS_DLL_PUBLIC
555ft_bool_t
556fvalue_lt(const fvalue_t *a, const fvalue_t *b);
557
558WS_DLL_PUBLIC
559ft_bool_t
560fvalue_le(const fvalue_t *a, const fvalue_t *b);
561
562WS_DLL_PUBLIC
563ft_bool_t
564fvalue_contains(const fvalue_t *a, const fvalue_t *b);
565
566WS_DLL_PUBLIC
567ft_bool_t
568fvalue_matches(const fvalue_t *a, const ws_regex_t *re);
569
570WS_DLL_PUBLIC
571bool
572fvalue_is_zero(const fvalue_t *a);
573
574WS_DLL_PUBLIC
575bool
576fvalue_is_negative(const fvalue_t *a);
577
578WS_DLL_PUBLIC
579bool
580fvalue_is_nan(const fvalue_t *a);
581
582WS_DLL_PUBLIC
583size_t
584fvalue_length2(fvalue_t *fv);
585
586WS_DLL_PUBLIC
588fvalue_slice(fvalue_t *fv, drange_t *dr);
589
590WS_DLL_PUBLIC
592fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b, char **err_msg);
593
594WS_DLL_PUBLIC
596fvalue_unary_minus(const fvalue_t *fv, char **err_msg);
597
598WS_DLL_PUBLIC
600fvalue_add(const fvalue_t *a, const fvalue_t *b, char **err_msg);
601
602WS_DLL_PUBLIC
604fvalue_subtract(const fvalue_t *a, const fvalue_t *b, char **err_msg);
605
606WS_DLL_PUBLIC
608fvalue_multiply(const fvalue_t *a, const fvalue_t *b, char **err_msg);
609
610WS_DLL_PUBLIC
612fvalue_divide(const fvalue_t *a, const fvalue_t *b, char **err_msg);
613
614WS_DLL_PUBLIC
616fvalue_modulo(const fvalue_t *a, const fvalue_t *b, char **err_msg);
617
618WS_DLL_PUBLIC
619unsigned
620fvalue_hash(const fvalue_t *fv);
621
622WS_DLL_PUBLIC
623bool
624fvalue_equal(const fvalue_t *a, const fvalue_t *b);
625
626#ifdef __cplusplus
627}
628#endif /* __cplusplus */
629
630#endif /* __FTYPES_H__ */
631
632/*
633 * Editor modelines - https://www.wireshark.org/tools/modelines.html
634 *
635 * Local variables:
636 * c-basic-offset: 8
637 * tab-width: 8
638 * indent-tabs-mode: t
639 * End:
640 *
641 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
642 * :indentSize=8:tabSize=8:noTabs=false:
643 */
Definition drange.h:40
Definition guid-utils.h:23
Describes a field type and its associated operations for display filtering.
Definition ftypes-int.h:112
ftenum_t ftype
Definition ftypes-int.h:113
Represents a typed field value used in protocol dissection.
Definition ftypes-int.h:24
const ftype_t * ftype
Definition ftypes-int.h:25
union _fvalue_t::@479 value
Definition ftypes.h:310
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Internal structure representing a wmem-allocated string buffer.
Definition wmem_strbuf.h:38
Definition regex.c:17
Definition inet_cidr.h:22
Definition inet_cidr.h:27
Definition nstime.h:26
Definition tvbuff-int.h:35