2 * Definitions for protocol display
4 * $Id: proto.h,v 1.25 2001/12/18 19:09:04 gram Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 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.
43 #include "ftypes/ftypes.h"
47 #define ITEM_LABEL_LENGTH 240
49 /* In order to make a const value_string[] look like a value_string*, I
51 #define VALS(x) (struct value_string*)(x)
53 /* ... and similarly, */
54 #define TFS(x) (struct true_false_string*)(x)
56 /* check protocol activation */
57 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) { \
58 if (!proto_is_protocol_enabled(index)) { \
59 call_dissector(x_handle,tvb, pinfo, tree); \
72 typedef struct _header_field_info header_field_info;
74 /* information describing a header field */
75 struct _header_field_info {
76 /* ---------- set by dissector --------- */
80 int display; /* for integers only, so far. Base */
81 void *strings; /* val_string or true_false_string */
83 char *blurb; /* Brief description of field. */
85 /* ---------- set by proto routines --------- */
86 int id; /* Field ID */
87 int parent; /* parent protocol */
88 int bitshift; /* bits to shift */
89 header_field_info *same_name_next; /* Link to next hfinfo with same abbrev*/
90 header_field_info *same_name_prev; /* Link to previous hfinfo with same abbrev*/
94 * HFILL initializes all the "set by proto routines" fields in a
95 * "header_field_info"; if new fields are added or removed, it should
96 * be changed as necessary.
98 #define HFILL 0, 0, 0, NULL, NULL
100 /* Used when registering many fields at once */
101 typedef struct hf_register_info {
102 int *p_id; /* pointer to int; written to by register() function */
103 header_field_info hfinfo;
107 /* Contains the field information for the proto_item. */
108 typedef struct field_info {
109 header_field_info *hfinfo;
112 gint tree_type; /* ETT_* */
113 char *representation; /* for GUI tree */
116 gchar *ds_name; /* data source name */
119 /* One of these exists for the entire protocol tree. Each proto_node
120 * in the protocol tree points to the same copy. */
122 GHashTable *interesting_hfids;
126 /* Each GNode (proto_tree, proto_item) points to one of
130 tree_data_t *tree_data;
133 typedef GNode proto_tree;
134 typedef GNode proto_item;
136 /* Retrieve the proto_node from a GNode. */
137 #define GNODE_PNODE(t) ((proto_node*)((GNode*)(t))->data)
139 /* Retrieve the field_info from a proto_item */
140 #define PITEM_FINFO(t) (GNODE_PNODE(t)->finfo)
142 /* Retrieve the tree_data_t from a proto_tree */
143 #define PTREE_DATA(t) (GNODE_PNODE(t)->tree_data)
145 /* Sets up memory used by proto routines. Called at program startup */
146 extern void proto_init(const char *plugin_dir,
147 void (register_all_protocols)(void), void (register_all_handoffs)(void));
149 /* Frees memory used by proto routines. Called at program shutdown */
150 extern void proto_cleanup(void);
152 /* Set text of proto_item after having already been created. */
154 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
155 __attribute__((format (printf, 2, 3)));
157 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
160 /* Append to text of proto_item after having already been created. */
162 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
163 __attribute__((format (printf, 2, 3)));
165 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
168 /* Set length of proto_item after having already been created. */
169 extern void proto_item_set_len(proto_item *ti, gint length);
171 /* Get length of proto_item. Useful after using proto_tree_add_item()
172 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
173 extern int proto_item_get_len(proto_item *ti);
175 /* Creates new proto_tree root */
176 extern proto_tree* proto_tree_create_root(void);
178 /* Mark a field/protocol ID as "interesting". */
180 proto_tree_prime_hfid(proto_tree *tree, int hfid);
182 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
183 extern void proto_tree_free(proto_tree *tree);
185 /* Create a subtree under an existing item; returns tree pointer */
186 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
189 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
190 struct value_string* vals);
193 proto_register_protocol(char *name, char *short_name, char *filter_name);
196 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
199 proto_register_subtree_array(gint **indices, int num_indices);
201 /* Add an item to a proto_tree, using the text label registered to that item;
202 the item is extracted from the tvbuff handed to it. */
204 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
205 gint start, gint length, gboolean little_endian);
208 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
209 gint start, gint length, gboolean little_endian);
211 /* Add a FT_NONE to a proto_tree */
214 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
215 gint length, const char *format, ...)
216 __attribute__((format (printf, 6, 7)));
219 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
220 gint length, const char *format, ...);
223 /* Add a FT_PROTOCOL to a proto_tree */
226 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
227 gint length, const char *format, ...)
228 __attribute__((format (printf, 6, 7)));
231 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
232 gint length, const char *format, ...);
235 /* Add a FT_BYTES to a proto_tree */
237 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
238 gint length, const guint8* start_ptr);
241 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
242 gint length, const guint8* start_ptr);
246 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
247 gint length, const guint8* start_ptr, const char *format, ...)
248 __attribute__((format (printf, 7, 8)));
251 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
252 gint length, const guint8* start_ptr, const char *format, ...);
255 /* Add a FT_*TIME to a proto_tree */
257 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
258 gint length, nstime_t* value_ptr);
261 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
262 gint length, nstime_t* value_ptr);
266 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
267 gint length, nstime_t* value_ptr, const char *format, ...)
268 __attribute__((format (printf, 7, 8)));
271 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
272 gint length, nstime_t* value_ptr, const char *format, ...);
275 /* Add a FT_IPXNET to a proto_tree */
277 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
278 gint length, guint32 value);
281 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
282 gint length, guint32 value);
286 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
287 gint length, guint32 value, const char *format, ...)
288 __attribute__((format (printf, 7, 8)));
291 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
292 gint length, guint32 value, const char *format, ...);
295 /* Add a FT_IPv4 to a proto_tree */
297 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
298 gint length, guint32 value);
301 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
302 gint length, guint32 value);
306 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
307 gint length, guint32 value, const char *format, ...)
308 __attribute__((format (printf, 7, 8)));
311 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
312 gint length, guint32 value, const char *format, ...);
315 /* Add a FT_IPv6 to a proto_tree */
317 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
318 gint length, const guint8* value_ptr);
321 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
322 gint length, const guint8* value_ptr);
326 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
327 gint length, const guint8* value_ptr, const char *format, ...)
328 __attribute__((format (printf, 7, 8)));
331 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
332 gint length, const guint8* value_ptr, const char *format, ...);
335 /* Add a FT_ETHER to a proto_tree */
337 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
338 gint length, const guint8* value);
341 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
342 gint length, const guint8* value);
346 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
347 gint length, const guint8* value, const char *format, ...)
348 __attribute__((format (printf, 7, 8)));
351 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
352 gint length, const guint8* value, const char *format, ...);
355 /* Add a FT_STRING to a proto_tree */
357 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
358 gint length, const char* value);
361 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
362 gint length, const char* value);
366 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
367 gint length, const char* value, const char *format, ...)
368 __attribute__((format (printf, 7, 8)));
371 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
372 gint length, const char* value, const char *format, ...);
375 /* Add a FT_BOOLEAN to a proto_tree */
377 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
378 gint length, guint32 value);
381 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
382 gint length, guint32 value);
386 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
387 gint length, guint32 value, const char *format, ...)
388 __attribute__((format (printf, 7, 8)));
391 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
392 gint length, guint32 value, const char *format, ...);
395 /* Add a FT_DOUBLE to a proto_tree */
397 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
398 gint length, double value);
401 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
402 gint length, double value);
406 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
407 gint length, double value, const char *format, ...)
408 __attribute__((format (printf, 7, 8)));
411 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
412 gint length, double value, const char *format, ...);
415 /* Add any FT_UINT* to a proto_tree */
417 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
418 gint length, guint32 value);
421 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
422 gint length, guint32 value);
426 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
427 gint length, guint32 value, const char *format, ...)
428 __attribute__((format (printf, 7, 8)));
431 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
432 gint length, guint32 value, const char *format, ...);
435 /* Add any FT_INT* to a proto_tree */
437 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
438 gint length, gint32 value);
441 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
442 gint length, gint32 value);
446 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
447 gint length, gint32 value, const char *format, ...)
448 __attribute__((format (printf, 7, 8)));
451 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
452 gint length, gint32 value, const char *format, ...);
456 /* Add a text-only node to the proto_tree */
459 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
460 ...) __attribute__((format (printf, 5, 6)));
463 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
468 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
469 gint length, const char *format, va_list ap);
472 /* Useful for quick debugging. Also sends string to STDOUT, so don't
473 * leave call to this function in production code. */
476 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
477 __attribute__((format (printf, 2, 3)));
480 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
484 proto_item_fill_label(field_info *fi, gchar *label_str);
487 proto_tree_set_visible(proto_tree *tree, gboolean visible);
489 /* Returns number of items (protocols or header fields) registered. */
490 extern int proto_registrar_n(void);
492 /* Returns char* to name for item # n (0-indexed) */
493 extern char* proto_registrar_get_name(int n);
495 /* Returns char* to abbrev for item # n (0-indexed) */
496 extern char* proto_registrar_get_abbrev(int n);
498 /* get the header field information based upon a field or protocol id */
499 extern header_field_info* proto_registrar_get_nth(int hfindex);
501 /* Returns enum ftenum for item # n */
502 extern int proto_registrar_get_ftype(int n);
504 /* Returns parent protocol for item # n.
505 * Returns -1 if item _is_ a protocol */
506 extern int proto_registrar_get_parent(int n);
508 /* Is item #n a protocol? */
509 extern gboolean proto_registrar_is_protocol(int n);
511 /* Is item #n decoding enabled ? */
512 extern gboolean proto_is_protocol_enabled(int proto_id);
514 /* Can item #n decoding be disabled? */
515 extern gboolean proto_can_disable_protocol(int proto_id);
517 /* Routines to use to iterate over the protocols; they return the item
518 * number of the protocol in question, and keep state in "*cookie". */
519 extern int proto_get_first_protocol(void **cookie);
520 extern int proto_get_next_protocol(void **cookie);
522 /* Given a protocol's filter_name, return it's proto_id */
523 extern int proto_get_id_by_filter_name(gchar* filter_name);
525 /* Given a protocol's item number, return its name. */
526 extern char *proto_get_protocol_name(int n);
528 /* Given a protocol's item number, return its short name. */
529 extern char *proto_get_protocol_short_name(int proto_id);
531 /* Given a protocol's item number, return its filter name. */
532 extern char *proto_get_protocol_filter_name(int proto_id);
534 /* Enable / Disable protocol */
535 extern void proto_set_decoding(int proto_id, gboolean enabled);
537 /* Disable disabling of protocol */
538 extern void proto_set_cant_disable(int proto_id);
540 /* Get length of registered field according to field type.
541 * 0 means undeterminable at registration time.
542 * -1 means unknown field */
543 extern gint proto_registrar_get_length(int n);
545 /* Checks for existence any protocol or field within a tree.
546 * "Protocols" are assumed to be a child of the [empty] root node.
547 * TRUE = found, FALSE = not found */
548 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
550 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
552 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
554 /* Dumps a glossary of the protocol and field registrations to STDOUT */
555 extern void proto_registrar_dump(void);
557 /* Is the parsing being done for a visible proto_tree or an invisible one?
558 * By setting this correctly, the proto_tree creation is sped up by not
559 * having to call vsnprintf and copy strings around.
561 extern gboolean proto_tree_is_visible;
563 /* Points to the first element of an array of Booleans, indexed by
564 a subtree item type; that array element is TRUE if subtrees of
565 an item of that type are to be expanded.
567 ETT_NONE is reserved for unregistered subtree types. */
569 extern gboolean *tree_is_expanded;
571 /* Number of elements in that array. */
572 extern int num_tree_types;
574 /* glib doesn't have g_ptr_array_len of all things!*/
575 #ifndef g_ptr_array_len
576 #define g_ptr_array_len(a) ((a)->len)
580 hfinfo_bitwidth(header_field_info *hfinfo);
583 * Returns TRUE if we can do a "match selected" on the field, FALSE
587 proto_can_match_selected(field_info *finfo);
590 proto_alloc_dfilter_string(field_info *finfo, guint8 *pd);
593 proto_find_field_from_offset(proto_tree *tree, guint offset, gchar *ds_name);