2 * Definitions for protocol display
4 * $Id: proto.h,v 1.37 2002/11/28 01:46:12 guy 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.
39 #include "ftypes/ftypes.h"
43 #define ITEM_LABEL_LENGTH 240
45 /* In order to make a const value_string[] look like a value_string*, I
47 #define VALS(x) (const struct _value_string*)(x)
49 /* ... and similarly, */
50 #define TFS(x) (const struct true_false_string*)(x)
52 /* check protocol activation */
53 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) { \
54 if (!proto_is_protocol_enabled(index)) { \
55 call_dissector(x_handle,tvb, pinfo, tree); \
68 typedef struct _header_field_info header_field_info;
70 /* information describing a header field */
71 struct _header_field_info {
72 /* ---------- set by dissector --------- */
76 int display; /* for integers only, so far. Base */
77 const void *strings; /* val_string or true_false_string */
79 char *blurb; /* Brief description of field. */
81 /* ---------- set by proto routines --------- */
82 int id; /* Field ID */
83 int parent; /* parent protocol */
84 int bitshift; /* bits to shift */
85 header_field_info *same_name_next; /* Link to next hfinfo with same abbrev*/
86 header_field_info *same_name_prev; /* Link to previous hfinfo with same abbrev*/
90 * HFILL initializes all the "set by proto routines" fields in a
91 * "header_field_info"; if new fields are added or removed, it should
92 * be changed as necessary.
94 #define HFILL 0, 0, 0, NULL, NULL
96 /* Used when registering many fields at once */
97 typedef struct hf_register_info {
98 int *p_id; /* pointer to int; written to by register() function */
99 header_field_info hfinfo;
103 /* Contains the field information for the proto_item. */
104 typedef struct field_info {
105 header_field_info *hfinfo;
108 gint tree_type; /* ETT_* */
109 char *representation; /* for GUI tree */
112 tvbuff_t *ds_tvb; /* data source tvbuff */
115 /* One of these exists for the entire protocol tree. Each proto_node
116 * in the protocol tree points to the same copy. */
118 GHashTable *interesting_hfids;
122 /* Each GNode (proto_tree, proto_item) points to one of
126 tree_data_t *tree_data;
129 typedef GNode proto_tree;
130 typedef GNode proto_item;
132 /* Retrieve the proto_node from a GNode. */
133 #define GNODE_PNODE(t) ((proto_node*)((GNode*)(t))->data)
135 /* Retrieve the field_info from a proto_item */
136 #define PITEM_FINFO(t) (GNODE_PNODE(t)->finfo)
138 /* Retrieve the tree_data_t from a proto_tree */
139 #define PTREE_DATA(t) (GNODE_PNODE(t)->tree_data)
141 /* Sets up memory used by proto routines. Called at program startup */
142 extern void proto_init(const char *plugin_dir,
143 void (register_all_protocols)(void), void (register_all_handoffs)(void));
145 /* Frees memory used by proto routines. Called at program shutdown */
146 extern void proto_cleanup(void);
148 /* Set text of proto_item after having already been created. */
150 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
151 __attribute__((format (printf, 2, 3)));
153 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
156 /* Append to text of proto_item after having already been created. */
158 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
159 __attribute__((format (printf, 2, 3)));
161 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
164 /* Set length of proto_item after having already been created. */
165 extern void proto_item_set_len(proto_item *ti, gint length);
167 /* Get length of proto_item. Useful after using proto_tree_add_item()
168 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
169 extern int proto_item_get_len(proto_item *ti);
171 /* Creates new proto_tree root */
172 extern proto_tree* proto_tree_create_root(void);
174 /* Mark a field/protocol ID as "interesting". */
176 proto_tree_prime_hfid(proto_tree *tree, int hfid);
178 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
179 extern void proto_tree_free(proto_tree *tree);
181 /* Create a subtree under an existing item; returns tree pointer */
182 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
185 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
186 struct _value_string* vals);
189 proto_register_protocol(char *name, char *short_name, char *filter_name);
192 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
195 proto_register_subtree_array(gint **indices, int num_indices);
197 /* Add an item to a proto_tree, using the text label registered to that item;
198 the item is extracted from the tvbuff handed to it. */
200 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
201 gint start, gint length, gboolean little_endian);
204 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
205 gint start, gint length, gboolean little_endian);
207 /* Add a FT_NONE to a proto_tree */
210 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
211 gint length, const char *format, ...)
212 __attribute__((format (printf, 6, 7)));
215 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
216 gint length, const char *format, ...);
219 /* Add a FT_PROTOCOL to a proto_tree */
222 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
223 gint length, const char *format, ...)
224 __attribute__((format (printf, 6, 7)));
227 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
228 gint length, const char *format, ...);
231 /* Add a FT_BYTES to a proto_tree */
233 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
234 gint length, const guint8* start_ptr);
237 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
238 gint length, const guint8* start_ptr);
242 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
243 gint length, const guint8* start_ptr, const char *format, ...)
244 __attribute__((format (printf, 7, 8)));
247 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
248 gint length, const guint8* start_ptr, const char *format, ...);
251 /* Add a FT_*TIME to a proto_tree */
253 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
254 gint length, nstime_t* value_ptr);
257 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
258 gint length, nstime_t* value_ptr);
262 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
263 gint length, nstime_t* value_ptr, const char *format, ...)
264 __attribute__((format (printf, 7, 8)));
267 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
268 gint length, nstime_t* value_ptr, const char *format, ...);
271 /* Add a FT_IPXNET to a proto_tree */
273 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
274 gint length, guint32 value);
277 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
278 gint length, guint32 value);
282 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
283 gint length, guint32 value, const char *format, ...)
284 __attribute__((format (printf, 7, 8)));
287 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
288 gint length, guint32 value, const char *format, ...);
291 /* Add a FT_IPv4 to a proto_tree */
293 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
294 gint length, guint32 value);
297 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
298 gint length, guint32 value);
302 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
303 gint length, guint32 value, const char *format, ...)
304 __attribute__((format (printf, 7, 8)));
307 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
308 gint length, guint32 value, const char *format, ...);
311 /* Add a FT_IPv6 to a proto_tree */
313 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
314 gint length, const guint8* value_ptr);
317 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
318 gint length, const guint8* value_ptr);
322 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
323 gint length, const guint8* value_ptr, const char *format, ...)
324 __attribute__((format (printf, 7, 8)));
327 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
328 gint length, const guint8* value_ptr, const char *format, ...);
331 /* Add a FT_ETHER to a proto_tree */
333 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
334 gint length, const guint8* value);
337 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
338 gint length, const guint8* value);
342 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
343 gint length, const guint8* value, const char *format, ...)
344 __attribute__((format (printf, 7, 8)));
347 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
348 gint length, const guint8* value, const char *format, ...);
351 /* Add a FT_STRING to a proto_tree */
353 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
354 gint length, const char* value);
357 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
358 gint length, const char* value);
362 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
363 gint length, const char* value, const char *format, ...)
364 __attribute__((format (printf, 7, 8)));
367 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
368 gint length, const char* value, const char *format, ...);
371 /* Add a FT_BOOLEAN to a proto_tree */
373 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
374 gint length, guint32 value);
377 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
378 gint length, guint32 value);
382 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
383 gint length, guint32 value, const char *format, ...)
384 __attribute__((format (printf, 7, 8)));
387 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
388 gint length, guint32 value, const char *format, ...);
391 /* Add a FT_FLOAT to a proto_tree */
393 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
394 gint length, float value);
397 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
398 gint length, float value);
402 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
403 gint length, float value, const char *format, ...)
404 __attribute__((format (printf, 7, 8)));
407 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
408 gint length, float value, const char *format, ...);
411 /* Add a FT_DOUBLE to a proto_tree */
413 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
414 gint length, double value);
417 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
418 gint length, double value);
422 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
423 gint length, double value, const char *format, ...)
424 __attribute__((format (printf, 7, 8)));
427 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
428 gint length, double value, const char *format, ...);
431 /* Add any FT_UINT* to a proto_tree */
433 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
434 gint length, guint32 value);
437 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
438 gint length, guint32 value);
442 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
443 gint length, guint32 value, const char *format, ...)
444 __attribute__((format (printf, 7, 8)));
447 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
448 gint length, guint32 value, const char *format, ...);
451 /* Add any FT_INT* to a proto_tree */
453 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
454 gint length, gint32 value);
457 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
458 gint length, gint32 value);
462 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
463 gint length, gint32 value, const char *format, ...)
464 __attribute__((format (printf, 7, 8)));
467 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
468 gint length, gint32 value, const char *format, ...);
472 /* Add a text-only node to the proto_tree */
475 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
476 ...) __attribute__((format (printf, 5, 6)));
479 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
484 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
485 gint length, const char *format, va_list ap);
488 /* Useful for quick debugging. Also sends string to STDOUT, so don't
489 * leave call to this function in production code. */
492 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
493 __attribute__((format (printf, 2, 3)));
496 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
500 proto_item_fill_label(field_info *fi, gchar *label_str);
503 proto_tree_set_visible(proto_tree *tree, gboolean visible);
505 /* Returns number of items (protocols or header fields) registered. */
506 extern int proto_registrar_n(void);
508 /* Returns char* to name for item # n (0-indexed) */
509 extern char* proto_registrar_get_name(int n);
511 /* Returns char* to abbrev for item # n (0-indexed) */
512 extern char* proto_registrar_get_abbrev(int n);
514 /* get the header field information based upon a field or protocol id */
515 extern header_field_info* proto_registrar_get_nth(int hfindex);
517 /* get the header field information based upon a field name */
518 extern header_field_info* proto_registrar_get_byname(char *field_name);
520 /* Returns enum ftenum for item # n */
521 extern int proto_registrar_get_ftype(int n);
523 /* Returns parent protocol for item # n.
524 * Returns -1 if item _is_ a protocol */
525 extern int proto_registrar_get_parent(int n);
527 /* Is item #n a protocol? */
528 extern gboolean proto_registrar_is_protocol(int n);
530 /* Is item #n decoding enabled ? */
531 extern gboolean proto_is_protocol_enabled(int proto_id);
533 /* Can item #n decoding be disabled? */
534 extern gboolean proto_can_disable_protocol(int proto_id);
536 /* Routines to use to iterate over the protocols; they return the item
537 * number of the protocol in question, and keep state in "*cookie". */
538 extern int proto_get_first_protocol(void **cookie);
539 extern int proto_get_next_protocol(void **cookie);
541 /* Given a protocol's filter_name, return it's proto_id */
542 extern int proto_get_id_by_filter_name(gchar* filter_name);
544 /* Given a protocol's item number, return its name. */
545 extern char *proto_get_protocol_name(int n);
547 /* Given a protocol's item number, return its short name. */
548 extern char *proto_get_protocol_short_name(int proto_id);
550 /* Given a protocol's item number, return its filter name. */
551 extern char *proto_get_protocol_filter_name(int proto_id);
553 /* Enable / Disable protocol */
554 extern void proto_set_decoding(int proto_id, gboolean enabled);
556 /* Disable disabling of protocol */
557 extern void proto_set_cant_disable(int proto_id);
559 /* Get length of registered field according to field type.
560 * 0 means undeterminable at registration time.
561 * -1 means unknown field */
562 extern gint proto_registrar_get_length(int n);
564 /* Checks for existence any protocol or field within a tree.
565 * "Protocols" are assumed to be a child of the [empty] root node.
566 * TRUE = found, FALSE = not found */
567 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
569 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
571 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
573 /* Dumps a glossary of the protocol registrations to STDOUT */
574 extern void proto_registrar_dump_protocols(void);
576 /* Dumps a glossary of the protocol and field registrations to STDOUT */
577 extern void proto_registrar_dump_fields(void);
579 /* Points to the first element of an array of Booleans, indexed by
580 a subtree item type; that array element is TRUE if subtrees of
581 an item of that type are to be expanded. */
582 extern gboolean *tree_is_expanded;
584 /* Number of elements in that array. */
585 extern int num_tree_types;
587 /* glib doesn't have g_ptr_array_len of all things!*/
588 #ifndef g_ptr_array_len
589 #define g_ptr_array_len(a) ((a)->len)
593 hfinfo_bitwidth(header_field_info *hfinfo);
596 * Returns TRUE if we can do a "match selected" on the field, FALSE
600 proto_can_match_selected(field_info *finfo);
603 proto_alloc_dfilter_string(field_info *finfo, guint8 *pd);
606 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);