Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
ftypes.h
1 /* ftypes.h
2  * Definitions for field types
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 2001 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 
12 #ifndef __FTYPES_H__
13 #define __FTYPES_H__
14 
15 #include <glib.h>
16 #include "../wmem/wmem.h"
17 #include "ws_symbol_export.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
22 
23 /* field types */
24 enum ftenum {
25  FT_NONE, /* used for text labels with no value */
26  FT_PROTOCOL,
27  FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
28  FT_CHAR, /* 1-octet character as 0-255 */
29  FT_UINT8,
30  FT_UINT16,
31  FT_UINT24, /* really a UINT32, but displayed as 6 hex-digits if FD_HEX*/
32  FT_UINT32,
33  FT_UINT40, /* really a UINT64, but displayed as 10 hex-digits if FD_HEX*/
34  FT_UINT48, /* really a UINT64, but displayed as 12 hex-digits if FD_HEX*/
35  FT_UINT56, /* really a UINT64, but displayed as 14 hex-digits if FD_HEX*/
36  FT_UINT64,
37  FT_INT8,
38  FT_INT16,
39  FT_INT24, /* same as for UINT24 */
40  FT_INT32,
41  FT_INT40, /* same as for UINT40 */
42  FT_INT48, /* same as for UINT48 */
43  FT_INT56, /* same as for UINT56 */
44  FT_INT64,
45  FT_IEEE_11073_SFLOAT,
46  FT_IEEE_11073_FLOAT,
47  FT_FLOAT,
48  FT_DOUBLE,
49  FT_ABSOLUTE_TIME,
50  FT_RELATIVE_TIME,
51  FT_STRING,
52  FT_STRINGZ, /* for use with proto_tree_add_item() */
53  FT_UINT_STRING, /* for use with proto_tree_add_item() */
54  FT_ETHER,
55  FT_BYTES,
56  FT_UINT_BYTES,
57  FT_IPv4,
58  FT_IPv6,
59  FT_IPXNET,
60  FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that number */
61  FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */
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, /* for use with proto_tree_add_item() */
70  FT_FCWWN,
71  FT_NUM_TYPES /* last item number plus one */
72 };
73 
74 #define IS_FT_INT(ft) ((ft)==FT_INT8||(ft)==FT_INT16||(ft)==FT_INT24||(ft)==FT_INT32||(ft)==FT_INT40||(ft)==FT_INT48||(ft)==FT_INT56||(ft)==FT_INT64)
75 #define IS_FT_UINT32(ft) ((ft)==FT_CHAR||(ft)==FT_UINT8||(ft)==FT_UINT16||(ft)==FT_UINT24||(ft)==FT_UINT32||(ft)==FT_FRAMENUM)
76 #define IS_FT_UINT(ft) ((ft)==FT_CHAR||(ft)==FT_UINT8||(ft)==FT_UINT16||(ft)==FT_UINT24||(ft)==FT_UINT32||(ft)==FT_UINT40||(ft)==FT_UINT48||(ft)==FT_UINT56||(ft)==FT_UINT64||(ft)==FT_FRAMENUM)
77 #define IS_FT_TIME(ft) ((ft)==FT_ABSOLUTE_TIME||(ft)==FT_RELATIVE_TIME)
78 #define IS_FT_STRING(ft) ((ft)==FT_STRING||(ft)==FT_STRINGZ||(ft)==FT_STRINGZPAD)
79 
80 /* field types lengths */
81 #define FT_ETHER_LEN 6
82 #define FT_GUID_LEN 16
83 #define FT_IPv4_LEN 4
84 #define FT_IPv6_LEN 16
85 #define FT_IPXNET_LEN 4
86 #define FT_EUI64_LEN 8
87 #define FT_AX25_ADDR_LEN 7
88 #define FT_VINES_ADDR_LEN 6
89 #define FT_FCWWN_LEN 8
90 #define FT_VARINT_MAX_LEN 10 /* Because 64 / 7 = 9 and 64 % 7 = 1, get an uint64 varint need reads up to 10 bytes. */
91 
92 typedef enum ftenum ftenum_t;
93 
94 enum ft_framenum_type {
95  FT_FRAMENUM_NONE,
96  FT_FRAMENUM_REQUEST,
97  FT_FRAMENUM_RESPONSE,
98  FT_FRAMENUM_ACK,
99  FT_FRAMENUM_DUP_ACK,
100  FT_FRAMENUM_RETRANS_PREV,
101  FT_FRAMENUM_RETRANS_NEXT,
102  FT_FRAMENUM_NUM_TYPES /* last item number plus one */
103 };
104 
105 typedef enum ft_framenum_type ft_framenum_type_t;
106 
107 struct _ftype_t;
108 typedef struct _ftype_t ftype_t;
109 
110 /* String representation types. */
111 enum ftrepr {
112  FTREPR_DISPLAY,
113  FTREPR_DFILTER
114 };
115 
116 typedef enum ftrepr ftrepr_t;
117 
118 /* Initialize the ftypes subsytem. Called once. */
119 void
120 ftypes_initialize(void);
121 
122 /* ---------------- FTYPE ----------------- */
123 
124 /* given two types, are they similar - for example can two
125  * duplicate fields be registered of these two types. */
126 gboolean
127 ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
128 
129 /* Return a string representing the name of the type */
130 WS_DLL_PUBLIC
131 const char*
132 ftype_name(ftenum_t ftype);
133 
134 /* Return a string presenting a "pretty" representation of the
135  * name of the type. The pretty name means more to the user than
136  * that "FT_*" name. */
137 WS_DLL_PUBLIC
138 const char*
139 ftype_pretty_name(ftenum_t ftype);
140 
141 /* Returns length of field in packet, or 0 if not determinable/defined. */
142 int
143 ftype_length(ftenum_t ftype);
144 
145 WS_DLL_PUBLIC
146 gboolean
147 ftype_can_slice(enum ftenum ftype);
148 
149 WS_DLL_PUBLIC
150 gboolean
151 ftype_can_eq(enum ftenum ftype);
152 
153 WS_DLL_PUBLIC
154 gboolean
155 ftype_can_ne(enum ftenum ftype);
156 
157 WS_DLL_PUBLIC
158 gboolean
159 ftype_can_gt(enum ftenum ftype);
160 
161 WS_DLL_PUBLIC
162 gboolean
163 ftype_can_ge(enum ftenum ftype);
164 
165 WS_DLL_PUBLIC
166 gboolean
167 ftype_can_lt(enum ftenum ftype);
168 
169 WS_DLL_PUBLIC
170 gboolean
171 ftype_can_le(enum ftenum ftype);
172 
173 gboolean
174 ftype_can_bitwise_and(enum ftenum ftype);
175 
176 WS_DLL_PUBLIC
177 gboolean
178 ftype_can_contains(enum ftenum ftype);
179 
180 WS_DLL_PUBLIC
181 gboolean
182 ftype_can_matches(enum ftenum ftype);
183 
184 /* ---------------- FVALUE ----------------- */
185 
186 #include <epan/ipv4.h>
187 #include <epan/ipv6.h>
188 #include <epan/guid-utils.h>
189 
190 #include <epan/tvbuff.h>
191 #include <wsutil/nstime.h>
192 #include <epan/dfilter/drange.h>
193 
194 typedef struct _protocol_value_t
195 {
196  tvbuff_t *tvb;
197  gchar *proto_string;
199 
200 typedef struct _fvalue_t {
201  ftype_t *ftype;
202  union {
203  /* Put a few basic types in here */
204  guint32 uinteger;
205  gint32 sinteger;
206  guint64 integer64;
207  guint64 uinteger64;
208  gint64 sinteger64;
209  gdouble floating;
210  gchar *string;
211  guchar *ustring;
212  GByteArray *bytes;
213  ipv4_addr_and_mask ipv4;
215  e_guid_t guid;
216  nstime_t time;
217  protocol_value_t protocol;
218  GRegex *re;
219  guint16 sfloat_ieee_11073;
220  guint32 float_ieee_11073;
221  } value;
222 
223  /* The following is provided for private use
224  * by the fvalue. */
225  gboolean fvalue_gboolean1;
226 
227 } fvalue_t;
228 
229 fvalue_t*
230 fvalue_new(ftenum_t ftype);
231 
232 void
233 fvalue_init(fvalue_t *fv, ftenum_t ftype);
234 
235 WS_DLL_PUBLIC
236 fvalue_t*
237 fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg);
238 
239 fvalue_t*
240 fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg);
241 
242 /* Returns the length of the string required to hold the
243  * string representation of the the field value.
244  *
245  * Returns -1 if the string cannot be represented in the given rtype.
246  *
247  * The length DOES NOT include the terminating NUL. */
248 WS_DLL_PUBLIC
249 int
250 fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display);
251 
252 /* Creates the string representation of the field value.
253  * Memory for the buffer is allocated based on wmem allocator
254  * provided.
255  *
256  * field_display parameter should be a BASE_ value (enum field_display_e)
257  * BASE_NONE should be used if field information isn't available.
258  *
259  * Returns NULL if the string cannot be represented in the given rtype.*/
260 WS_DLL_PUBLIC char *
261 fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int field_display);
262 
263 WS_DLL_PUBLIC ftenum_t
264 fvalue_type_ftenum(fvalue_t *fv);
265 
266 const char*
267 fvalue_type_name(fvalue_t *fv);
268 
269 void
270 fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
271 
272 void
273 fvalue_set_bytes(fvalue_t *fv, const guint8 *value);
274 
275 void
276 fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
277 
278 void
279 fvalue_set_time(fvalue_t *fv, const nstime_t *value);
280 
281 void
282 fvalue_set_string(fvalue_t *fv, const gchar *value);
283 
284 void
285 fvalue_set_protocol(fvalue_t *fv, tvbuff_t *value, const gchar *name);
286 
287 void
288 fvalue_set_uinteger(fvalue_t *fv, guint32 value);
289 
290 void
291 fvalue_set_sinteger(fvalue_t *fv, gint32 value);
292 
293 void
294 fvalue_set_uinteger64(fvalue_t *fv, guint64 value);
295 
296 void
297 fvalue_set_sinteger64(fvalue_t *fv, gint64 value);
298 
299 void
300 fvalue_set_floating(fvalue_t *fv, gdouble value);
301 
302 WS_DLL_PUBLIC
303 gpointer
304 fvalue_get(fvalue_t *fv);
305 
306 WS_DLL_PUBLIC guint32
307 fvalue_get_uinteger(fvalue_t *fv);
308 
309 WS_DLL_PUBLIC gint32
310 fvalue_get_sinteger(fvalue_t *fv);
311 
312 WS_DLL_PUBLIC
313 guint64
314 fvalue_get_uinteger64(fvalue_t *fv);
315 
316 WS_DLL_PUBLIC
317 gint64
318 fvalue_get_sinteger64(fvalue_t *fv);
319 
320 WS_DLL_PUBLIC double
321 fvalue_get_floating(fvalue_t *fv);
322 
323 gboolean
324 fvalue_eq(const fvalue_t *a, const fvalue_t *b);
325 
326 gboolean
327 fvalue_ne(const fvalue_t *a, const fvalue_t *b);
328 
329 gboolean
330 fvalue_gt(const fvalue_t *a, const fvalue_t *b);
331 
332 gboolean
333 fvalue_ge(const fvalue_t *a, const fvalue_t *b);
334 
335 gboolean
336 fvalue_lt(const fvalue_t *a, const fvalue_t *b);
337 
338 gboolean
339 fvalue_le(const fvalue_t *a, const fvalue_t *b);
340 
341 gboolean
342 fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b);
343 
344 gboolean
345 fvalue_contains(const fvalue_t *a, const fvalue_t *b);
346 
347 gboolean
348 fvalue_matches(const fvalue_t *a, const fvalue_t *b);
349 
350 guint
351 fvalue_length(fvalue_t *fv);
352 
353 fvalue_t*
354 fvalue_slice(fvalue_t *fv, drange_t *dr);
355 
356 #ifdef __cplusplus
357 }
358 #endif /* __cplusplus */
359 
360 #endif /* __FTYPES_H__ */
361 
362 /*
363  * Editor modelines - http://www.wireshark.org/tools/modelines.html
364  *
365  * Local variables:
366  * c-basic-offset: 8
367  * tab-width: 8
368  * indent-tabs-mode: t
369  * End:
370  *
371  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
372  * :indentSize=8:tabSize=8:noTabs=false:
373  */
Definition: ftypes-int.h:69
Definition: tvbuff-int.h:35
Definition: ftypes.h:194
Definition: nstime.h:27
Definition: guid-utils.h:21
Definition: wmem_allocator.h:26
Definition: ftypes.h:200
Definition: ipv4.h:21
Definition: drange.h:41
Definition: ipv6.h:22