regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / epan / ftypes / ftypes.h
blob0e119eac8c29f68807a03e7a704687244f592734
1 /** @file
2 * Definitions for field types
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2001 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
12 #ifndef __FTYPES_H__
13 #define __FTYPES_H__
15 #include <wireshark.h>
17 #include <wsutil/regex.h>
18 #include <epan/wmem_scopes.h>
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
24 #define ASSERT_FTYPE_NOT_REACHED(ft) \
25 ws_error("Invalid field type '%s'.", ftype_name(ft))
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 FT_ENUM_SIZE = FT_SCALAR /* Must be equal to last enumeration */
81 #define FT_IS_INT32(ft) \
82 ((ft) == FT_INT8 || \
83 (ft) == FT_INT16 || \
84 (ft) == FT_INT24 || \
85 (ft) == FT_INT32)
87 #define FT_IS_INT64(ft) \
88 ((ft) == FT_INT40 || \
89 (ft) == FT_INT48 || \
90 (ft) == FT_INT56 || \
91 (ft) == FT_INT64)
93 #define FT_IS_INT(ft) (FT_IS_INT32(ft) || FT_IS_INT64(ft))
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)
103 #define FT_IS_UINT64(ft) \
104 ((ft) == FT_UINT40 || \
105 (ft) == FT_UINT48 || \
106 (ft) == FT_UINT56 || \
107 (ft) == FT_UINT64)
109 #define FT_IS_UINT(ft) (FT_IS_UINT32(ft) || FT_IS_UINT64(ft))
111 #define FT_IS_INTEGER(ft) (FT_IS_INT(ft) || FT_IS_UINT(ft))
113 #define FT_IS_FLOATING(ft) ((ft) == FT_FLOAT || (ft) == FT_DOUBLE)
115 #define FT_IS_TIME(ft) \
116 ((ft) == FT_ABSOLUTE_TIME || (ft) == FT_RELATIVE_TIME)
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)
122 #define FT_IS_SCALAR(ft) ((ft) == FT_INT64 || (ft) == FT_DOUBLE)
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. */
136 typedef enum ftenum ftenum_t;
138 enum 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 */
149 typedef enum ft_framenum_type ft_framenum_type_t;
151 struct _ftype_t;
152 typedef struct _ftype_t ftype_t;
154 enum ft_result {
155 FT_OK = 0,
156 FT_OVERFLOW,
157 FT_UNDERFLOW,
158 FT_BADARG,
159 FT_ERROR, /* Generic. */
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).
170 typedef int ft_bool_t;
171 #define FT_TRUE 1
172 #define FT_FALSE 0
174 /* String representation types. */
175 enum ftrepr {
176 FTREPR_DISPLAY,
177 FTREPR_DFILTER,
178 FTREPR_JSON,
179 FTREPR_RAW,
182 typedef enum ftrepr ftrepr_t;
184 /* Initialize the ftypes subsystem. Called once. */
185 void
186 ftypes_initialize(void);
188 void
189 ftypes_register_pseudofields(void);
191 /* ---------------- FTYPE ----------------- */
193 /* given two types, are they similar - for example can two
194 * duplicate fields be registered of these two types. */
195 bool
196 ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
198 /* Return a string representing the name of the type */
199 WS_DLL_PUBLIC
200 const char*
201 ftype_name(ftenum_t ftype);
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. */
206 WS_DLL_PUBLIC
207 const char*
208 ftype_pretty_name(ftenum_t ftype);
210 /* Returns length of field in packet, or 0 if not determinable/defined. */
212 ftype_wire_size(ftenum_t ftype);
214 WS_DLL_PUBLIC
215 bool
216 ftype_can_length(enum ftenum ftype);
218 WS_DLL_PUBLIC
219 bool
220 ftype_can_slice(enum ftenum ftype);
222 WS_DLL_PUBLIC
223 bool
224 ftype_can_eq(enum ftenum ftype);
226 WS_DLL_PUBLIC
227 bool
228 ftype_can_cmp(enum ftenum ftype);
230 WS_DLL_PUBLIC
231 bool
232 ftype_can_bitwise_and(enum ftenum ftype);
234 WS_DLL_PUBLIC
235 bool
236 ftype_can_unary_minus(enum ftenum ftype);
238 WS_DLL_PUBLIC
239 bool
240 ftype_can_add(enum ftenum ftype);
242 WS_DLL_PUBLIC
243 bool
244 ftype_can_subtract(enum ftenum ftype);
246 WS_DLL_PUBLIC
247 bool
248 ftype_can_multiply(enum ftenum ftype);
250 WS_DLL_PUBLIC
251 bool
252 ftype_can_divide(enum ftenum ftype);
254 WS_DLL_PUBLIC
255 bool
256 ftype_can_modulo(enum ftenum ftype);
258 WS_DLL_PUBLIC
259 bool
260 ftype_can_contains(enum ftenum ftype);
262 WS_DLL_PUBLIC
263 bool
264 ftype_can_matches(enum ftenum ftype);
266 WS_DLL_PUBLIC
267 bool
268 ftype_can_is_zero(enum ftenum ftype);
270 WS_DLL_PUBLIC
271 bool
272 ftype_can_is_negative(enum ftenum ftype);
274 WS_DLL_PUBLIC
275 bool
276 ftype_can_val_to_sinteger(enum ftenum ftype);
278 WS_DLL_PUBLIC
279 bool
280 ftype_can_val_to_uinteger(enum ftenum ftype);
282 WS_DLL_PUBLIC
283 bool
284 ftype_can_val_to_sinteger64(enum ftenum ftype);
286 WS_DLL_PUBLIC
287 bool
288 ftype_can_val_to_uinteger64(enum ftenum ftype);
290 WS_DLL_PUBLIC
291 bool
292 ftype_can_val_to_double(enum ftenum ftype);
294 /* ---------------- FVALUE ----------------- */
296 #include <wsutil/inet_cidr.h>
297 #include <epan/guid-utils.h>
299 #include <epan/tvbuff.h>
300 #include <wsutil/nstime.h>
301 #include <epan/dfilter/drange.h>
303 typedef struct _protocol_value_t
305 tvbuff_t *tvb;
306 int length;
307 char *proto_string;
308 bool tvb_is_private;
309 } protocol_value_t;
311 typedef struct _fvalue_t fvalue_t;
313 WS_DLL_PUBLIC
314 fvalue_t*
315 fvalue_new(ftenum_t ftype);
317 WS_DLL_PUBLIC
318 fvalue_t*
319 fvalue_dup(const fvalue_t *fv);
321 WS_DLL_PUBLIC
322 void
323 fvalue_init(fvalue_t *fv, ftenum_t ftype);
325 WS_DLL_PUBLIC
326 void
327 fvalue_cleanup(fvalue_t *fv);
329 WS_DLL_PUBLIC
330 void
331 fvalue_free(fvalue_t *fv);
333 WS_DLL_PUBLIC
334 fvalue_t*
335 fvalue_from_literal(ftenum_t ftype, const char *s, bool allow_partial_value, char **err_msg);
337 /* String *MUST* be null-terminated. Length is optional (pass zero) and does not include the null terminator. */
338 fvalue_t*
339 fvalue_from_string(ftenum_t ftype, const char *s, size_t len, char **err_msg);
341 fvalue_t*
342 fvalue_from_charconst(ftenum_t ftype, unsigned long number, char **err_msg);
344 fvalue_t*
345 fvalue_from_sinteger64(ftenum_t ftype, const char *s, int64_t number, char **err_msg);
347 fvalue_t*
348 fvalue_from_uinteger64(ftenum_t ftype, const char *s, uint64_t number, char **err_msg);
350 fvalue_t*
351 fvalue_from_floating(ftenum_t ftype, const char *s, double number, char **err_msg);
353 /* Creates the string representation of the field value.
354 * Memory for the buffer is allocated based on wmem allocator
355 * provided.
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.
360 * Returns NULL if the string cannot be represented in the given rtype.*/
361 WS_DLL_PUBLIC char *
362 fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display);
364 #define fvalue_to_debug_repr(scope, fv) \
365 fvalue_to_string_repr(scope, fv, FTREPR_DFILTER, 0)
367 WS_DLL_PUBLIC enum ft_result
368 fvalue_to_uinteger(const fvalue_t *fv, uint32_t *repr);
370 WS_DLL_PUBLIC enum ft_result
371 fvalue_to_sinteger(const fvalue_t *fv, int32_t *repr);
373 WS_DLL_PUBLIC enum ft_result
374 fvalue_to_uinteger64(const fvalue_t *fv, uint64_t *repr);
376 WS_DLL_PUBLIC enum ft_result
377 fvalue_to_sinteger64(const fvalue_t *fv, int64_t *repr);
379 WS_DLL_PUBLIC enum ft_result
380 fvalue_to_double(const fvalue_t *fv, double *repr);
382 WS_DLL_PUBLIC ftenum_t
383 fvalue_type_ftenum(const fvalue_t *fv);
385 WS_DLL_PUBLIC
386 const char*
387 fvalue_type_name(const fvalue_t *fv);
389 /* GBytes reference count is automatically incremented. */
390 WS_DLL_PUBLIC
391 void
392 fvalue_set_bytes(fvalue_t *fv, GBytes *value);
394 WS_DLL_PUBLIC
395 void
396 fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
398 WS_DLL_PUBLIC
399 void
400 fvalue_set_bytes_data(fvalue_t *fv, const void *data, size_t size);
402 WS_DLL_PUBLIC
403 void
404 fvalue_set_fcwwn(fvalue_t *fv, const uint8_t *value);
406 WS_DLL_PUBLIC
407 void
408 fvalue_set_ax25(fvalue_t *fv, const uint8_t *value);
410 WS_DLL_PUBLIC
411 void
412 fvalue_set_vines(fvalue_t *fv, const uint8_t *value);
414 WS_DLL_PUBLIC
415 void
416 fvalue_set_ether(fvalue_t *fv, const uint8_t *value);
418 WS_DLL_PUBLIC
419 void
420 fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
422 WS_DLL_PUBLIC
423 void
424 fvalue_set_time(fvalue_t *fv, const nstime_t *value);
426 WS_DLL_PUBLIC
427 void
428 fvalue_set_string(fvalue_t *fv, const char *value);
430 WS_DLL_PUBLIC
431 void
432 fvalue_set_strbuf(fvalue_t *fv, wmem_strbuf_t *value);
434 WS_DLL_PUBLIC
435 void
436 fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const char *name, int length);
438 WS_DLL_PUBLIC
439 void
440 fvalue_set_protocol_length(fvalue_t *fv, int length);
442 WS_DLL_PUBLIC
443 void
444 fvalue_set_uinteger(fvalue_t *fv, uint32_t value);
446 WS_DLL_PUBLIC
447 void
448 fvalue_set_sinteger(fvalue_t *fv, int32_t value);
450 WS_DLL_PUBLIC
451 void
452 fvalue_set_uinteger64(fvalue_t *fv, uint64_t value);
454 WS_DLL_PUBLIC
455 void
456 fvalue_set_sinteger64(fvalue_t *fv, int64_t value);
458 WS_DLL_PUBLIC
459 void
460 fvalue_set_floating(fvalue_t *fv, double value);
462 WS_DLL_PUBLIC
463 void
464 fvalue_set_ipv4(fvalue_t *fv, const ipv4_addr_and_mask *value);
466 WS_DLL_PUBLIC
467 void
468 fvalue_set_ipv6(fvalue_t *fv, const ipv6_addr_and_prefix *value);
470 /* GBytes reference count is automatically incremented. */
471 WS_DLL_PUBLIC
472 GBytes *
473 fvalue_get_bytes(fvalue_t *fv);
475 WS_DLL_PUBLIC
476 size_t
477 fvalue_get_bytes_size(fvalue_t *fv);
479 /* Same as fvalue_length() */
480 WS_DLL_PUBLIC
481 const void *
482 fvalue_get_bytes_data(fvalue_t *fv);
484 WS_DLL_PUBLIC
485 const e_guid_t *
486 fvalue_get_guid(fvalue_t *fv);
488 WS_DLL_PUBLIC
489 const nstime_t *
490 fvalue_get_time(fvalue_t *fv);
492 WS_DLL_PUBLIC
493 const char *
494 fvalue_get_string(fvalue_t *fv);
496 WS_DLL_PUBLIC
497 const wmem_strbuf_t *
498 fvalue_get_strbuf(fvalue_t *fv);
500 WS_DLL_PUBLIC
501 tvbuff_t *
502 fvalue_get_protocol(fvalue_t *fv);
504 WS_DLL_PUBLIC
505 uint32_t
506 fvalue_get_uinteger(fvalue_t *fv);
508 WS_DLL_PUBLIC
509 int32_t
510 fvalue_get_sinteger(fvalue_t *fv);
512 WS_DLL_PUBLIC
513 uint64_t
514 fvalue_get_uinteger64(fvalue_t *fv);
516 WS_DLL_PUBLIC
517 int64_t
518 fvalue_get_sinteger64(fvalue_t *fv);
520 WS_DLL_PUBLIC
521 double
522 fvalue_get_floating(fvalue_t *fv);
524 WS_DLL_PUBLIC
525 const ipv4_addr_and_mask *
526 fvalue_get_ipv4(fvalue_t *fv);
528 WS_DLL_PUBLIC
529 const ipv6_addr_and_prefix *
530 fvalue_get_ipv6(fvalue_t *fv);
532 WS_DLL_PUBLIC
533 ft_bool_t
534 fvalue_eq(const fvalue_t *a, const fvalue_t *b);
536 WS_DLL_PUBLIC
537 ft_bool_t
538 fvalue_ne(const fvalue_t *a, const fvalue_t *b);
540 WS_DLL_PUBLIC
541 ft_bool_t
542 fvalue_gt(const fvalue_t *a, const fvalue_t *b);
544 WS_DLL_PUBLIC
545 ft_bool_t
546 fvalue_ge(const fvalue_t *a, const fvalue_t *b);
548 WS_DLL_PUBLIC
549 ft_bool_t
550 fvalue_lt(const fvalue_t *a, const fvalue_t *b);
552 WS_DLL_PUBLIC
553 ft_bool_t
554 fvalue_le(const fvalue_t *a, const fvalue_t *b);
556 WS_DLL_PUBLIC
557 ft_bool_t
558 fvalue_contains(const fvalue_t *a, const fvalue_t *b);
560 WS_DLL_PUBLIC
561 ft_bool_t
562 fvalue_matches(const fvalue_t *a, const ws_regex_t *re);
564 WS_DLL_PUBLIC
565 ft_bool_t
566 fvalue_is_zero(const fvalue_t *a);
568 WS_DLL_PUBLIC
569 ft_bool_t
570 fvalue_is_negative(const fvalue_t *a);
572 WS_DLL_PUBLIC
573 size_t
574 fvalue_length2(fvalue_t *fv);
576 WS_DLL_PUBLIC
577 fvalue_t*
578 fvalue_slice(fvalue_t *fv, drange_t *dr);
580 WS_DLL_PUBLIC
581 fvalue_t*
582 fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b, char **err_msg);
584 WS_DLL_PUBLIC
585 fvalue_t*
586 fvalue_unary_minus(const fvalue_t *fv, char **err_msg);
588 WS_DLL_PUBLIC
589 fvalue_t*
590 fvalue_add(const fvalue_t *a, const fvalue_t *b, char **err_msg);
592 WS_DLL_PUBLIC
593 fvalue_t*
594 fvalue_subtract(const fvalue_t *a, const fvalue_t *b, char **err_msg);
596 WS_DLL_PUBLIC
597 fvalue_t*
598 fvalue_multiply(const fvalue_t *a, const fvalue_t *b, char **err_msg);
600 WS_DLL_PUBLIC
601 fvalue_t*
602 fvalue_divide(const fvalue_t *a, const fvalue_t *b, char **err_msg);
604 WS_DLL_PUBLIC
605 fvalue_t*
606 fvalue_modulo(const fvalue_t *a, const fvalue_t *b, char **err_msg);
608 WS_DLL_PUBLIC
609 unsigned
610 fvalue_hash(const fvalue_t *fv);
612 WS_DLL_PUBLIC
613 bool
614 fvalue_equal(const fvalue_t *a, const fvalue_t *b);
616 #ifdef __cplusplus
618 #endif /* __cplusplus */
620 #endif /* __FTYPES_H__ */
623 * Editor modelines - https://www.wireshark.org/tools/modelines.html
625 * Local variables:
626 * c-basic-offset: 8
627 * tab-width: 8
628 * indent-tabs-mode: t
629 * End:
631 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
632 * :indentSize=8:tabSize=8:noTabs=false: