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