2 * Definitions for protocol display
4 * $Id: proto.h,v 1.45 2003/11/24 21:12:10 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;
105 /* Contains the field information for the proto_item. */
106 typedef struct field_info {
108 /* the next pointer is only used when keeping track of
109 * free (unallocated) field_infos. Such field_info's
110 * are never associated with a header_field_info.
112 struct field_info *next;
113 header_field_info *hfinfo;
117 gint tree_type; /* ETT_* */
118 char *representation; /* for GUI tree */
121 tvbuff_t *ds_tvb; /* data source tvbuff */
124 /* One of these exists for the entire protocol tree. Each proto_node
125 * in the protocol tree points to the same copy. */
127 GHashTable *interesting_hfids;
131 /* Each GNode (proto_tree, proto_item) points to one of
135 tree_data_t *tree_data;
138 typedef GNode proto_tree;
139 typedef GNode proto_item;
141 /* Retrieve the proto_node from a GNode. */
142 #define GNODE_PNODE(t) ((proto_node*)((GNode*)(t))->data)
144 /* Retrieve the field_info from a proto_item */
145 #define PITEM_FINFO(t) (GNODE_PNODE(t)->finfo)
147 /* Retrieve the tree_data_t from a proto_tree */
148 #define PTREE_DATA(t) (GNODE_PNODE(t)->tree_data)
150 /* Sets up memory used by proto routines. Called at program startup */
151 extern void proto_init(const char *plugin_dir,
152 void (register_all_protocols)(void), void (register_all_handoffs)(void));
154 /* Frees memory used by proto routines. Called at program shutdown */
155 extern void proto_cleanup(void);
157 /* Set text of proto_item after having already been created. */
159 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
160 __attribute__((format (printf, 2, 3)));
162 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
165 /* Append to text of proto_item after having already been created. */
167 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
168 __attribute__((format (printf, 2, 3)));
170 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
173 /* Set length of proto_item after having already been created. */
174 extern void proto_item_set_len(proto_item *ti, gint length);
177 * Sets the length of the item based on its start and on the specified
178 * offset, which is the offset past the end of the item; as the start
179 * in the item is relative to the beginning of the data source tvbuff,
180 * we need to pass in a tvbuff - the end offset is relative to the beginning
183 extern void proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end);
185 /* Get length of proto_item. Useful after using proto_tree_add_item()
186 * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
187 extern int proto_item_get_len(proto_item *ti);
189 /* Creates new proto_tree root */
190 extern proto_tree* proto_tree_create_root(void);
192 /* Mark a field/protocol ID as "interesting". */
194 proto_tree_prime_hfid(proto_tree *tree, int hfid);
196 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
197 extern void proto_tree_free(proto_tree *tree);
199 /* Create a subtree under an existing item; returns tree pointer */
200 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
203 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
204 struct _value_string* vals);
207 proto_register_protocol(char *name, char *short_name, char *filter_name);
210 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
213 proto_register_subtree_array(gint **indices, int num_indices);
215 /* Add an item to a proto_tree, using the text label registered to that item;
216 the item is extracted from the tvbuff handed to it. */
218 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
219 gint start, gint length, gboolean little_endian);
222 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
223 gint start, gint length, gboolean little_endian);
225 /* Add a FT_NONE to a proto_tree */
228 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
229 gint length, const char *format, ...)
230 __attribute__((format (printf, 6, 7)));
233 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
234 gint length, const char *format, ...);
237 /* Add a FT_PROTOCOL to a proto_tree */
240 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
241 gint length, const char *format, ...)
242 __attribute__((format (printf, 6, 7)));
245 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
246 gint length, const char *format, ...);
249 /* Add a FT_BYTES to a proto_tree */
251 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
252 gint length, const guint8* start_ptr);
255 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
256 gint length, const guint8* start_ptr);
260 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
261 gint length, const guint8* start_ptr, const char *format, ...)
262 __attribute__((format (printf, 7, 8)));
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, ...);
269 /* Add a FT_*TIME to a proto_tree */
271 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
272 gint length, nstime_t* value_ptr);
275 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
276 gint length, nstime_t* value_ptr);
280 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
281 gint length, nstime_t* value_ptr, const char *format, ...)
282 __attribute__((format (printf, 7, 8)));
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, ...);
289 /* Add a FT_IPXNET to a proto_tree */
291 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
292 gint length, guint32 value);
295 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
296 gint length, guint32 value);
300 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
301 gint length, guint32 value, const char *format, ...)
302 __attribute__((format (printf, 7, 8)));
305 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
306 gint length, guint32 value, const char *format, ...);
309 /* Add a FT_IPv4 to a proto_tree */
311 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
312 gint length, guint32 value);
315 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
316 gint length, guint32 value);
320 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
321 gint length, guint32 value, const char *format, ...)
322 __attribute__((format (printf, 7, 8)));
325 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
326 gint length, guint32 value, const char *format, ...);
329 /* Add a FT_IPv6 to a proto_tree */
331 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
332 gint length, const guint8* value_ptr);
335 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
336 gint length, const guint8* value_ptr);
340 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
341 gint length, const guint8* value_ptr, const char *format, ...)
342 __attribute__((format (printf, 7, 8)));
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, ...);
349 /* Add a FT_ETHER to a proto_tree */
351 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
352 gint length, const guint8* value);
355 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
356 gint length, const guint8* value);
360 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
361 gint length, const guint8* value, const char *format, ...)
362 __attribute__((format (printf, 7, 8)));
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, ...);
369 /* Add a FT_STRING to a proto_tree */
371 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
372 gint length, const char* value);
375 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
376 gint length, const char* value);
380 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
381 gint length, const char* value, const char *format, ...)
382 __attribute__((format (printf, 7, 8)));
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, ...);
390 proto_item_append_string(proto_item *pi, const char *str);
392 /* Add a FT_BOOLEAN to a proto_tree */
394 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
395 gint length, guint32 value);
398 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
399 gint length, guint32 value);
403 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
404 gint length, guint32 value, const char *format, ...)
405 __attribute__((format (printf, 7, 8)));
408 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
409 gint length, guint32 value, const char *format, ...);
412 /* Add a FT_FLOAT to a proto_tree */
414 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
415 gint length, float value);
418 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
419 gint length, float value);
423 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
424 gint length, float value, const char *format, ...)
425 __attribute__((format (printf, 7, 8)));
428 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
429 gint length, float value, const char *format, ...);
432 /* Add a FT_DOUBLE to a proto_tree */
434 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
435 gint length, double value);
438 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
439 gint length, double value);
443 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
444 gint length, double value, const char *format, ...)
445 __attribute__((format (printf, 7, 8)));
448 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
449 gint length, double value, const char *format, ...);
452 /* Add any FT_UINT* to a proto_tree */
454 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
455 gint length, guint32 value);
458 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
459 gint length, guint32 value);
463 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
464 gint length, guint32 value, const char *format, ...)
465 __attribute__((format (printf, 7, 8)));
468 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
469 gint length, guint32 value, const char *format, ...);
472 /* Add any FT_INT* to a proto_tree */
474 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
475 gint length, gint32 value);
478 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
479 gint length, gint32 value);
483 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
484 gint length, gint32 value, const char *format, ...)
485 __attribute__((format (printf, 7, 8)));
488 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
489 gint length, gint32 value, const char *format, ...);
493 /* Add a text-only node to the proto_tree */
496 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
497 ...) __attribute__((format (printf, 5, 6)));
500 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
505 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
506 gint length, const char *format, va_list ap);
509 /* Useful for quick debugging. Also sends string to STDOUT, so don't
510 * leave call to this function in production code. */
513 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
514 __attribute__((format (printf, 2, 3)));
517 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
521 proto_item_fill_label(field_info *fi, gchar *label_str);
524 proto_tree_set_visible(proto_tree *tree, gboolean visible);
526 /* Returns number of items (protocols or header fields) registered. */
527 extern int proto_registrar_n(void);
529 /* Returns char* to name for item # n (0-indexed) */
530 extern char* proto_registrar_get_name(int n);
532 /* Returns char* to abbrev for item # n (0-indexed) */
533 extern char* proto_registrar_get_abbrev(int n);
535 /* get the header field information based upon a field or protocol id */
536 extern header_field_info* proto_registrar_get_nth(guint hfindex);
538 /* get the header field information based upon a field name */
539 extern header_field_info* proto_registrar_get_byname(char *field_name);
541 /* Returns enum ftenum for item # n */
542 extern int proto_registrar_get_ftype(int n);
544 /* Returns parent protocol for item # n.
545 * Returns -1 if item _is_ a protocol */
546 extern int proto_registrar_get_parent(int n);
548 /* Is item #n a protocol? */
549 extern gboolean proto_registrar_is_protocol(int n);
551 /* Is protocol's decoding enabled ? */
552 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
554 /* Can item #n decoding be disabled? */
555 extern gboolean proto_can_disable_protocol(int proto_id);
557 /* Routines to use to iterate over the protocols and their fields;
558 * they return the item number of the protocol in question or the
559 * appropriate hfinfo pointer, and keep state in "*cookie". */
560 extern int proto_get_first_protocol(void **cookie);
561 extern int proto_get_next_protocol(void **cookie);
562 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
563 extern header_field_info *proto_get_next_protocol_field(void **cookle);
565 /* Given a protocol's "protocol_t", return its proto_id */
566 extern int proto_get_id(protocol_t *protocol);
568 /* Given a protocol's filter_name, return its proto_id */
569 extern int proto_get_id_by_filter_name(gchar* filter_name);
571 /* Given a protocol's item number, find the "protocol_t" structure for it */
572 extern protocol_t *find_protocol_by_id(int proto_id);
574 /* Given a protocol's item number, return its name. */
575 extern char *proto_get_protocol_name(int n);
577 /* Given a protocol's "protocol_t", return its short name. */
578 extern char *proto_get_protocol_short_name(protocol_t *protocol);
580 /* Given a protocol's item number, return its filter name. */
581 extern char *proto_get_protocol_filter_name(int proto_id);
583 /* Enable / Disable protocol */
584 extern void proto_set_decoding(int proto_id, gboolean enabled);
586 /* Disable disabling of protocol */
587 extern void proto_set_cant_disable(int proto_id);
589 /* Get length of registered field according to field type.
590 * 0 means undeterminable at registration time.
591 * -1 means unknown field */
592 extern gint proto_registrar_get_length(int n);
594 /* Checks for existence any protocol or field within a tree.
595 * "Protocols" are assumed to be a child of the [empty] root node.
596 * TRUE = found, FALSE = not found */
597 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
599 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
601 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
603 /* Dumps a glossary of the protocol registrations to STDOUT */
604 extern void proto_registrar_dump_protocols(void);
606 /* Dumps a glossary of the protocol and field registrations to STDOUT */
607 extern void proto_registrar_dump_fields(void);
609 /* Points to the first element of an array of Booleans, indexed by
610 a subtree item type; that array element is TRUE if subtrees of
611 an item of that type are to be expanded. */
612 extern gboolean *tree_is_expanded;
614 /* Number of elements in that array. */
615 extern int num_tree_types;
617 /* glib doesn't have g_ptr_array_len of all things!*/
618 #ifndef g_ptr_array_len
619 #define g_ptr_array_len(a) ((a)->len)
623 hfinfo_bitwidth(header_field_info *hfinfo);
628 * Returns TRUE if we can do a "match selected" on the field, FALSE
632 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
635 proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt);
638 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);