epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / ftypes / ftypes.h
blob74a3e1849dc1f6d0a5169e7e3f4a1a9927ccfebf
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_BADARG,
158 FT_ERROR, /* Generic. */
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).
169 typedef bool ft_bool_t;
170 #define FT_TRUE 1
171 #define FT_FALSE 0
173 /* String representation types. */
174 enum ftrepr {
175 FTREPR_DISPLAY,
176 FTREPR_DFILTER,
177 FTREPR_JSON,
178 FTREPR_RAW,
181 typedef enum ftrepr ftrepr_t;
183 /* Initialize the ftypes subsystem. Called once. */
184 void
185 ftypes_initialize(void);
187 void
188 ftypes_register_pseudofields(void);
190 /* ---------------- FTYPE ----------------- */
192 /* given two types, are they similar - for example can two
193 * duplicate fields be registered of these two types. */
194 bool
195 ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
197 /* Return a string representing the name of the type */
198 WS_DLL_PUBLIC
199 const char*
200 ftype_name(ftenum_t ftype);
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. */
205 WS_DLL_PUBLIC
206 const char*
207 ftype_pretty_name(ftenum_t ftype);
209 /* Returns length of field in packet, or 0 if not determinable/defined. */
211 ftype_wire_size(ftenum_t ftype);
213 WS_DLL_PUBLIC
214 bool
215 ftype_can_length(enum ftenum ftype);
217 WS_DLL_PUBLIC
218 bool
219 ftype_can_slice(enum ftenum ftype);
221 WS_DLL_PUBLIC
222 bool
223 ftype_can_eq(enum ftenum ftype);
225 WS_DLL_PUBLIC
226 bool
227 ftype_can_cmp(enum ftenum ftype);
229 WS_DLL_PUBLIC
230 bool
231 ftype_can_bitwise_and(enum ftenum ftype);
233 WS_DLL_PUBLIC
234 bool
235 ftype_can_unary_minus(enum ftenum ftype);
237 WS_DLL_PUBLIC
238 bool
239 ftype_can_add(enum ftenum ftype);
241 WS_DLL_PUBLIC
242 bool
243 ftype_can_subtract(enum ftenum ftype);
245 WS_DLL_PUBLIC
246 bool
247 ftype_can_multiply(enum ftenum ftype);
249 WS_DLL_PUBLIC
250 bool
251 ftype_can_divide(enum ftenum ftype);
253 WS_DLL_PUBLIC
254 bool
255 ftype_can_modulo(enum ftenum ftype);
257 WS_DLL_PUBLIC
258 bool
259 ftype_can_contains(enum ftenum ftype);
261 WS_DLL_PUBLIC
262 bool
263 ftype_can_matches(enum ftenum ftype);
265 WS_DLL_PUBLIC
266 bool
267 ftype_can_is_zero(enum ftenum ftype);
269 WS_DLL_PUBLIC
270 bool
271 ftype_can_is_negative(enum ftenum ftype);
273 WS_DLL_PUBLIC
274 bool
275 ftype_can_val_to_sinteger(enum ftenum ftype);
277 WS_DLL_PUBLIC
278 bool
279 ftype_can_val_to_uinteger(enum ftenum ftype);
281 WS_DLL_PUBLIC
282 bool
283 ftype_can_val_to_sinteger64(enum ftenum ftype);
285 WS_DLL_PUBLIC
286 bool
287 ftype_can_val_to_uinteger64(enum ftenum ftype);
289 /* ---------------- FVALUE ----------------- */
291 #include <wsutil/inet_cidr.h>
292 #include <epan/guid-utils.h>
294 #include <epan/tvbuff.h>
295 #include <wsutil/nstime.h>
296 #include <epan/dfilter/drange.h>
298 typedef struct _protocol_value_t
300 tvbuff_t *tvb;
301 int length;
302 char *proto_string;
303 bool tvb_is_private;
304 } protocol_value_t;
306 typedef struct _fvalue_t fvalue_t;
308 WS_DLL_PUBLIC
309 fvalue_t*
310 fvalue_new(ftenum_t ftype);
312 WS_DLL_PUBLIC
313 fvalue_t*
314 fvalue_dup(const fvalue_t *fv);
316 WS_DLL_PUBLIC
317 void
318 fvalue_init(fvalue_t *fv, ftenum_t ftype);
320 WS_DLL_PUBLIC
321 void
322 fvalue_cleanup(fvalue_t *fv);
324 WS_DLL_PUBLIC
325 void
326 fvalue_free(fvalue_t *fv);
328 WS_DLL_PUBLIC
329 fvalue_t*
330 fvalue_from_literal(ftenum_t ftype, const char *s, bool allow_partial_value, char **err_msg);
332 /* String *MUST* be null-terminated. Length is optional (pass zero) and does not include the null terminator. */
333 fvalue_t*
334 fvalue_from_string(ftenum_t ftype, const char *s, size_t len, char **err_msg);
336 fvalue_t*
337 fvalue_from_charconst(ftenum_t ftype, unsigned long number, char **err_msg);
339 fvalue_t*
340 fvalue_from_sinteger64(ftenum_t ftype, const char *s, int64_t number, char **err_msg);
342 fvalue_t*
343 fvalue_from_uinteger64(ftenum_t ftype, const char *s, uint64_t number, char **err_msg);
345 fvalue_t*
346 fvalue_from_floating(ftenum_t ftype, const char *s, double number, char **err_msg);
348 /* Creates the string representation of the field value.
349 * Memory for the buffer is allocated based on wmem allocator
350 * provided.
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.
355 * Returns NULL if the string cannot be represented in the given rtype.*/
356 WS_DLL_PUBLIC char *
357 fvalue_to_string_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display);
359 #define fvalue_to_debug_repr(scope, fv) \
360 fvalue_to_string_repr(scope, fv, FTREPR_DFILTER, 0)
362 WS_DLL_PUBLIC enum ft_result
363 fvalue_to_uinteger(const fvalue_t *fv, uint32_t *repr);
365 WS_DLL_PUBLIC enum ft_result
366 fvalue_to_sinteger(const fvalue_t *fv, int32_t *repr);
368 WS_DLL_PUBLIC enum ft_result
369 fvalue_to_uinteger64(const fvalue_t *fv, uint64_t *repr);
371 WS_DLL_PUBLIC enum ft_result
372 fvalue_to_sinteger64(const fvalue_t *fv, int64_t *repr);
374 WS_DLL_PUBLIC enum ft_result
375 fvalue_to_double(const fvalue_t *fv, double *repr);
377 WS_DLL_PUBLIC ftenum_t
378 fvalue_type_ftenum(const fvalue_t *fv);
380 WS_DLL_PUBLIC
381 const char*
382 fvalue_type_name(const fvalue_t *fv);
384 /* GBytes reference count is automatically incremented. */
385 WS_DLL_PUBLIC
386 void
387 fvalue_set_bytes(fvalue_t *fv, GBytes *value);
389 WS_DLL_PUBLIC
390 void
391 fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
393 WS_DLL_PUBLIC
394 void
395 fvalue_set_bytes_data(fvalue_t *fv, const void *data, size_t size);
397 WS_DLL_PUBLIC
398 void
399 fvalue_set_fcwwn(fvalue_t *fv, const uint8_t *value);
401 WS_DLL_PUBLIC
402 void
403 fvalue_set_ax25(fvalue_t *fv, const uint8_t *value);
405 WS_DLL_PUBLIC
406 void
407 fvalue_set_vines(fvalue_t *fv, const uint8_t *value);
409 WS_DLL_PUBLIC
410 void
411 fvalue_set_ether(fvalue_t *fv, const uint8_t *value);
413 WS_DLL_PUBLIC
414 void
415 fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
417 WS_DLL_PUBLIC
418 void
419 fvalue_set_time(fvalue_t *fv, const nstime_t *value);
421 WS_DLL_PUBLIC
422 void
423 fvalue_set_string(fvalue_t *fv, const char *value);
425 WS_DLL_PUBLIC
426 void
427 fvalue_set_strbuf(fvalue_t *fv, wmem_strbuf_t *value);
429 WS_DLL_PUBLIC
430 void
431 fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const char *name, int length);
433 WS_DLL_PUBLIC
434 void
435 fvalue_set_protocol_length(fvalue_t *fv, int length);
437 WS_DLL_PUBLIC
438 void
439 fvalue_set_uinteger(fvalue_t *fv, uint32_t value);
441 WS_DLL_PUBLIC
442 void
443 fvalue_set_sinteger(fvalue_t *fv, int32_t value);
445 WS_DLL_PUBLIC
446 void
447 fvalue_set_uinteger64(fvalue_t *fv, uint64_t value);
449 WS_DLL_PUBLIC
450 void
451 fvalue_set_sinteger64(fvalue_t *fv, int64_t value);
453 WS_DLL_PUBLIC
454 void
455 fvalue_set_floating(fvalue_t *fv, double value);
457 WS_DLL_PUBLIC
458 void
459 fvalue_set_ipv4(fvalue_t *fv, const ipv4_addr_and_mask *value);
461 WS_DLL_PUBLIC
462 void
463 fvalue_set_ipv6(fvalue_t *fv, const ipv6_addr_and_prefix *value);
465 /* GBytes reference count is automatically incremented. */
466 WS_DLL_PUBLIC
467 GBytes *
468 fvalue_get_bytes(fvalue_t *fv);
470 WS_DLL_PUBLIC
471 size_t
472 fvalue_get_bytes_size(fvalue_t *fv);
474 /* Same as fvalue_length() */
475 WS_DLL_PUBLIC
476 const void *
477 fvalue_get_bytes_data(fvalue_t *fv);
479 WS_DLL_PUBLIC
480 const e_guid_t *
481 fvalue_get_guid(fvalue_t *fv);
483 WS_DLL_PUBLIC
484 const nstime_t *
485 fvalue_get_time(fvalue_t *fv);
487 WS_DLL_PUBLIC
488 const char *
489 fvalue_get_string(fvalue_t *fv);
491 WS_DLL_PUBLIC
492 const wmem_strbuf_t *
493 fvalue_get_strbuf(fvalue_t *fv);
495 WS_DLL_PUBLIC
496 tvbuff_t *
497 fvalue_get_protocol(fvalue_t *fv);
499 WS_DLL_PUBLIC
500 uint32_t
501 fvalue_get_uinteger(fvalue_t *fv);
503 WS_DLL_PUBLIC
504 int32_t
505 fvalue_get_sinteger(fvalue_t *fv);
507 WS_DLL_PUBLIC
508 uint64_t
509 fvalue_get_uinteger64(fvalue_t *fv);
511 WS_DLL_PUBLIC
512 int64_t
513 fvalue_get_sinteger64(fvalue_t *fv);
515 WS_DLL_PUBLIC
516 double
517 fvalue_get_floating(fvalue_t *fv);
519 WS_DLL_PUBLIC
520 const ipv4_addr_and_mask *
521 fvalue_get_ipv4(fvalue_t *fv);
523 WS_DLL_PUBLIC
524 const ipv6_addr_and_prefix *
525 fvalue_get_ipv6(fvalue_t *fv);
527 WS_DLL_PUBLIC
528 ft_bool_t
529 fvalue_eq(const fvalue_t *a, const fvalue_t *b);
531 WS_DLL_PUBLIC
532 ft_bool_t
533 fvalue_ne(const fvalue_t *a, const fvalue_t *b);
535 WS_DLL_PUBLIC
536 ft_bool_t
537 fvalue_gt(const fvalue_t *a, const fvalue_t *b);
539 WS_DLL_PUBLIC
540 ft_bool_t
541 fvalue_ge(const fvalue_t *a, const fvalue_t *b);
543 WS_DLL_PUBLIC
544 ft_bool_t
545 fvalue_lt(const fvalue_t *a, const fvalue_t *b);
547 WS_DLL_PUBLIC
548 ft_bool_t
549 fvalue_le(const fvalue_t *a, const fvalue_t *b);
551 WS_DLL_PUBLIC
552 ft_bool_t
553 fvalue_contains(const fvalue_t *a, const fvalue_t *b);
555 WS_DLL_PUBLIC
556 ft_bool_t
557 fvalue_matches(const fvalue_t *a, const ws_regex_t *re);
559 WS_DLL_PUBLIC
560 bool
561 fvalue_is_zero(const fvalue_t *a);
563 WS_DLL_PUBLIC
564 bool
565 fvalue_is_negative(const fvalue_t *a);
567 WS_DLL_PUBLIC
568 size_t
569 fvalue_length2(fvalue_t *fv);
571 WS_DLL_PUBLIC
572 fvalue_t*
573 fvalue_slice(fvalue_t *fv, drange_t *dr);
575 WS_DLL_PUBLIC
576 fvalue_t*
577 fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b, char **err_msg);
579 WS_DLL_PUBLIC
580 fvalue_t*
581 fvalue_unary_minus(const fvalue_t *fv, char **err_msg);
583 WS_DLL_PUBLIC
584 fvalue_t*
585 fvalue_add(const fvalue_t *a, const fvalue_t *b, char **err_msg);
587 WS_DLL_PUBLIC
588 fvalue_t*
589 fvalue_subtract(const fvalue_t *a, const fvalue_t *b, char **err_msg);
591 WS_DLL_PUBLIC
592 fvalue_t*
593 fvalue_multiply(const fvalue_t *a, const fvalue_t *b, char **err_msg);
595 WS_DLL_PUBLIC
596 fvalue_t*
597 fvalue_divide(const fvalue_t *a, const fvalue_t *b, char **err_msg);
599 WS_DLL_PUBLIC
600 fvalue_t*
601 fvalue_modulo(const fvalue_t *a, const fvalue_t *b, char **err_msg);
603 WS_DLL_PUBLIC
604 unsigned
605 fvalue_hash(const fvalue_t *fv);
607 WS_DLL_PUBLIC
608 bool
609 fvalue_equal(const fvalue_t *a, const fvalue_t *b);
611 #ifdef __cplusplus
613 #endif /* __cplusplus */
615 #endif /* __FTYPES_H__ */
618 * Editor modelines - https://www.wireshark.org/tools/modelines.html
620 * Local variables:
621 * c-basic-offset: 8
622 * tab-width: 8
623 * indent-tabs-mode: t
624 * End:
626 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
627 * :indentSize=8:tabSize=8:noTabs=false: