Move the declaration of "ipprotostr()" out of "epan/packet.h" into a new
[obnox/wireshark/wip.git] / epan / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * $Id: packet.h,v 1.31 2001/04/17 06:29:14 guy 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 __PACKET_H__
28 #define __PACKET_H__
29
30 #include "wiretap/wtap.h"
31 #include "proto.h"
32 #include "tvbuff.h"
33 #include "pint.h"
34 #include "to_str.h"
35 #include "value_string.h"
36 #include "column_info.h"
37 #include "frame_data.h"
38 #include "packet_info.h"
39 #include "column-utils.h"
40
41 #define hi_nibble(b) (((b) & 0xf0) >> 4)
42 #define lo_nibble(b) ((b) & 0x0f)
43
44 /* Useful when you have an array whose size you can tell at compile-time */
45 #define array_length(x) (sizeof x / sizeof x[0])
46
47 /* Useful when highlighting regions inside a dissect_*() function. With this
48  * macro, you can highlight from an arbitrary offset to the end of the
49  * packet (which may come before the end of the frame).
50  * See old_dissect_data() for an example.
51  */
52 #define END_OF_FRAME    (pi.captured_len - offset)
53
54 /* Check whether the "len" bytes of data starting at "offset" is
55  * entirely inside the captured data for this packet. */
56 #define BYTES_ARE_IN_FRAME(offset, len) ((offset) + (len) <= pi.captured_len)
57
58 /* Check whether there's any data at all starting at "offset". */
59 #define IS_DATA_IN_FRAME(offset)        ((offset) < pi.captured_len)
60                 
61 /* To pass one of two strings, singular or plural */
62 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
63
64 typedef struct _packet_counts {
65   gint           sctp;
66   gint           tcp;
67   gint           udp;
68   gint           icmp;
69   gint           ospf;
70   gint           gre;
71   gint           netbios;
72   gint           ipx;
73   gint           vines;
74   gint           other;
75   gint           total;
76 } packet_counts;
77
78 /* Types of character encodings */
79 typedef enum {
80         CHAR_ASCII       = 0,   /* ASCII */
81         CHAR_EBCDIC      = 1    /* EBCDIC */
82 } char_enc;
83
84 /* Struct for boolean enumerations */
85 typedef struct true_false_string {
86         char    *true_string;
87         char    *false_string;
88 } true_false_string;
89
90 void packet_init(void);
91 void packet_cleanup(void);
92
93 /* Hash table for matching port numbers and dissectors */
94 typedef GHashTable* dissector_table_t;
95
96 /* types for sub-dissector lookup */
97 typedef void (*old_dissector_t)(const u_char *, int, frame_data *, proto_tree *);
98 typedef void (*dissector_t)(tvbuff_t *, packet_info *, proto_tree *);
99
100 typedef void (*DATFunc) (gchar *table_name, gpointer key, gpointer value, gpointer user_data);
101
102 /* Opaque structure - provides type checking but no access to components */
103 typedef struct dtbl_entry dtbl_entry_t;
104
105 gboolean dissector_get_old_flag (dtbl_entry_t *entry);
106 gint dissector_get_proto (dtbl_entry_t * entry);
107 gint dissector_get_initial_proto (dtbl_entry_t * entry);
108 void dissector_table_foreach_changed (char *name, DATFunc func, gpointer user_data);
109 void dissector_table_foreach (char *name, DATFunc func, gpointer user_data);
110 void dissector_all_tables_foreach_changed (DATFunc func, gpointer user_data);
111
112 /* a protocol uses the function to register a sub-dissector table */
113 dissector_table_t register_dissector_table(const char *name);
114
115 /* Add a sub-dissector to a dissector table.  Called by the protocol routine */
116 /* that wants to register a sub-dissector.  */
117 void old_dissector_add(const char *abbrev, guint32 pattern,
118     old_dissector_t dissector, int proto);
119 void dissector_add(const char *abbrev, guint32 pattern,
120     dissector_t dissector, int proto);
121
122 /* Add a sub-dissector to a dissector table.  Called by the protocol routine */
123 /* that wants to de-register a sub-dissector.  */
124 void old_dissector_delete(const char *name, guint32 pattern, old_dissector_t dissector);
125 void dissector_delete(const char *name, guint32 pattern, dissector_t dissector);
126
127 /* Reset a dissector in a sub-dissector table to its initial value. */
128 void dissector_change(const char *abbrev, guint32 pattern,
129     dissector_t dissector, gboolean old, int proto);
130 void dissector_reset(const char *name, guint32 pattern);
131
132 /* Look for a given port in a given dissector table and, if found, call
133    the dissector with the arguments supplied, and return TRUE, otherwise
134    return FALSE. */
135 gboolean old_dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
136     const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
137 gboolean dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
138     tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
139
140 /* List of "heuristic" dissectors (which get handed a packet, look at it,
141    and either recognize it as being for their protocol, dissect it, and
142    return TRUE, or don't recognize it and return FALSE) to be called
143    by another dissector. */
144 typedef GSList *heur_dissector_list_t;
145
146 /* Type of a heuristic dissector */
147 typedef gboolean (*old_heur_dissector_t)(const u_char *, int, frame_data *,
148         proto_tree *);
149 typedef gboolean (*heur_dissector_t)(tvbuff_t *, packet_info *,
150         proto_tree *);
151
152 /* A protocol uses this function to register a heuristic dissector list */
153 void register_heur_dissector_list(const char *name, heur_dissector_list_t *list);
154
155 /* Add a sub-dissector to a heuristic dissector list.  Called by the
156    protocol routine that wants to register a sub-dissector.  */
157 void old_heur_dissector_add(const char *name, old_heur_dissector_t dissector,
158     int proto);
159 void heur_dissector_add(const char *name, heur_dissector_t dissector,
160     int proto);
161
162 /* Try all the dissectors in a given heuristic dissector list until
163    we find one that recognizes the protocol, in which case we return
164    TRUE, or we run out of dissectors, in which case we return FALSE. */
165 gboolean dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
166     tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
167
168 /* List of "conversation" dissectors (they're not heuristic, but are
169    assigned to a conversation if some other dissector sees some traffic
170    saying "traffic between these hosts on these ports will be of type
171    XXX", e.g. RTSP traffic doing so).
172
173    These lists are for use by the UI, which, for a given conversation,
174    would offer a list of dissectors that could be used with it; this
175    would include dissectors on the conversation dissector list for
176    the transport-layer protocol for the conversation, as well as
177    dissectors for any port-based lists for that protocol (as a conversation
178    between two ports, both of which have dissectors associated with them,
179    might have been given to the wrong one of those dissectors). */
180 typedef GSList *conv_dissector_list_t;
181
182 /* A protocol uses this function to register a conversation dissector list */
183 void register_conv_dissector_list(const char *name, conv_dissector_list_t *list);
184
185 /* Add a sub-dissector to a conversation dissector list.  Called by the
186    protocol routine that wants to register a sub-dissector.  */
187 void old_conv_dissector_add(const char *name, old_dissector_t dissector,
188     int proto);
189 void conv_dissector_add(const char *name, dissector_t dissector,
190     int proto);
191
192 /* Opaque structure - provides type checking but no access to components */
193 typedef struct conv_dtbl_entry conv_dtbl_entry_t;
194
195 gboolean conv_dissector_get_old_flag (conv_dtbl_entry_t *entry);
196 gint conv_dissector_get_proto (conv_dtbl_entry_t * entry);
197 void dissector_conv_foreach(char *name, DATFunc func, gpointer user_data);
198 void dissector_all_conv_foreach(DATFunc func, gpointer user_data);
199
200 /* Handle for dissectors you call directly.
201    This handle is opaque outside of "packet.c". */
202 struct dissector_handle;
203 typedef struct dissector_handle *dissector_handle_t;
204
205 /* Register a dissector. */
206 void register_dissector(const char *name, dissector_t dissector, int proto);
207
208 /* Find a dissector by name. */
209 dissector_handle_t find_dissector(const char *name);
210
211 /* Call a dissector through a handle. */
212 void call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
213     packet_info *pinfo, proto_tree *tree);
214
215 /* Do all one-time initialization. */
216 void dissect_init(void);
217
218 void dissect_cleanup(void);
219
220 /* Allow protocols to register "init" routines, which are called before
221    we make a pass through a capture file and dissect all its packets
222    (e.g., when we read in a new capture file, or run a "filter packets"
223    or "colorize packets" pass over the current capture file). */
224 void register_init_routine(void (*func)(void));
225
226 /* Call all the registered "init" routines. */
227 void init_all_protocols(void);
228
229 /*
230  * Dissectors should never modify the packet data.
231  */
232 void dissect_packet(tvbuff_t **p_tvb, union wtap_pseudo_header *pseudo_header,
233                 const u_char *pd, frame_data *fd, proto_tree *tree);
234 void old_dissect_data(const u_char *, int, frame_data *, proto_tree *);
235 void dissect_data(tvbuff_t *tvb, int, packet_info *pinfo, proto_tree *tree);
236
237
238 /* These functions are in packet-ethertype.c */
239 void capture_ethertype(guint16 etype, int offset,
240                 const u_char *pd, packet_counts *ld);
241 void ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_ethertype,
242                 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
243                 int etype_id, int trailer_id);
244 extern const value_string etype_vals[];
245
246 #endif /* packet.h */