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