2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.48 2001/12/18 19:09:03 gram 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"
40 #define hi_nibble(b) (((b) & 0xf0) >> 4)
41 #define lo_nibble(b) ((b) & 0x0f)
43 /* Useful when you have an array whose size you can tell at compile-time */
44 #define array_length(x) (sizeof x / sizeof x[0])
46 /* Check whether the "len" bytes of data starting at "offset" is
47 * entirely inside the captured data for this packet. */
48 #define BYTES_ARE_IN_FRAME(offset, captured_len, len) \
49 ((offset) + (len) <= (captured_len))
51 /* To pass one of two strings, singular or plural */
52 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
54 typedef struct _packet_counts {
68 /* Types of character encodings */
70 CHAR_ASCII = 0, /* ASCII */
71 CHAR_EBCDIC = 1 /* EBCDIC */
74 /* Struct for boolean enumerations */
75 typedef struct true_false_string {
80 extern void packet_init(void);
81 extern void packet_cleanup(void);
83 /* Handle for dissectors you call directly or register with "dissector_add()".
84 This handle is opaque outside of "packet.c". */
85 struct dissector_handle;
86 typedef struct dissector_handle *dissector_handle_t;
88 /* Hash table for matching port numbers and dissectors; this is opaque
89 outside of "packet.c". */
90 struct dissector_table;
91 typedef struct dissector_table *dissector_table_t;
93 /* types for sub-dissector lookup */
94 typedef void (*old_dissector_t)(const u_char *, int, frame_data *, proto_tree *);
95 typedef void (*dissector_t)(tvbuff_t *, packet_info *, proto_tree *);
97 typedef void (*DATFunc) (gchar *table_name, gpointer key, gpointer value, gpointer user_data);
98 typedef void (*DATFunc_handle) (gchar *table_name, gpointer value, gpointer user_data);
100 /* Opaque structure - provides type checking but no access to components */
101 typedef struct dtbl_entry dtbl_entry_t;
103 extern dissector_handle_t dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry);
104 extern dissector_handle_t dtbl_entry_get_initial_handle (dtbl_entry_t * entry);
105 extern void dissector_table_foreach_changed (char *name, DATFunc func,
107 extern void dissector_table_foreach (char *name, DATFunc func,
109 extern void dissector_all_tables_foreach_changed (DATFunc func,
111 extern void dissector_table_foreach_handle(char *name, DATFunc_handle func,
114 /* a protocol uses the function to register a sub-dissector table */
115 extern dissector_table_t register_dissector_table(const char *name,
116 char *ui_name, ftenum_t type, int base);
118 /* Get the UI name for a sub-dissector table, given its internal name */
119 extern char *get_dissector_table_ui_name(const char *name);
121 /* Get the field type to use when displaying values of the selector for a
122 sub-dissector table, given the table's internal name */
123 ftenum_t get_dissector_table_type(const char *name);
125 /* Get the base to use when displaying values of the selector for a
126 sub-dissector table, given the table's internal name */
127 extern int get_dissector_table_base(const char *name);
129 /* Add a sub-dissector to a dissector table. Called by the protocol routine */
130 /* that wants to register a sub-dissector. */
131 extern void dissector_add(const char *abbrev, guint32 pattern,
132 dissector_handle_t handle);
134 /* Add a sub-dissector to a dissector table. Called by the protocol routine */
135 /* that wants to de-register a sub-dissector. */
136 extern void dissector_delete(const char *name, guint32 pattern,
137 dissector_handle_t handle);
139 extern void dissector_change(const char *abbrev, guint32 pattern,
140 dissector_handle_t handle);
142 /* Reset a dissector in a sub-dissector table to its initial value. */
143 extern void dissector_reset(const char *name, guint32 pattern);
145 /* Look for a given port in a given dissector table and, if found, call
146 the dissector with the arguments supplied, and return TRUE, otherwise
148 extern gboolean dissector_try_port(dissector_table_t sub_dissectors,
149 guint32 port, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
151 /* Look for a given port in a given dissector table and, if found, return
152 the dissector handle for that port. */
153 extern dissector_handle_t dissector_get_port_handle(
154 dissector_table_t sub_dissectors, guint32 port);
156 /* Add a handle to the list of handles that *could* be used with this
157 table. That list is used by code in the UI. */
158 extern void dissector_add_handle(const char *name, dissector_handle_t handle);
160 /* List of "heuristic" dissectors (which get handed a packet, look at it,
161 and either recognize it as being for their protocol, dissect it, and
162 return TRUE, or don't recognize it and return FALSE) to be called
163 by another dissector. */
164 typedef GSList *heur_dissector_list_t;
166 /* Type of a heuristic dissector */
167 typedef gboolean (*heur_dissector_t)(tvbuff_t *, packet_info *,
170 /* A protocol uses this function to register a heuristic dissector list */
171 extern void register_heur_dissector_list(const char *name,
172 heur_dissector_list_t *list);
174 /* Add a sub-dissector to a heuristic dissector list. Called by the
175 protocol routine that wants to register a sub-dissector. */
176 extern void heur_dissector_add(const char *name, heur_dissector_t dissector,
179 /* Try all the dissectors in a given heuristic dissector list until
180 we find one that recognizes the protocol, in which case we return
181 TRUE, or we run out of dissectors, in which case we return FALSE. */
182 extern gboolean dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
183 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
185 /* Register a dissector. */
186 extern void register_dissector(const char *name, dissector_t dissector,
189 /* Get the short name of the protocol for a dissector handle. */
190 extern char *dissector_handle_get_short_name(dissector_handle_t handle);
192 /* Find a dissector by name. */
193 extern dissector_handle_t find_dissector(const char *name);
195 /* Create an anonymous handle for a dissector. */
196 extern dissector_handle_t create_dissector_handle(dissector_t dissector,
199 /* Call a dissector through a handle. */
200 extern void call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
201 packet_info *pinfo, proto_tree *tree);
203 /* Do all one-time initialization. */
204 extern void dissect_init(void);
206 extern void dissect_cleanup(void);
209 * Given a tvbuff, a packet_info *, and a length from a packet header,
210 * adjust the length of the tvbuff, and the "len" and "captured_len"
211 * members of the "packet_info" structure, to reflect the specified
214 extern void set_actual_length(tvbuff_t *tvb, packet_info *pinfo,
215 guint specified_len);
217 /* Allow protocols to register "init" routines, which are called before
218 we make a pass through a capture file and dissect all its packets
219 (e.g., when we read in a new capture file, or run a "filter packets"
220 or "colorize packets" pass over the current capture file). */
221 extern void register_init_routine(void (*func)(void));
223 /* Call all the registered "init" routines. */
224 extern void init_all_protocols(void);
227 * Dissectors should never modify the packet data.
229 extern void dissect_packet(epan_dissect_t *edt,
230 union wtap_pseudo_header *pseudo_header, const u_char *pd,
231 frame_data *fd, column_info *cinfo);
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 */