2 * Definitions for protocol display
4 * $Id: proto.h,v 1.50 2003/12/03 08:53:36 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)
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 char representation[ITEM_LABEL_LENGTH];
110 /* Contains the field information for the proto_item. */
111 typedef struct field_info {
113 /* the next pointer is only used when keeping track of
114 * free (unallocated) field_infos. Such field_info's
115 * are never associated with a header_field_info.
117 struct field_info *next;
118 header_field_info *hfinfo;
122 gint tree_type; /* ETT_* */
123 item_label_t *rep; /* string for GUI tree */
125 tvbuff_t *ds_tvb; /* data source tvbuff */
129 /* One of these exists for the entire protocol tree. Each proto_node
130 * in the protocol tree points to the same copy. */
132 GHashTable *interesting_hfids;
136 /* Each GNode (proto_tree, proto_item) points to one of
138 typedef struct _proto_node {
140 tree_data_t *tree_data;
143 typedef GNode proto_tree;
144 typedef GNode proto_item;
146 /* Retrieve the proto_node from a GNode. */
147 #define GNODE_PNODE(t) ((proto_node*)((GNode*)(t))->data)
149 /* Retrieve the field_info from a proto_item */
150 #define PITEM_FINFO(t) (GNODE_PNODE(t)->finfo)
152 /* Retrieve the tree_data_t from a proto_tree */
153 #define PTREE_DATA(t) (GNODE_PNODE(t)->tree_data)
155 /* Sets up memory used by proto routines. Called at program startup */
156 extern void proto_init(const char *plugin_dir,
157 void (register_all_protocols)(void), void (register_all_handoffs)(void));
159 /* Frees memory used by proto routines. Called at program shutdown */
160 extern void proto_cleanup(void);
162 /* Set text of proto_item after having already been created. */
164 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
165 __attribute__((format (printf, 2, 3)));
167 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
170 /* Append to text of proto_item after having already been created. */
172 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
173 __attribute__((format (printf, 2, 3)));
175 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
178 /* Set length of proto_item after having already been created. */
179 extern void proto_item_set_len(proto_item *ti, gint length);
182 * Sets the length of the item based on its start and on the specified
183 * offset, which is the offset past the end of the item; as the start
184 * in the item is relative to the beginning of the data source tvbuff,
185 * we need to pass in a tvbuff - the end offset is relative to the beginning
188 extern void proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end);
190 /* Get length of proto_item. Useful after using proto_tree_add_item()
191 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
192 extern int proto_item_get_len(proto_item *ti);
194 /* Creates new proto_tree root */
195 extern proto_tree* proto_tree_create_root(void);
197 /* Mark a field/protocol ID as "interesting". */
199 proto_tree_prime_hfid(proto_tree *tree, int hfid);
201 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
202 extern void proto_tree_free(proto_tree *tree);
204 /* Create a subtree under an existing item; returns tree pointer */
205 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
208 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
209 struct _value_string* vals);
212 proto_register_protocol(char *name, char *short_name, char *filter_name);
215 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
218 proto_register_subtree_array(gint **indices, int num_indices);
220 /* Add an item to a proto_tree, using the text label registered to that item;
221 the item is extracted from the tvbuff handed to it. */
223 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
224 gint start, gint length, gboolean little_endian);
227 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
228 gint start, gint length, gboolean little_endian);
230 /* Add a FT_NONE to a proto_tree */
233 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
234 gint length, const char *format, ...)
235 __attribute__((format (printf, 6, 7)));
238 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
239 gint length, const char *format, ...);
242 /* Add a FT_PROTOCOL to a proto_tree */
245 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
246 gint length, const char *format, ...)
247 __attribute__((format (printf, 6, 7)));
250 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
251 gint length, const char *format, ...);
254 /* Add a FT_BYTES to a proto_tree */
256 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
257 gint length, const guint8* start_ptr);
260 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
261 gint length, const guint8* start_ptr);
265 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
266 gint length, const guint8* start_ptr, const char *format, ...)
267 __attribute__((format (printf, 7, 8)));
270 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
271 gint length, const guint8* start_ptr, const char *format, ...);
274 /* Add a FT_*TIME to a proto_tree */
276 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
277 gint length, nstime_t* value_ptr);
280 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
281 gint length, nstime_t* value_ptr);
285 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
286 gint length, nstime_t* value_ptr, const char *format, ...)
287 __attribute__((format (printf, 7, 8)));
290 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
291 gint length, nstime_t* value_ptr, const char *format, ...);
294 /* Add a FT_IPXNET to a proto_tree */
296 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
297 gint length, guint32 value);
300 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
301 gint length, guint32 value);
305 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
306 gint length, guint32 value, const char *format, ...)
307 __attribute__((format (printf, 7, 8)));
310 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
311 gint length, guint32 value, const char *format, ...);
314 /* Add a FT_IPv4 to a proto_tree */
316 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
317 gint length, guint32 value);
320 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
321 gint length, guint32 value);
325 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
326 gint length, guint32 value, const char *format, ...)
327 __attribute__((format (printf, 7, 8)));
330 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
331 gint length, guint32 value, const char *format, ...);
334 /* Add a FT_IPv6 to a proto_tree */
336 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
337 gint length, const guint8* value_ptr);
340 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
341 gint length, const guint8* value_ptr);
345 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
346 gint length, const guint8* value_ptr, const char *format, ...)
347 __attribute__((format (printf, 7, 8)));
350 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
351 gint length, const guint8* value_ptr, const char *format, ...);
354 /* Add a FT_ETHER to a proto_tree */
356 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
357 gint length, const guint8* value);
360 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
361 gint length, const guint8* value);
365 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
366 gint length, const guint8* value, const char *format, ...)
367 __attribute__((format (printf, 7, 8)));
370 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
371 gint length, const guint8* value, const char *format, ...);
374 /* Add a FT_STRING to a proto_tree */
376 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
377 gint length, const char* value);
380 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
381 gint length, const char* value);
385 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
386 gint length, const char* value, const char *format, ...)
387 __attribute__((format (printf, 7, 8)));
390 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
391 gint length, const char* value, const char *format, ...);
395 proto_item_append_string(proto_item *pi, const char *str);
397 /* Add a FT_BOOLEAN to a proto_tree */
399 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
400 gint length, guint32 value);
403 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
404 gint length, guint32 value);
408 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
409 gint length, guint32 value, const char *format, ...)
410 __attribute__((format (printf, 7, 8)));
413 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
414 gint length, guint32 value, const char *format, ...);
417 /* Add a FT_FLOAT to a proto_tree */
419 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
420 gint length, float value);
423 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
424 gint length, float value);
428 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
429 gint length, float value, const char *format, ...)
430 __attribute__((format (printf, 7, 8)));
433 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
434 gint length, float value, const char *format, ...);
437 /* Add a FT_DOUBLE to a proto_tree */
439 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
440 gint length, double value);
443 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
444 gint length, double value);
448 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
449 gint length, double value, const char *format, ...)
450 __attribute__((format (printf, 7, 8)));
453 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
454 gint length, double value, const char *format, ...);
457 /* Add any FT_UINT* to a proto_tree */
459 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
460 gint length, guint32 value);
463 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
464 gint length, guint32 value);
468 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
469 gint length, guint32 value, const char *format, ...)
470 __attribute__((format (printf, 7, 8)));
473 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
474 gint length, guint32 value, const char *format, ...);
477 /* Add any FT_INT* to a proto_tree */
479 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
480 gint length, gint32 value);
483 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
484 gint length, gint32 value);
488 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
489 gint length, gint32 value, const char *format, ...)
490 __attribute__((format (printf, 7, 8)));
493 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
494 gint length, gint32 value, const char *format, ...);
498 /* Add a text-only node to the proto_tree */
501 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
502 ...) __attribute__((format (printf, 5, 6)));
505 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
510 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
511 gint length, const char *format, va_list ap);
514 /* Useful for quick debugging. Also sends string to STDOUT, so don't
515 * leave call to this function in production code. */
518 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
519 __attribute__((format (printf, 2, 3)));
522 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
526 proto_item_fill_label(field_info *fi, gchar *label_str);
529 proto_tree_set_visible(proto_tree *tree, gboolean visible);
531 /* Returns number of items (protocols or header fields) registered. */
532 extern int proto_registrar_n(void);
534 /* Returns char* to name for item # n (0-indexed) */
535 extern char* proto_registrar_get_name(int n);
537 /* Returns char* to abbrev for item # n (0-indexed) */
538 extern char* proto_registrar_get_abbrev(int n);
540 /* get the header field information based upon a field or protocol id */
541 extern header_field_info* proto_registrar_get_nth(guint hfindex);
543 /* get the header field information based upon a field name */
544 extern header_field_info* proto_registrar_get_byname(char *field_name);
546 /* Returns enum ftenum for item # n */
547 extern int proto_registrar_get_ftype(int n);
549 /* Returns parent protocol for item # n.
550 * Returns -1 if item _is_ a protocol */
551 extern int proto_registrar_get_parent(int n);
553 /* Is item #n a protocol? */
554 extern gboolean proto_registrar_is_protocol(int n);
556 /* Is protocol's decoding enabled ? */
557 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
559 /* Can item #n decoding be disabled? */
560 extern gboolean proto_can_disable_protocol(int proto_id);
562 /* Routines to use to iterate over the protocols and their fields;
563 * they return the item number of the protocol in question or the
564 * appropriate hfinfo pointer, and keep state in "*cookie". */
565 extern int proto_get_first_protocol(void **cookie);
566 extern int proto_get_next_protocol(void **cookie);
567 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
568 extern header_field_info *proto_get_next_protocol_field(void **cookle);
570 /* Given a protocol's "protocol_t", return its proto_id */
571 extern int proto_get_id(protocol_t *protocol);
573 /* Given a protocol's filter_name, return its proto_id */
574 extern int proto_get_id_by_filter_name(gchar* filter_name);
576 /* Given a protocol's item number, find the "protocol_t" structure for it */
577 extern protocol_t *find_protocol_by_id(int proto_id);
579 /* Given a protocol's item number, return its name. */
580 extern char *proto_get_protocol_name(int n);
582 /* Given a protocol's "protocol_t", return its short name. */
583 extern char *proto_get_protocol_short_name(protocol_t *protocol);
585 /* Given a protocol's item number, return its filter name. */
586 extern char *proto_get_protocol_filter_name(int proto_id);
588 /* Enable / Disable protocol */
589 extern void proto_set_decoding(int proto_id, gboolean enabled);
591 /* Disable disabling of protocol */
592 extern void proto_set_cant_disable(int proto_id);
594 /* Get length of registered field according to field type.
595 * 0 means undeterminable at registration time.
596 * -1 means unknown field */
597 extern gint proto_registrar_get_length(int n);
599 /* Checks for existence any protocol or field within a tree.
600 * "Protocols" are assumed to be a child of the [empty] root node.
601 * TRUE = found, FALSE = not found */
602 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
604 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
606 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
608 /* Dumps a glossary of the protocol registrations to STDOUT */
609 extern void proto_registrar_dump_protocols(void);
611 /* Dumps a glossary of the protocol and field registrations to STDOUT */
612 extern void proto_registrar_dump_fields(void);
614 /* Points to the first element of an array of Booleans, indexed by
615 a subtree item type; that array element is TRUE if subtrees of
616 an item of that type are to be expanded. */
617 extern gboolean *tree_is_expanded;
619 /* Number of elements in that array. */
620 extern int num_tree_types;
622 /* glib doesn't have g_ptr_array_len of all things!*/
623 #ifndef g_ptr_array_len
624 #define g_ptr_array_len(a) ((a)->len)
628 hfinfo_bitwidth(header_field_info *hfinfo);
633 * Returns TRUE if we can do a "match selected" on the field, FALSE
637 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
640 proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt);
643 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);