2 * Definitions for protocol display
4 * $Id: proto.h,v 1.48 2003/11/26 12:22:22 sahlberg 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)
54 typedef struct _protocol protocol_t;
56 /* check protocol activation */
57 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) { \
58 if (!proto_is_protocol_enabled(find_protocol_by_id(index))) { \
59 call_dissector(x_handle,tvb, pinfo, tree); \
71 typedef struct _header_field_info header_field_info;
73 /* information describing a header field */
74 struct _header_field_info {
75 /* ---------- set by dissector --------- */
79 int display; /* for integers only, so far. Base */
80 const void *strings; /* val_string or true_false_string */
82 char *blurb; /* Brief description of field. */
84 /* ---------- set by proto routines --------- */
85 int id; /* Field ID */
86 int parent; /* parent protocol */
87 int bitshift; /* bits to shift */
88 header_field_info *same_name_next; /* Link to next hfinfo with same abbrev*/
89 header_field_info *same_name_prev; /* Link to previous hfinfo with same abbrev*/
93 * HFILL initializes all the "set by proto routines" fields in a
94 * "header_field_info"; if new fields are added or removed, it should
95 * be changed as necessary.
97 #define HFILL 0, 0, 0, NULL, NULL
99 /* Used when registering many fields at once */
100 typedef struct hf_register_info {
101 int *p_id; /* pointer to int; written to by register() function */
102 header_field_info hfinfo;
106 typedef struct _item_label_t {
107 struct _item_label_t *next;
108 char representation[ITEM_LABEL_LENGTH];
111 /* Contains the field information for the proto_item. */
112 typedef struct field_info {
114 /* the next pointer is only used when keeping track of
115 * free (unallocated) field_infos. Such field_info's
116 * are never associated with a header_field_info.
118 struct field_info *next;
119 header_field_info *hfinfo;
123 gint tree_type; /* ETT_* */
124 item_label_t *rep; /* string for GUI tree */
127 tvbuff_t *ds_tvb; /* data source tvbuff */
130 /* One of these exists for the entire protocol tree. Each proto_node
131 * in the protocol tree points to the same copy. */
133 GHashTable *interesting_hfids;
137 /* Each GNode (proto_tree, proto_item) points to one of
139 typedef struct _proto_node {
140 struct _proto_node *next;
142 tree_data_t *tree_data;
145 typedef GNode proto_tree;
146 typedef GNode proto_item;
148 /* Retrieve the proto_node from a GNode. */
149 #define GNODE_PNODE(t) ((proto_node*)((GNode*)(t))->data)
151 /* Retrieve the field_info from a proto_item */
152 #define PITEM_FINFO(t) (GNODE_PNODE(t)->finfo)
154 /* Retrieve the tree_data_t from a proto_tree */
155 #define PTREE_DATA(t) (GNODE_PNODE(t)->tree_data)
157 /* Sets up memory used by proto routines. Called at program startup */
158 extern void proto_init(const char *plugin_dir,
159 void (register_all_protocols)(void), void (register_all_handoffs)(void));
161 /* Frees memory used by proto routines. Called at program shutdown */
162 extern void proto_cleanup(void);
164 /* Set text of proto_item after having already been created. */
166 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
167 __attribute__((format (printf, 2, 3)));
169 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
172 /* Append to text of proto_item after having already been created. */
174 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
175 __attribute__((format (printf, 2, 3)));
177 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
180 /* Set length of proto_item after having already been created. */
181 extern void proto_item_set_len(proto_item *ti, gint length);
184 * Sets the length of the item based on its start and on the specified
185 * offset, which is the offset past the end of the item; as the start
186 * in the item is relative to the beginning of the data source tvbuff,
187 * we need to pass in a tvbuff - the end offset is relative to the beginning
190 extern void proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end);
192 /* Get length of proto_item. Useful after using proto_tree_add_item()
193 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
194 extern int proto_item_get_len(proto_item *ti);
196 /* Creates new proto_tree root */
197 extern proto_tree* proto_tree_create_root(void);
199 /* Mark a field/protocol ID as "interesting". */
201 proto_tree_prime_hfid(proto_tree *tree, int hfid);
203 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
204 extern void proto_tree_free(proto_tree *tree);
206 /* Create a subtree under an existing item; returns tree pointer */
207 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
210 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
211 struct _value_string* vals);
214 proto_register_protocol(char *name, char *short_name, char *filter_name);
217 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
220 proto_register_subtree_array(gint **indices, int num_indices);
222 /* Add an item to a proto_tree, using the text label registered to that item;
223 the item is extracted from the tvbuff handed to it. */
225 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
226 gint start, gint length, gboolean little_endian);
229 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
230 gint start, gint length, gboolean little_endian);
232 /* Add a FT_NONE to a proto_tree */
235 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
236 gint length, const char *format, ...)
237 __attribute__((format (printf, 6, 7)));
240 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
241 gint length, const char *format, ...);
244 /* Add a FT_PROTOCOL to a proto_tree */
247 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
248 gint length, const char *format, ...)
249 __attribute__((format (printf, 6, 7)));
252 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
253 gint length, const char *format, ...);
256 /* Add a FT_BYTES to a proto_tree */
258 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
259 gint length, const guint8* start_ptr);
262 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
263 gint length, const guint8* start_ptr);
267 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
268 gint length, const guint8* start_ptr, const char *format, ...)
269 __attribute__((format (printf, 7, 8)));
272 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
273 gint length, const guint8* start_ptr, const char *format, ...);
276 /* Add a FT_*TIME to a proto_tree */
278 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
279 gint length, nstime_t* value_ptr);
282 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
283 gint length, nstime_t* value_ptr);
287 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
288 gint length, nstime_t* value_ptr, const char *format, ...)
289 __attribute__((format (printf, 7, 8)));
292 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
293 gint length, nstime_t* value_ptr, const char *format, ...);
296 /* Add a FT_IPXNET to a proto_tree */
298 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
299 gint length, guint32 value);
302 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
303 gint length, guint32 value);
307 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
308 gint length, guint32 value, const char *format, ...)
309 __attribute__((format (printf, 7, 8)));
312 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
313 gint length, guint32 value, const char *format, ...);
316 /* Add a FT_IPv4 to a proto_tree */
318 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
319 gint length, guint32 value);
322 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
323 gint length, guint32 value);
327 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
328 gint length, guint32 value, const char *format, ...)
329 __attribute__((format (printf, 7, 8)));
332 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
333 gint length, guint32 value, const char *format, ...);
336 /* Add a FT_IPv6 to a proto_tree */
338 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
339 gint length, const guint8* value_ptr);
342 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
343 gint length, const guint8* value_ptr);
347 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
348 gint length, const guint8* value_ptr, const char *format, ...)
349 __attribute__((format (printf, 7, 8)));
352 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
353 gint length, const guint8* value_ptr, const char *format, ...);
356 /* Add a FT_ETHER to a proto_tree */
358 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
359 gint length, const guint8* value);
362 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
363 gint length, const guint8* value);
367 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
368 gint length, const guint8* value, const char *format, ...)
369 __attribute__((format (printf, 7, 8)));
372 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
373 gint length, const guint8* value, const char *format, ...);
376 /* Add a FT_STRING to a proto_tree */
378 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
379 gint length, const char* value);
382 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
383 gint length, const char* value);
387 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
388 gint length, const char* value, const char *format, ...)
389 __attribute__((format (printf, 7, 8)));
392 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
393 gint length, const char* value, const char *format, ...);
397 proto_item_append_string(proto_item *pi, const char *str);
399 /* Add a FT_BOOLEAN to a proto_tree */
401 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
402 gint length, guint32 value);
405 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
406 gint length, guint32 value);
410 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
411 gint length, guint32 value, const char *format, ...)
412 __attribute__((format (printf, 7, 8)));
415 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
416 gint length, guint32 value, const char *format, ...);
419 /* Add a FT_FLOAT to a proto_tree */
421 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
422 gint length, float value);
425 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
426 gint length, float value);
430 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
431 gint length, float value, const char *format, ...)
432 __attribute__((format (printf, 7, 8)));
435 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
436 gint length, float value, const char *format, ...);
439 /* Add a FT_DOUBLE to a proto_tree */
441 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
442 gint length, double value);
445 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
446 gint length, double value);
450 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
451 gint length, double value, const char *format, ...)
452 __attribute__((format (printf, 7, 8)));
455 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
456 gint length, double value, const char *format, ...);
459 /* Add any FT_UINT* to a proto_tree */
461 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
462 gint length, guint32 value);
465 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
466 gint length, guint32 value);
470 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
471 gint length, guint32 value, const char *format, ...)
472 __attribute__((format (printf, 7, 8)));
475 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
476 gint length, guint32 value, const char *format, ...);
479 /* Add any FT_INT* to a proto_tree */
481 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
482 gint length, gint32 value);
485 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
486 gint length, gint32 value);
490 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
491 gint length, gint32 value, const char *format, ...)
492 __attribute__((format (printf, 7, 8)));
495 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
496 gint length, gint32 value, const char *format, ...);
500 /* Add a text-only node to the proto_tree */
503 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
504 ...) __attribute__((format (printf, 5, 6)));
507 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
512 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
513 gint length, const char *format, va_list ap);
516 /* Useful for quick debugging. Also sends string to STDOUT, so don't
517 * leave call to this function in production code. */
520 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
521 __attribute__((format (printf, 2, 3)));
524 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
528 proto_item_fill_label(field_info *fi, gchar *label_str);
531 proto_tree_set_visible(proto_tree *tree, gboolean visible);
533 /* Returns number of items (protocols or header fields) registered. */
534 extern int proto_registrar_n(void);
536 /* Returns char* to name for item # n (0-indexed) */
537 extern char* proto_registrar_get_name(int n);
539 /* Returns char* to abbrev for item # n (0-indexed) */
540 extern char* proto_registrar_get_abbrev(int n);
542 /* get the header field information based upon a field or protocol id */
543 extern header_field_info* proto_registrar_get_nth(guint hfindex);
545 /* get the header field information based upon a field name */
546 extern header_field_info* proto_registrar_get_byname(char *field_name);
548 /* Returns enum ftenum for item # n */
549 extern int proto_registrar_get_ftype(int n);
551 /* Returns parent protocol for item # n.
552 * Returns -1 if item _is_ a protocol */
553 extern int proto_registrar_get_parent(int n);
555 /* Is item #n a protocol? */
556 extern gboolean proto_registrar_is_protocol(int n);
558 /* Is protocol's decoding enabled ? */
559 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
561 /* Can item #n decoding be disabled? */
562 extern gboolean proto_can_disable_protocol(int proto_id);
564 /* Routines to use to iterate over the protocols and their fields;
565 * they return the item number of the protocol in question or the
566 * appropriate hfinfo pointer, and keep state in "*cookie". */
567 extern int proto_get_first_protocol(void **cookie);
568 extern int proto_get_next_protocol(void **cookie);
569 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
570 extern header_field_info *proto_get_next_protocol_field(void **cookle);
572 /* Given a protocol's "protocol_t", return its proto_id */
573 extern int proto_get_id(protocol_t *protocol);
575 /* Given a protocol's filter_name, return its proto_id */
576 extern int proto_get_id_by_filter_name(gchar* filter_name);
578 /* Given a protocol's item number, find the "protocol_t" structure for it */
579 extern protocol_t *find_protocol_by_id(int proto_id);
581 /* Given a protocol's item number, return its name. */
582 extern char *proto_get_protocol_name(int n);
584 /* Given a protocol's "protocol_t", return its short name. */
585 extern char *proto_get_protocol_short_name(protocol_t *protocol);
587 /* Given a protocol's item number, return its filter name. */
588 extern char *proto_get_protocol_filter_name(int proto_id);
590 /* Enable / Disable protocol */
591 extern void proto_set_decoding(int proto_id, gboolean enabled);
593 /* Disable disabling of protocol */
594 extern void proto_set_cant_disable(int proto_id);
596 /* Get length of registered field according to field type.
597 * 0 means undeterminable at registration time.
598 * -1 means unknown field */
599 extern gint proto_registrar_get_length(int n);
601 /* Checks for existence any protocol or field within a tree.
602 * "Protocols" are assumed to be a child of the [empty] root node.
603 * TRUE = found, FALSE = not found */
604 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
606 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
608 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
610 /* Dumps a glossary of the protocol registrations to STDOUT */
611 extern void proto_registrar_dump_protocols(void);
613 /* Dumps a glossary of the protocol and field registrations to STDOUT */
614 extern void proto_registrar_dump_fields(void);
616 /* Points to the first element of an array of Booleans, indexed by
617 a subtree item type; that array element is TRUE if subtrees of
618 an item of that type are to be expanded. */
619 extern gboolean *tree_is_expanded;
621 /* Number of elements in that array. */
622 extern int num_tree_types;
624 /* glib doesn't have g_ptr_array_len of all things!*/
625 #ifndef g_ptr_array_len
626 #define g_ptr_array_len(a) ((a)->len)
630 hfinfo_bitwidth(header_field_info *hfinfo);
635 * Returns TRUE if we can do a "match selected" on the field, FALSE
639 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
642 proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt);
645 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);