Rename ipv6-utils.h to ipv6.h.
[metze/wireshark/wip.git] / epan / ftypes / 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  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23
24 #ifndef __FTYPES_H__
25 #define __FTYPES_H__
26
27 #include <glib.h>
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /* field types */
35 enum ftenum {
36         FT_NONE,        /* used for text labels with no value */
37         FT_PROTOCOL,
38         FT_BOOLEAN,     /* TRUE and FALSE come from <glib.h> */
39         FT_UINT8,
40         FT_UINT16,
41         FT_UINT24,      /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
42         FT_UINT32,
43         FT_UINT40,      /* really a UINT64, but displayed as 10 hex-digits if FD_HEX*/
44         FT_UINT48,      /* really a UINT64, but displayed as 12 hex-digits if FD_HEX*/
45         FT_UINT56,      /* really a UINT64, but displayed as 14 hex-digits if FD_HEX*/
46         FT_UINT64,
47         FT_INT8,
48         FT_INT16,
49         FT_INT24,       /* same as for UINT24 */
50         FT_INT32,
51         FT_INT40, /* same as for UINT40 */
52         FT_INT48, /* same as for UINT48 */
53         FT_INT56, /* same as for UINT56 */
54         FT_INT64,
55         FT_IEEE_11073_SFLOAT,
56         FT_IEEE_11073_FLOAT,
57         FT_FLOAT,
58         FT_DOUBLE,
59         FT_ABSOLUTE_TIME,
60         FT_RELATIVE_TIME,
61         FT_STRING,
62         FT_STRINGZ,     /* for use with proto_tree_add_item() */
63         FT_UINT_STRING, /* for use with proto_tree_add_item() */
64         FT_ETHER,
65         FT_BYTES,
66         FT_UINT_BYTES,
67         FT_IPv4,
68         FT_IPv6,
69         FT_IPXNET,
70         FT_FRAMENUM,    /* a UINT32, but if selected lets you go to frame with that number */
71         FT_PCRE,        /* a compiled Perl-Compatible Regular Expression object */
72         FT_GUID,        /* GUID, UUID */
73         FT_OID,         /* OBJECT IDENTIFIER */
74         FT_EUI64,
75         FT_AX25,
76         FT_VINES,
77         FT_REL_OID,     /* RELATIVE-OID */
78         FT_SYSTEM_ID,
79         FT_STRINGZPAD,  /* for use with proto_tree_add_item() */
80         FT_FCWWN,
81         FT_NUM_TYPES /* last item number plus one */
82 };
83
84 #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)
85 #define IS_FT_UINT(ft)   ((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)
86 #define IS_FT_TIME(ft)   ((ft)==FT_ABSOLUTE_TIME||(ft)==FT_RELATIVE_TIME)
87 #define IS_FT_STRING(ft) ((ft)==FT_STRING||(ft)==FT_STRINGZ||(ft)==FT_STRINGZPAD)
88
89 /* field types lengths */
90 #define FT_ETHER_LEN        6
91 #define FT_GUID_LEN         16
92 #define FT_IPv4_LEN         4
93 #define FT_IPv6_LEN         16
94 #define FT_IPXNET_LEN       4
95 #define FT_EUI64_LEN        8
96 #define FT_AX25_ADDR_LEN    7
97 #define FT_VINES_ADDR_LEN         6
98 #define FT_FCWWN_LEN        8
99
100 typedef enum ftenum ftenum_t;
101
102 enum ft_framenum_type {
103     FT_FRAMENUM_NONE,
104     FT_FRAMENUM_REQUEST,
105     FT_FRAMENUM_RESPONSE,
106     FT_FRAMENUM_ACK,
107     FT_FRAMENUM_DUP_ACK,
108     FT_FRAMENUM_NUM_TYPES /* last item number plus one */
109 };
110
111 typedef enum ft_framenum_type ft_framenum_type_t;
112
113 struct _ftype_t;
114 typedef struct _ftype_t ftype_t;
115
116 /* String representation types. */
117 enum ftrepr {
118         FTREPR_DISPLAY,
119         FTREPR_DFILTER
120 };
121
122 typedef enum ftrepr ftrepr_t;
123
124 /* Initialize the ftypes subsytem. Called once. */
125 void
126 ftypes_initialize(void);
127
128 /* ---------------- FTYPE ----------------- */
129
130 /* given two types, are they similar - for example can two
131  * duplicate fields be registered of these two types. */
132 gboolean
133 ftype_similar_types(const enum ftenum ftype_a, const enum ftenum ftype_b);
134
135 /* Return a string representing the name of the type */
136 WS_DLL_PUBLIC
137 const char*
138 ftype_name(ftenum_t ftype);
139
140 /* Return a string presenting a "pretty" representation of the
141  * name of the type. The pretty name means more to the user than
142  * that "FT_*" name. */
143 WS_DLL_PUBLIC
144 const char*
145 ftype_pretty_name(ftenum_t ftype);
146
147 /* Returns length of field in packet, or 0 if not determinable/defined. */
148 int
149 ftype_length(ftenum_t ftype);
150
151 WS_DLL_PUBLIC
152 gboolean
153 ftype_can_slice(enum ftenum ftype);
154
155 WS_DLL_PUBLIC
156 gboolean
157 ftype_can_eq(enum ftenum ftype);
158
159 WS_DLL_PUBLIC
160 gboolean
161 ftype_can_ne(enum ftenum ftype);
162
163 WS_DLL_PUBLIC
164 gboolean
165 ftype_can_gt(enum ftenum ftype);
166
167 WS_DLL_PUBLIC
168 gboolean
169 ftype_can_ge(enum ftenum ftype);
170
171 WS_DLL_PUBLIC
172 gboolean
173 ftype_can_lt(enum ftenum ftype);
174
175 WS_DLL_PUBLIC
176 gboolean
177 ftype_can_le(enum ftenum ftype);
178
179 gboolean
180 ftype_can_bitwise_and(enum ftenum ftype);
181
182 WS_DLL_PUBLIC
183 gboolean
184 ftype_can_contains(enum ftenum ftype);
185
186 WS_DLL_PUBLIC
187 gboolean
188 ftype_can_matches(enum ftenum ftype);
189
190 /* ---------------- FVALUE ----------------- */
191
192 #include <epan/ipv4.h>
193 #include <epan/ipv6.h>
194 #include <epan/guid-utils.h>
195
196 #include <epan/tvbuff.h>
197 #include <wsutil/nstime.h>
198 #include <epan/dfilter/drange.h>
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       ipv4;
214                 ipv6_addr       ipv6;
215                 e_guid_t        guid;
216                 nstime_t        time;
217                 tvbuff_t        *tvb;
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  * If given non-NULL 'buf', the string is written at the memory
254  * location pointed to by 'buf'. If 'buf' is NULL, new memory
255  * is malloc'ed and the string representation is written there.
256  * The pointer to the beginning of the string representation is
257  * returned. If 'buf' was NULL, this points to the newly-allocated
258  * memory. if 'buf' was non-NULL, then the return value will be
259  * 'buf'.
260  *
261  * field_display parameter should be a BASE_ value (enum field_display_e)
262  * BASE_NONE should be used if field information isn't available.
263  *
264  * Returns NULL if the string cannot be represented in the given rtype.*/
265 WS_DLL_PUBLIC char *
266 fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf);
267
268 WS_DLL_PUBLIC ftenum_t
269 fvalue_type_ftenum(fvalue_t *fv);
270
271 const char*
272 fvalue_type_name(fvalue_t *fv);
273
274 void
275 fvalue_set_byte_array(fvalue_t *fv, GByteArray *value);
276
277 void
278 fvalue_set_bytes(fvalue_t *fv, const guint8 *value);
279
280 void
281 fvalue_set_guid(fvalue_t *fv, const e_guid_t *value);
282
283 void
284 fvalue_set_time(fvalue_t *fv, const nstime_t *value);
285
286 void
287 fvalue_set_string(fvalue_t *fv, const gchar *value);
288
289 void
290 fvalue_set_tvbuff(fvalue_t *fv, tvbuff_t *value);
291
292 void
293 fvalue_set_uinteger(fvalue_t *fv, guint32 value);
294
295 void
296 fvalue_set_sinteger(fvalue_t *fv, gint32 value);
297
298 void
299 fvalue_set_uinteger64(fvalue_t *fv, guint64 value);
300
301 void
302 fvalue_set_sinteger64(fvalue_t *fv, gint64 value);
303
304 void
305 fvalue_set_floating(fvalue_t *fv, gdouble value);
306
307 WS_DLL_PUBLIC
308 gpointer
309 fvalue_get(fvalue_t *fv);
310
311 WS_DLL_PUBLIC guint32
312 fvalue_get_uinteger(fvalue_t *fv);
313
314 WS_DLL_PUBLIC gint32
315 fvalue_get_sinteger(fvalue_t *fv);
316
317 WS_DLL_PUBLIC
318 guint64
319 fvalue_get_uinteger64(fvalue_t *fv);
320
321 WS_DLL_PUBLIC
322 gint64
323 fvalue_get_sinteger64(fvalue_t *fv);
324
325 WS_DLL_PUBLIC double
326 fvalue_get_floating(fvalue_t *fv);
327
328 gboolean
329 fvalue_eq(const fvalue_t *a, const fvalue_t *b);
330
331 gboolean
332 fvalue_ne(const fvalue_t *a, const fvalue_t *b);
333
334 gboolean
335 fvalue_gt(const fvalue_t *a, const fvalue_t *b);
336
337 gboolean
338 fvalue_ge(const fvalue_t *a, const fvalue_t *b);
339
340 gboolean
341 fvalue_lt(const fvalue_t *a, const fvalue_t *b);
342
343 gboolean
344 fvalue_le(const fvalue_t *a, const fvalue_t *b);
345
346 gboolean
347 fvalue_bitwise_and(const fvalue_t *a, const fvalue_t *b);
348
349 gboolean
350 fvalue_contains(const fvalue_t *a, const fvalue_t *b);
351
352 gboolean
353 fvalue_matches(const fvalue_t *a, const fvalue_t *b);
354
355 guint
356 fvalue_length(fvalue_t *fv);
357
358 fvalue_t*
359 fvalue_slice(fvalue_t *fv, drange_t *dr);
360
361 #ifdef __cplusplus
362 }
363 #endif /* __cplusplus */
364
365 #endif /* __FTYPES_H__ */
366
367 /*
368  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
369  *
370  * Local variables:
371  * c-basic-offset: 8
372  * tab-width: 8
373  * indent-tabs-mode: t
374  * End:
375  *
376  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
377  * :indentSize=8:tabSize=8:noTabs=false:
378  */