Have "do_capture()" take, as an argument, a pointer to the name of the
[obnox/wireshark/wip.git] / proto.h
1 /* proto.h
2  * Definitions for protocol display
3  *
4  * $Id: proto.h,v 1.13 1999/09/18 15:44:40 deniel Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26
27 #ifndef __PROTO_H__
28 #define __PROTO_H__
29
30 #ifdef HAVE_SYS_TIME_H
31 # ifndef _SYS_TIME_H
32 #  include <sys/time.h>
33 # endif
34 #endif
35
36 #ifdef HAVE_WINSOCK_H
37 # include <winsock.h>
38 #endif
39
40 /* needs glib.h */
41 typedef struct GNode proto_tree;
42 typedef struct GNode proto_item;
43 struct value_string;
44
45 #define ITEM_LABEL_LENGTH       240
46
47 /* In order to make a const value_string[] look like a value_string*, I
48  * need this macro */
49 #define VALS(x) (struct value_string*)(x)
50
51
52 /* field types */
53 enum ftenum {
54         FT_NONE,        /* used for protocol labels (thus no field type) */
55         FT_BOOLEAN,     /* TRUE and FALSE come from <glib.h> */
56         FT_UINT8,
57         FT_UINT16,
58         FT_UINT32,
59         FT_DOUBLE,
60         FT_ABSOLUTE_TIME,
61         FT_RELATIVE_TIME,
62         FT_STRING,
63         FT_ETHER,
64         FT_BYTES,
65         FT_IPv4,
66         FT_IPv6,
67         FT_IPXNET,
68         FT_VALS_UINT8,
69         FT_VALS_UINT16,
70         FT_VALS_UINT24,
71         FT_VALS_UINT32,
72         FT_TEXT_ONLY,   /* non-filterable, used when converting ethereal
73                                 from old-style proto_tree to new-style proto_tree */
74         NUM_FIELD_TYPES /* last item number plus one */
75 };
76
77 /* information describing a header field */
78 typedef struct header_field_info {
79         char                            *name;
80         char                            *abbrev;
81         enum ftenum                     type;
82         struct value_string             *vals;
83         int                             id; /* assigned by order of registration */
84         int                             parent; /* parent protocol */
85 } header_field_info;
86
87 /* Used when registering many fields at once */
88 typedef struct hf_register_info {
89         int                     *p_id;  /* pointer to int; written to by register() function */
90         header_field_info       hfinfo;
91 } hf_register_info;
92
93 #ifdef WIN32
94 /* 'boolean' is a reserved word on win32 */
95 #define boolean truth_value
96 #endif
97
98 /* Info stored in each proto_item GNode */
99 typedef struct field_info {
100         struct header_field_info        *hfinfo;
101         gint                            start;
102         gint                            length;
103         gint                            tree_type; /* ETT_* */
104         char                            *representation; /* for GUI tree */
105         int                             visible;
106         union {
107                 guint32         numeric;
108                 struct timeval  time; /* the whole struct, not a pointer */
109                 gdouble         floating;
110                 gchar           *string;
111                 guint8          *bytes;
112                 guint8          ether[6];
113         }                               value;
114 } field_info;
115
116
117 /* used when calling proto search functions */
118 typedef struct proto_tree_search_info {
119         int                     target;
120         int                     parent;
121         const guint8            *packet_data;
122         GNodeTraverseFunc       traverse_func;
123         union {
124                 GArray                  *array;
125                 GNode                   *node;
126         }                       result;
127 } proto_tree_search_info;
128
129 /* Sets up memory used by proto routines. Called at program startup */
130 void proto_init(void);
131
132 /* Frees memory used by proto routines. Called at program shutdown */
133 void proto_cleanup(void);
134
135 void proto_item_set_len(proto_item *ti, gint length);
136 proto_tree* proto_tree_create_root(void);
137 void proto_tree_free(proto_tree *tree);
138 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
139
140 int
141 proto_register_field(char *name, char *abbrev, enum ftenum type, int parent,
142         struct value_string* vals);
143
144 int
145 proto_register_protocol(char *name, char *abbrev);
146
147 void
148 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
149
150 proto_item *
151 proto_tree_add_item(proto_tree *tree, int hfindex, gint start,
152         gint length, ...);
153
154 proto_item *
155 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, gint start,
156         gint length, ...);
157
158 proto_item *
159 proto_tree_add_item_format(proto_tree *tree, int hfindex, gint start,
160         gint length, ...);
161
162 proto_item *
163 proto_tree_add_text(proto_tree *tree, gint start, gint length, ...);
164
165 void
166 proto_item_fill_label(field_info *fi, gchar *label_str);
167
168 /* Returns number of items (protocols or header fields) registered. */
169 int proto_registrar_n(void);
170
171 /* Returns char* to abbrev for item # n (0-indexed) */
172 char* proto_registrar_get_abbrev(int n);
173
174 /* Returns enum ftenum for item # n */
175 int proto_registrar_get_ftype(int n);
176
177 /* Returns parent protocol for item # n.
178  * Returns -1 if item _is_ a protocol */
179 int proto_registrar_get_parent(int n);
180
181 /* Is item #n a protocol? */
182 gboolean proto_registrar_is_protocol(int n);
183
184 /* Checks for existence any protocol or field within a tree.
185  * TRUE = found, FALSE = not found */
186 gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
187
188 /* Search for a protocol subtree, which can occur more than once, and for each successful
189  * find, call the calback function, passing sinfo as the second argument */
190 void proto_find_protocol_multi(proto_tree* tree, int target, GNodeTraverseFunc callback,
191                         proto_tree_search_info *sinfo);
192
193 /* Just a wrapper to call sinfo->traverse_func() for all nodes in the subtree, with the GNode
194  * and sinfo as the two arguments to sinfo->traverse_func(). Useful when you have to process
195  * all nodes in a subtree. */
196 gboolean proto_get_field_values(proto_tree* subtree, proto_tree_search_info *sinfo);
197
198 /* Dumps a glossary of the protocol and field registrations to STDOUT */
199 void proto_registrar_dump(void);
200
201 /* Is the parsing being done for a visible proto_tree or an invisible one?
202  * By setting this correctly, the proto_tree creation is sped up by not
203  * having to call vsnprintf and copy strings around.
204  */
205 extern gboolean proto_tree_is_visible;
206
207 #endif /* proto.h */