2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.39 2001/11/20 21:59:18 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.
28 #include "wiretap/wtap.h"
33 #include "value_string.h"
34 #include "column_info.h"
35 #include "frame_data.h"
36 #include "packet_info.h"
37 #include "column-utils.h"
39 #define hi_nibble(b) (((b) & 0xf0) >> 4)
40 #define lo_nibble(b) ((b) & 0x0f)
42 /* Useful when you have an array whose size you can tell at compile-time */
43 #define array_length(x) (sizeof x / sizeof x[0])
45 /* Check whether the "len" bytes of data starting at "offset" is
46 * entirely inside the captured data for this packet. */
47 #define BYTES_ARE_IN_FRAME(offset, captured_len, len) \
48 ((offset) + (len) <= (captured_len))
50 /* To pass one of two strings, singular or plural */
51 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
53 typedef struct _packet_counts {
67 /* Types of character encodings */
69 CHAR_ASCII = 0, /* ASCII */
70 CHAR_EBCDIC = 1 /* EBCDIC */
73 /* Struct for boolean enumerations */
74 typedef struct true_false_string {
79 extern void packet_init(void);
80 extern void packet_cleanup(void);
82 /* Hash table for matching port numbers and dissectors */
83 typedef GHashTable* dissector_table_t;
85 /* types for sub-dissector lookup */
86 typedef void (*old_dissector_t)(const u_char *, int, frame_data *, proto_tree *);
87 typedef void (*dissector_t)(tvbuff_t *, packet_info *, proto_tree *);
89 typedef void (*DATFunc) (gchar *table_name, gpointer key, gpointer value, gpointer user_data);
91 /* Opaque structure - provides type checking but no access to components */
92 typedef struct dtbl_entry dtbl_entry_t;
94 extern gint dissector_get_proto (dtbl_entry_t * entry);
95 extern gint dissector_get_initial_proto (dtbl_entry_t * entry);
96 extern void dissector_table_foreach_changed (char *name, DATFunc func,
98 extern void dissector_table_foreach (char *name, DATFunc func,
100 extern void dissector_all_tables_foreach_changed (DATFunc func,
103 /* a protocol uses the function to register a sub-dissector table */
104 extern dissector_table_t register_dissector_table(const char *name);
106 /* Add a sub-dissector to a dissector table. Called by the protocol routine */
107 /* that wants to register a sub-dissector. */
108 extern void dissector_add(const char *abbrev, guint32 pattern,
109 dissector_t dissector, int proto);
111 /* Add a sub-dissector to a dissector table. Called by the protocol routine */
112 /* that wants to de-register a sub-dissector. */
113 extern void dissector_delete(const char *name, guint32 pattern,
114 dissector_t dissector);
116 extern void dissector_change(const char *abbrev, guint32 pattern,
117 dissector_t dissector, int proto);
119 /* Reset a dissector in a sub-dissector table to its initial value. */
120 extern void dissector_reset(const char *name, guint32 pattern);
122 /* Look for a given port in a given dissector table and, if found, call
123 the dissector with the arguments supplied, and return TRUE, otherwise
125 extern gboolean dissector_try_port(dissector_table_t sub_dissectors,
126 guint32 port, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
128 /* List of "heuristic" dissectors (which get handed a packet, look at it,
129 and either recognize it as being for their protocol, dissect it, and
130 return TRUE, or don't recognize it and return FALSE) to be called
131 by another dissector. */
132 typedef GSList *heur_dissector_list_t;
134 /* Type of a heuristic dissector */
135 typedef gboolean (*heur_dissector_t)(tvbuff_t *, packet_info *,
138 /* A protocol uses this function to register a heuristic dissector list */
139 extern void register_heur_dissector_list(const char *name,
140 heur_dissector_list_t *list);
142 /* Add a sub-dissector to a heuristic dissector list. Called by the
143 protocol routine that wants to register a sub-dissector. */
144 extern void heur_dissector_add(const char *name, heur_dissector_t dissector,
147 /* Try all the dissectors in a given heuristic dissector list until
148 we find one that recognizes the protocol, in which case we return
149 TRUE, or we run out of dissectors, in which case we return FALSE. */
150 extern gboolean dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
151 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
153 /* List of "conversation" dissectors (they're not heuristic, but are
154 assigned to a conversation if some other dissector sees some traffic
155 saying "traffic between these hosts on these ports will be of type
156 XXX", e.g. RTSP traffic doing so).
158 These lists are for use by the UI, which, for a given conversation,
159 would offer a list of dissectors that could be used with it; this
160 would include dissectors on the conversation dissector list for
161 the transport-layer protocol for the conversation, as well as
162 dissectors for any port-based lists for that protocol (as a conversation
163 between two ports, both of which have dissectors associated with them,
164 might have been given to the wrong one of those dissectors). */
165 typedef GSList *conv_dissector_list_t;
167 /* A protocol uses this function to register a conversation dissector list */
168 extern void register_conv_dissector_list(const char *name,
169 conv_dissector_list_t *list);
171 /* Add a sub-dissector to a conversation dissector list. Called by the
172 protocol routine that wants to register a sub-dissector. */
173 extern void conv_dissector_add(const char *name, dissector_t dissector,
176 /* Opaque structure - provides type checking but no access to components */
177 typedef struct conv_dtbl_entry conv_dtbl_entry_t;
179 extern gint conv_dissector_get_proto (conv_dtbl_entry_t * entry);
180 extern void dissector_conv_foreach(char *name, DATFunc func,
182 extern void dissector_all_conv_foreach(DATFunc func, gpointer user_data);
184 /* Handle for dissectors you call directly.
185 This handle is opaque outside of "packet.c". */
186 struct dissector_handle;
187 typedef struct dissector_handle *dissector_handle_t;
189 /* Register a dissector. */
190 extern void register_dissector(const char *name, dissector_t dissector,
193 /* Find a dissector by name. */
194 extern dissector_handle_t find_dissector(const char *name);
196 /* Call a dissector through a handle. */
197 extern void call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
198 packet_info *pinfo, proto_tree *tree);
200 /* Do all one-time initialization. */
201 extern void dissect_init(void);
203 extern void dissect_cleanup(void);
206 * Given a tvbuff, a packet_info *, and a length from a packet header,
207 * adjust the length of the tvbuff, and the "len" and "captured_len"
208 * members of the "packet_info" structure, to reflect the specified
211 extern void set_actual_length(tvbuff_t *tvb, packet_info *pinfo,
212 guint specified_len);
214 /* Allow protocols to register "init" routines, which are called before
215 we make a pass through a capture file and dissect all its packets
216 (e.g., when we read in a new capture file, or run a "filter packets"
217 or "colorize packets" pass over the current capture file). */
218 extern void register_init_routine(void (*func)(void));
220 /* Call all the registered "init" routines. */
221 extern void init_all_protocols(void);
224 * Dissectors should never modify the packet data.
226 extern void dissect_packet(tvbuff_t **p_tvb,
227 union wtap_pseudo_header *pseudo_header, const u_char *pd,
228 frame_data *fd, proto_tree *tree);
229 extern void dissect_data(tvbuff_t *tvb, int, packet_info *pinfo,
233 /* These functions are in packet-ethertype.c */
234 extern void capture_ethertype(guint16 etype, const u_char *pd, int offset,
235 int len, packet_counts *ld);
236 extern void ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_ethertype,
237 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
238 int etype_id, int trailer_id);
240 #endif /* packet.h */