2 * Definitions for field types
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2001 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 FT_NONE, /* used for text labels with no value */
36 FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
39 FT_UINT24, /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
44 FT_INT24, /* same as for UINT24 */
52 FT_STRINGZ, /* for use with proto_tree_add_item() */
53 FT_EBCDIC, /* for use with proto_tree_add_item() */
54 FT_UINT_STRING, /* for use with proto_tree_add_item() */
55 /*FT_UCS2_LE, */ /* Unicode, 2 byte, Little Endian */
62 FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that number */
63 FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */
64 FT_GUID, /* GUID, UUID */
65 FT_OID, /* OBJECT IDENTIFIER */
66 FT_NUM_TYPES /* last item number plus one */
69 #define IS_FT_INT(ft) ((ft)==FT_INT8||(ft)==FT_INT16||(ft)==FT_INT24||(ft)==FT_INT32||(ft)==FT_INT64)
70 #define IS_FT_UINT(ft) ((ft)==FT_UINT8||(ft)==FT_UINT16||(ft)==FT_UINT24||(ft)==FT_UINT32||(ft)==FT_UINT64||(ft)==FT_FRAMENUM)
71 #define IS_FT_TIME(ft) ((ft)==FT_ABSOLUTE_TIME||(ft)==FT_RELATIVE_TIME)
72 #define IS_FT_STRING(ft) ((ft)==FT_STRING||(ft)==FT_STRINGZ)
74 /* field types lengths */
75 #define FT_ETHER_LEN 6
76 #define FT_GUID_LEN 16
78 #define FT_IPv6_LEN 16
79 #define FT_IPXNET_LEN 4
81 typedef enum ftenum ftenum_t;
82 typedef struct _ftype_t ftype_t;
84 /* String representation types. */
90 typedef enum ftrepr ftrepr_t;
93 typedef struct _pcre_tuple_t pcre_tuple_t;
94 #endif /* HAVE_LIBPCRE */
96 /* Initialize the ftypes subsytem. Called once. */
98 ftypes_initialize(void);
100 /* ---------------- FTYPE ----------------- */
102 /* Return a string representing the name of the type */
104 ftype_name(ftenum_t ftype);
106 /* Return a string presenting a "pretty" representation of the
107 * name of the type. The pretty name means more to the user than
108 * that "FT_*" name. */
110 ftype_pretty_name(ftenum_t ftype);
112 /* Returns length of field in packet, or 0 if not determinable/defined. */
114 ftype_length(ftenum_t ftype);
117 ftype_can_slice(enum ftenum ftype);
120 ftype_can_eq(enum ftenum ftype);
123 ftype_can_ne(enum ftenum ftype);
126 ftype_can_gt(enum ftenum ftype);
129 ftype_can_ge(enum ftenum ftype);
132 ftype_can_lt(enum ftenum ftype);
135 ftype_can_le(enum ftenum ftype);
138 ftype_can_bitwise_and(enum ftenum ftype);
141 ftype_can_contains(enum ftenum ftype);
144 ftype_can_matches(enum ftenum ftype);
146 /* ---------------- FVALUE ----------------- */
148 #include <epan/ipv4.h>
149 #include <epan/guid-utils.h>
151 #include <epan/tvbuff.h>
152 #include <epan/nstime.h>
153 #include <epan/dfilter/drange.h>
155 typedef struct _fvalue_t {
158 /* Put a few basic types in here */
172 #elif GLIB_CHECK_VERSION(2,14,0) /* Try falling back to GRegex. */
174 #endif /* HAVE_LIBPCRE */
177 /* The following is provided for private use
179 gboolean fvalue_gboolean1;
183 typedef void (*FvalueNewFunc)(fvalue_t*);
184 typedef void (*FvalueFreeFunc)(fvalue_t*);
185 typedef void (*LogFunc)(const char*,...);
187 typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, char*, gboolean, LogFunc);
188 typedef gboolean (*FvalueFromString)(fvalue_t*, char*, LogFunc);
189 typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, char*);
190 typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t);
192 typedef void (*FvalueSetFunc)(fvalue_t*, gpointer, gboolean);
193 typedef void (*FvalueSetUnsignedIntegerFunc)(fvalue_t*, guint32);
194 typedef void (*FvalueSetSignedIntegerFunc)(fvalue_t*, gint32);
195 typedef void (*FvalueSetInteger64Func)(fvalue_t*, guint64);
196 typedef void (*FvalueSetFloatingFunc)(fvalue_t*, gdouble);
198 typedef gpointer (*FvalueGetFunc)(fvalue_t*);
199 typedef guint32 (*FvalueGetUnsignedIntegerFunc)(fvalue_t*);
200 typedef gint32 (*FvalueGetSignedIntegerFunc)(fvalue_t*);
201 typedef guint64 (*FvalueGetInteger64Func)(fvalue_t*);
202 typedef double (*FvalueGetFloatingFunc)(fvalue_t*);
204 typedef gboolean (*FvalueCmp)(fvalue_t*, fvalue_t*);
206 typedef guint (*FvalueLen)(fvalue_t*);
207 typedef void (*FvalueSlice)(fvalue_t*, GByteArray *, guint offset, guint length);
212 const char *pretty_name;
214 FvalueNewFunc new_value;
215 FvalueFreeFunc free_value;
216 FvalueFromUnparsed val_from_unparsed;
217 FvalueFromString val_from_string;
218 FvalueToStringRepr val_to_string_repr;
219 FvalueStringReprLen len_string_repr;
222 FvalueSetFunc set_value;
223 FvalueSetUnsignedIntegerFunc set_value_uinteger;
224 FvalueSetSignedIntegerFunc set_value_sinteger;
225 FvalueSetInteger64Func set_value_integer64;
226 FvalueSetFloatingFunc set_value_floating;
229 FvalueGetFunc get_value;
230 FvalueGetUnsignedIntegerFunc get_value_uinteger;
231 FvalueGetSignedIntegerFunc get_value_sinteger;
232 FvalueGetInteger64Func get_value_integer64;
233 FvalueGetFloatingFunc get_value_floating;
241 FvalueCmp cmp_bitwise_and;
242 FvalueCmp cmp_contains;
243 FvalueCmp cmp_matches;
251 fvalue_new(ftenum_t ftype);
254 fvalue_init(fvalue_t *fv, ftenum_t ftype);
257 /* Define type needed for the fvalue_t free list. */
258 SLAB_ITEM_TYPE_DEFINE(fvalue_t)
260 /* Free all memory used by an fvalue_t. With MSVC and a
261 * libwireshark.dll, we need a special declaration.
263 WS_VAR_IMPORT SLAB_FREE_LIST_DECLARE(fvalue_t)
266 #define FVALUE_CLEANUP(fv) \
268 register FvalueFreeFunc free_value; \
269 free_value = (fv)->ftype->free_value; \
275 #define FVALUE_FREE(fv) \
278 SLAB_FREE(fv, fvalue_t); \
283 fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogFunc logfunc);
286 fvalue_from_string(ftenum_t ftype, char *s, LogFunc logfunc);
288 /* Returns the length of the string required to hold the
289 * string representation of the the field value.
291 * Returns -1 if the string cannot be represented in the given rtype.
293 * The length DOES NOT include the terminating NUL. */
295 fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype);
297 /* Creates the string representation of the field value.
298 * If given non-NULL 'buf', the string is written at the memory
299 * location pointed to by 'buf'. If 'buf' is NULL, new memory
300 * is malloc'ed and the string representation is written there.
301 * The pointer to the beginning of the string representation is
302 * returned. If 'buf' was NULL, this points to the newly-allocated
303 * memory. if 'buf' was non-NULL, then the return value will be
306 * Returns NULL if the string cannot be represented in the given rtype.*/
308 fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, char *buf);
311 fvalue_ftype(fvalue_t *fv);
314 fvalue_type_name(fvalue_t *fv);
317 fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied);
320 fvalue_set_uinteger(fvalue_t *fv, guint32 value);
323 fvalue_set_sinteger(fvalue_t *fv, gint32 value);
326 fvalue_set_integer64(fvalue_t *fv, guint64 value);
329 fvalue_set_floating(fvalue_t *fv, gdouble value);
332 fvalue_get(fvalue_t *fv);
335 fvalue_get_uinteger(fvalue_t *fv);
338 fvalue_get_sinteger(fvalue_t *fv);
341 fvalue_get_integer64(fvalue_t *fv);
344 fvalue_get_floating(fvalue_t *fv);
347 fvalue_eq(fvalue_t *a, fvalue_t *b);
350 fvalue_ne(fvalue_t *a, fvalue_t *b);
353 fvalue_gt(fvalue_t *a, fvalue_t *b);
356 fvalue_ge(fvalue_t *a, fvalue_t *b);
359 fvalue_lt(fvalue_t *a, fvalue_t *b);
362 fvalue_le(fvalue_t *a, fvalue_t *b);
365 fvalue_bitwise_and(fvalue_t *a, fvalue_t *b);
368 fvalue_contains(fvalue_t *a, fvalue_t *b);
371 fvalue_matches(fvalue_t *a, fvalue_t *b);
374 fvalue_length(fvalue_t *fv);
377 fvalue_slice(fvalue_t *fv, drange *dr);
379 #endif /* ftypes.h */