Wireshark 4.5.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};
181
182typedef enum ftrepr ftrepr_t;
183
184/* Initialize the ftypes subsystem. Called once. */
185void
186ftypes_initialize(void);
187
188void
189ftypes_register_pseudofields(void);
190
191/* ---------------- FTYPE ----------------- */
192
193/* given two types, are they similar - for example can two
194 * duplicate fields be registered of these two types. */
195bool
196ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
197
198/* Return a string representing the name of the type */
199WS_DLL_PUBLIC
200const char*
201ftype_name(ftenum_t ftype);
202
203/* Return a string presenting a "pretty" representation of the
204 * name of the type. The pretty name means more to the user than
205 * that "FT_*" name. */
206WS_DLL_PUBLIC
207const char*
208ftype_pretty_name(ftenum_t ftype);
209
210/* Returns length of field in packet, or 0 if not determinable/defined. */
211int
212ftype_wire_size(ftenum_t ftype);
213
214WS_DLL_PUBLIC
215bool
216ftype_can_length(enum ftenum ftype);
217
218WS_DLL_PUBLIC
219bool
220ftype_can_slice(enum ftenum ftype);
221
222WS_DLL_PUBLIC
223bool
224ftype_can_eq(enum ftenum ftype);
225
226WS_DLL_PUBLIC
227bool
228ftype_can_cmp(enum ftenum ftype);
229
230WS_DLL_PUBLIC
231bool
232ftype_can_bitwise_and(enum ftenum ftype);
233
234WS_DLL_PUBLIC
235bool
236ftype_can_unary_minus(enum ftenum ftype);
237
238WS_DLL_PUBLIC
239bool
240ftype_can_add(enum ftenum ftype);
241
242WS_DLL_PUBLIC
243bool
244ftype_can_subtract(enum ftenum ftype);
245
246WS_DLL_PUBLIC
247bool
248ftype_can_multiply(enum ftenum ftype);
249
250WS_DLL_PUBLIC
251bool
252ftype_can_divide(enum ftenum ftype);
253
254WS_DLL_PUBLIC
255bool
256ftype_can_modulo(enum ftenum ftype);
257
258WS_DLL_PUBLIC
259bool
260ftype_can_contains(enum ftenum ftype);
261
262WS_DLL_PUBLIC
263bool
264ftype_can_matches(enum ftenum ftype);
265
266WS_DLL_PUBLIC
267bool
268ftype_can_is_zero(enum ftenum ftype);
269
270WS_DLL_PUBLIC
271bool
272ftype_can_is_negative(enum ftenum ftype);
273
274WS_DLL_PUBLIC
275bool
276ftype_can_val_to_sinteger(enum ftenum ftype);
277
278WS_DLL_PUBLIC
279bool
280ftype_can_val_to_uinteger(enum ftenum ftype);
281
282WS_DLL_PUBLIC
283bool
284ftype_can_val_to_sinteger64(enum ftenum ftype);
285
286WS_DLL_PUBLIC
287bool
288ftype_can_val_to_uinteger64(enum ftenum ftype);
289
290WS_DLL_PUBLIC
291bool
292ftype_can_val_to_double(enum ftenum ftype);
293
294/* ---------------- FVALUE ----------------- */
295
296#include <wsutil/inet_cidr.h>
297#include <epan/guid-utils.h>
298
299#include <epan/tvbuff.h>
300#include <wsutil/nstime.h>
301#include <epan/dfilter/drange.h>
302
303typedef struct _protocol_value_t
304{
305 tvbuff_t *tvb;
306 int length;
307 char *proto_string;
308 bool tvb_is_private;
310
311typedef struct _fvalue_t fvalue_t;
312
313WS_DLL_PUBLIC
315fvalue_new(ftenum_t ftype);
316
317WS_DLL_PUBLIC
319fvalue_dup(const fvalue_t *fv);
320
321WS_DLL_PUBLIC
322void
323fvalue_init(fvalue_t *fv, ftenum_t ftype);
324
325WS_DLL_PUBLIC
326void
327fvalue_cleanup(fvalue_t *fv);
328
329WS_DLL_PUBLIC
330void
331fvalue_free(fvalue_t *fv);
332
333WS_DLL_PUBLIC
335fvalue_from_literal(ftenum_t ftype, const char *s, bool allow_partial_value, char **err_msg);
336
337/* String *MUST* be null-terminated. Length is optional (pass zero) and does not include the null terminator. */
339fvalue_from_string(ftenum_t ftype, const char *s, size_t len, char **err_msg);
340
342fvalue_from_charconst(ftenum_t ftype, unsigned long number, char **err_msg);
343
345fvalue_from_sinteger64(ftenum_t ftype, const char *s, int64_t number, char **err_msg);
346
348fvalue_from_uinteger64(ftenum_t ftype, const char *s, uint64_t number, char **err_msg);
349
351fvalue_from_floating(ftenum_t ftype, const char *s, double number, char **err_msg);
352
353/* Creates the string representation of the field value.
354 * Memory for the buffer is allocated based on wmem allocator
355 * provided.
356 *
357 * field_display parameter should be a BASE_ value (enum field_display_e)
358 * BASE_NONE should be used if field information isn't available.
359 *
360 * Returns NULL if the string cannot be represented in the given rtype.*/
361WS_DLL_PUBLIC char *
362fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display);
363
364#define fvalue_to_debug_repr(scope, fv) \
365 fvalue_to_string_repr(scope, fv, FTREPR_DFILTER, 0)
366
367WS_DLL_PUBLIC enum ft_result
368fvalue_to_uinteger(const fvalue_t *fv, uint32_t *repr);
369
370WS_DLL_PUBLIC enum ft_result
371fvalue_to_sinteger(const fvalue_t *fv, int32_t *repr);
372
373WS_DLL_PUBLIC enum ft_result
374fvalue_to_uinteger64(const fvalue_t *fv, uint64_t *repr);
375
376WS_DLL_PUBLIC enum ft_result
377fvalue_to_sinteger64(const fvalue_t *fv, int64_t *repr);
378
379WS_DLL_PUBLIC enum ft_result
380fvalue_to_double(const fvalue_t *fv, double *repr);
381
382WS_DLL_PUBLIC ftenum_t
383fvalue_type_ftenum(const fvalue_t *fv);
384
385WS_DLL_PUBLIC
386const char*
387fvalue_type_name(const fvalue_t *fv);
388
389/* GBytes reference count is automatically incremented. */
390WS_DLL_PUBLIC
391void
392fvalue_set_bytes(fvalue_t *fv, GBytes *value);
393
394WS_DLL_PUBLIC
395void
396fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
397
398WS_DLL_PUBLIC
399void
400fvalue_set_bytes_data(fvalue_t *fv, const void *data, size_t size);
401
402WS_DLL_PUBLIC
403void
404fvalue_set_fcwwn(fvalue_t *fv, const uint8_t *value);
405
406WS_DLL_PUBLIC
407void
408fvalue_set_ax25(fvalue_t *fv, const uint8_t *value);
409
410WS_DLL_PUBLIC
411void
412fvalue_set_vines(fvalue_t *fv, const uint8_t *value);
413
414WS_DLL_PUBLIC
415void
416fvalue_set_ether(fvalue_t *fv, const uint8_t *value);
417
418WS_DLL_PUBLIC
419void
420fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
421
422WS_DLL_PUBLIC
423void
424fvalue_set_time(fvalue_t *fv, const nstime_t *value);
425
426WS_DLL_PUBLIC
427void
428fvalue_set_string(fvalue_t *fv, const char *value);
429
430WS_DLL_PUBLIC
431void
432fvalue_set_strbuf(fvalue_t *fv, wmem_strbuf_t *value);
433
434WS_DLL_PUBLIC
435void
436fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const char *name, int length);
437
438WS_DLL_PUBLIC
439void
440fvalue_set_protocol_length(fvalue_t *fv, int length);
441
442WS_DLL_PUBLIC
443void
444fvalue_set_uinteger(fvalue_t *fv, uint32_t value);
445
446WS_DLL_PUBLIC
447void
448fvalue_set_sinteger(fvalue_t *fv, int32_t value);
449
450WS_DLL_PUBLIC
451void
452fvalue_set_uinteger64(fvalue_t *fv, uint64_t value);
453
454WS_DLL_PUBLIC
455void
456fvalue_set_sinteger64(fvalue_t *fv, int64_t value);
457
458WS_DLL_PUBLIC
459void
460fvalue_set_floating(fvalue_t *fv, double value);
461
462WS_DLL_PUBLIC
463void
464fvalue_set_ipv4(fvalue_t *fv, const ipv4_addr_and_mask *value);
465
466WS_DLL_PUBLIC
467void
468fvalue_set_ipv6(fvalue_t *fv, const ipv6_addr_and_prefix *value);
469
470/* GBytes reference count is automatically incremented. */
471WS_DLL_PUBLIC
472GBytes *
473fvalue_get_bytes(fvalue_t *fv);
474
475WS_DLL_PUBLIC
476size_t
477fvalue_get_bytes_size(fvalue_t *fv);
478
479/* Same as fvalue_length() */
480WS_DLL_PUBLIC
481const void *
482fvalue_get_bytes_data(fvalue_t *fv);
483
484WS_DLL_PUBLIC
485const e_guid_t *
486fvalue_get_guid(fvalue_t *fv);
487
488WS_DLL_PUBLIC
489const nstime_t *
490fvalue_get_time(fvalue_t *fv);
491
492WS_DLL_PUBLIC
493const char *
494fvalue_get_string(fvalue_t *fv);
495
496WS_DLL_PUBLIC
497const wmem_strbuf_t *
498fvalue_get_strbuf(fvalue_t *fv);
499
500WS_DLL_PUBLIC
501tvbuff_t *
502fvalue_get_protocol(fvalue_t *fv);
503
504WS_DLL_PUBLIC
505uint32_t
506fvalue_get_uinteger(fvalue_t *fv);
507
508WS_DLL_PUBLIC
509int32_t
510fvalue_get_sinteger(fvalue_t *fv);
511
512WS_DLL_PUBLIC
513uint64_t
514fvalue_get_uinteger64(fvalue_t *fv);
515
516WS_DLL_PUBLIC
517int64_t
518fvalue_get_sinteger64(fvalue_t *fv);
519
520WS_DLL_PUBLIC
521double
522fvalue_get_floating(fvalue_t *fv);
523
524WS_DLL_PUBLIC
525const ipv4_addr_and_mask *
526fvalue_get_ipv4(fvalue_t *fv);
527
528WS_DLL_PUBLIC
530fvalue_get_ipv6(fvalue_t *fv);
531
532WS_DLL_PUBLIC
533ft_bool_t
534fvalue_eq(const fvalue_t *a, const fvalue_t *b);
535
536WS_DLL_PUBLIC
537ft_bool_t
538fvalue_ne(const fvalue_t *a, const fvalue_t *b);
539
540WS_DLL_PUBLIC
541ft_bool_t
542fvalue_gt(const fvalue_t *a, const fvalue_t *b);
543
544WS_DLL_PUBLIC
545ft_bool_t
546fvalue_ge(const fvalue_t *a, const fvalue_t *b);
547
548WS_DLL_PUBLIC
549ft_bool_t
550fvalue_lt(const fvalue_t *a, const fvalue_t *b);
551
552WS_DLL_PUBLIC
553ft_bool_t
554fvalue_le(const fvalue_t *a, const fvalue_t *b);
555
556WS_DLL_PUBLIC
557ft_bool_t
558fvalue_contains(const fvalue_t *a, const fvalue_t *b);
559
560WS_DLL_PUBLIC
561ft_bool_t
562fvalue_matches(const fvalue_t *a, const ws_regex_t *re);
563
564WS_DLL_PUBLIC
565ft_bool_t
566fvalue_is_zero(const fvalue_t *a);
567
568WS_DLL_PUBLIC
569ft_bool_t
570fvalue_is_negative(const fvalue_t *a);
571
572WS_DLL_PUBLIC
573size_t
574fvalue_length2(fvalue_t *fv);
575
576WS_DLL_PUBLIC
578fvalue_slice(fvalue_t *fv, drange_t *dr);
579
580WS_DLL_PUBLIC
582fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b, char **err_msg);
583
584WS_DLL_PUBLIC
586fvalue_unary_minus(const fvalue_t *fv, char **err_msg);
587
588WS_DLL_PUBLIC
590fvalue_add(const fvalue_t *a, const fvalue_t *b, char **err_msg);
591
592WS_DLL_PUBLIC
594fvalue_subtract(const fvalue_t *a, const fvalue_t *b, char **err_msg);
595
596WS_DLL_PUBLIC
598fvalue_multiply(const fvalue_t *a, const fvalue_t *b, char **err_msg);
599
600WS_DLL_PUBLIC
602fvalue_divide(const fvalue_t *a, const fvalue_t *b, char **err_msg);
603
604WS_DLL_PUBLIC
606fvalue_modulo(const fvalue_t *a, const fvalue_t *b, char **err_msg);
607
608WS_DLL_PUBLIC
609unsigned
610fvalue_hash(const fvalue_t *fv);
611
612WS_DLL_PUBLIC
613bool
614fvalue_equal(const fvalue_t *a, const fvalue_t *b);
615
616#ifdef __cplusplus
617}
618#endif /* __cplusplus */
619
620#endif /* __FTYPES_H__ */
621
622/*
623 * Editor modelines - https://www.wireshark.org/tools/modelines.html
624 *
625 * Local variables:
626 * c-basic-offset: 8
627 * tab-width: 8
628 * indent-tabs-mode: t
629 * End:
630 *
631 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
632 * :indentSize=8:tabSize=8:noTabs=false:
633 */
Definition drange.h:40
Definition guid-utils.h:23
Definition ftypes-int.h:98
Definition ftypes-int.h:17
Definition ftypes.h:304
Definition wmem_allocator.h:27
Definition wmem_strbuf.h:42
Definition regex.c:17
Definition inet_cidr.h:22
Definition inet_cidr.h:27
Definition nstime.h:26
Definition tvbuff-int.h:35