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