3 * Top-most dissector. Decides dissector based on Wiretap Encapsulation Type.
5 * $Id: packet-frame.c,v 1.19 2002/01/17 09:28:22 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 2000 Gerald Combs
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.
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.
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.
32 #include "timestamp.h"
34 #include "packet-frame.h"
37 static int proto_frame = -1;
38 static int hf_frame_arrival_time = -1;
39 static int hf_frame_time_delta = -1;
40 static int hf_frame_time_relative = -1;
41 static int hf_frame_number = -1;
42 static int hf_frame_packet_len = -1;
43 static int hf_frame_capture_len = -1;
44 static int hf_frame_p2p_dir = -1;
45 static int hf_frame_file_off = -1;
46 static int proto_short = -1;
47 int proto_malformed = -1;
48 static int proto_unreassembled = -1;
50 static gint ett_frame = -1;
52 static dissector_handle_t data_handle;
55 static gboolean show_file_off = FALSE;
57 static const value_string p2p_dirs[] = {
58 { P2P_DIR_SENT, "Sent" },
59 { P2P_DIR_RECV, "Received" },
63 static dissector_table_t wtap_encap_dissector_table;
66 dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
73 pinfo->current_proto = "Frame";
75 if (pinfo->fd->lnk_t == WTAP_ENCAP_LAPD ||
76 pinfo->fd->lnk_t == WTAP_ENCAP_CHDLC ||
77 pinfo->fd->lnk_t == WTAP_ENCAP_PPP_WITH_PHDR) {
79 pinfo->p2p_dir = pinfo->pseudo_header->p2p.sent ? P2P_DIR_SENT : P2P_DIR_RECV;
81 else if (pinfo->fd->lnk_t == WTAP_ENCAP_LAPB ||
82 pinfo->fd->lnk_t == WTAP_ENCAP_FRELAY) {
84 pinfo->p2p_dir = (pinfo->pseudo_header->x25.flags & 0x80) ? P2P_DIR_RECV : P2P_DIR_SENT;
87 /* Put in frame header information. */
90 cap_len = tvb_length(tvb);
91 pkt_len = tvb_reported_length(tvb);
93 ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, tvb_length(tvb),
94 "Frame %u (%u on wire, %u captured)", pinfo->fd->num, pkt_len, cap_len);
96 fh_tree = proto_item_add_subtree(ti, ett_frame);
98 ts.secs = pinfo->fd->abs_secs;
99 ts.nsecs = pinfo->fd->abs_usecs*1000;
101 proto_tree_add_time(fh_tree, hf_frame_arrival_time, tvb,
104 ts.secs = pinfo->fd->del_secs;
105 ts.nsecs = pinfo->fd->del_usecs*1000;
107 proto_tree_add_time(fh_tree, hf_frame_time_delta, tvb,
110 ts.secs = pinfo->fd->rel_secs;
111 ts.nsecs = pinfo->fd->rel_usecs*1000;
113 proto_tree_add_time(fh_tree, hf_frame_time_relative, tvb,
116 proto_tree_add_uint(fh_tree, hf_frame_number, tvb,
117 0, 0, pinfo->fd->num);
119 proto_tree_add_uint_format(fh_tree, hf_frame_packet_len, tvb,
120 0, 0, pkt_len, "Packet Length: %d byte%s", pkt_len,
121 plurality(pkt_len, "", "s"));
123 proto_tree_add_uint_format(fh_tree, hf_frame_capture_len, tvb,
124 0, 0, cap_len, "Capture Length: %d byte%s", cap_len,
125 plurality(cap_len, "", "s"));
127 /* Check for existences of P2P pseudo header */
128 if (pinfo->p2p_dir != P2P_DIR_UNKNOWN) {
129 proto_tree_add_uint(fh_tree, hf_frame_p2p_dir, tvb,
130 0, 0, pinfo->p2p_dir);
134 proto_tree_add_int_format(fh_tree, hf_frame_file_off, tvb,
135 0, 0, pinfo->fd->file_off,
136 "File Offset: %ld (0x%lx)",
137 pinfo->fd->file_off, pinfo->fd->file_off);
143 if (!dissector_try_port(wtap_encap_dissector_table, pinfo->fd->lnk_t,
146 if (check_col(pinfo->cinfo, COL_PROTOCOL))
147 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
148 if (check_col(pinfo->cinfo, COL_INFO))
149 col_add_fstr(pinfo->cinfo, COL_INFO, "WTAP_ENCAP = %u",
151 call_dissector(data_handle,tvb, pinfo, tree);
155 if (check_col(pinfo->cinfo, COL_INFO))
156 col_append_str(pinfo->cinfo, COL_INFO, "[Short Frame]");
157 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
158 "[Short Frame: %s]", pinfo->current_proto );
160 CATCH(ReportedBoundsError) {
161 if (pinfo->fragmented) {
163 * We were dissecting an unreassembled fragmented
164 * packet when the exception was thrown, so the
165 * problem isn't that the dissector expected
166 * something but it wasn't in the packet, the
167 * problem is that the dissector expected something
168 * but it wasn't in the fragment we dissected.
170 if (check_col(pinfo->cinfo, COL_INFO))
171 col_append_str(pinfo->cinfo, COL_INFO,
172 "[Unreassembled Packet]");
173 proto_tree_add_protocol_format(tree, proto_unreassembled,
174 tvb, 0, 0, "[Unreassembled Packet: %s]",
175 pinfo->current_proto );
177 if (check_col(pinfo->cinfo, COL_INFO))
178 col_append_str(pinfo->cinfo, COL_INFO,
179 "[Malformed Packet]");
180 proto_tree_add_protocol_format(tree, proto_malformed,
181 tvb, 0, 0, "[Malformed Packet: %s]",
182 pinfo->current_proto );
189 proto_register_frame(void)
191 static hf_register_info hf[] = {
192 { &hf_frame_arrival_time,
193 { "Arrival Time", "frame.time", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
196 { &hf_frame_time_delta,
197 { "Time delta from previous packet", "frame.time_delta", FT_RELATIVE_TIME, BASE_NONE, NULL,
201 { &hf_frame_time_relative,
202 { "Time relative to first packet", "frame.time_relative", FT_RELATIVE_TIME, BASE_NONE, NULL,
207 { "Frame Number", "frame.number", FT_UINT32, BASE_DEC, NULL, 0x0,
210 { &hf_frame_packet_len,
211 { "Total Frame Length", "frame.pkt_len", FT_UINT32, BASE_DEC, NULL, 0x0,
214 { &hf_frame_capture_len,
215 { "Capture Frame Length", "frame.cap_len", FT_UINT32, BASE_DEC, NULL, 0x0,
219 { "Point-to-Point Direction", "frame.p2p_dir", FT_UINT8, BASE_DEC, VALS(p2p_dirs), 0x0,
222 { &hf_frame_file_off,
223 { "File Offset", "frame.file_off", FT_INT32, BASE_DEC, NULL, 0x0,
227 static gint *ett[] = {
230 module_t *frame_module;
232 wtap_encap_dissector_table = register_dissector_table("wtap_encap",
233 "Wiretap encapsulation type", FT_UINT32, BASE_DEC);
235 proto_frame = proto_register_protocol("Frame", "Frame", "frame");
236 proto_register_field_array(proto_frame, hf, array_length(hf));
237 proto_register_subtree_array(ett, array_length(ett));
238 register_dissector("frame",dissect_frame,proto_frame);
240 /* You can't disable dissection of "Frame", as that would be
241 tantamount to not doing any dissection whatsoever. */
242 proto_set_cant_disable(proto_frame);
244 proto_short = proto_register_protocol("Short Frame", "Short frame", "short");
245 proto_malformed = proto_register_protocol("Malformed Packet",
246 "Malformed packet", "malformed");
247 proto_unreassembled = proto_register_protocol(
248 "Unreassembled Fragmented Packet",
249 "Unreassembled fragmented packet", "unreassembled");
251 /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
252 Packet" aren't really protocols, they're error indications;
253 disabling them makes no sense. */
254 proto_set_cant_disable(proto_short);
255 proto_set_cant_disable(proto_malformed);
256 proto_set_cant_disable(proto_unreassembled);
258 /* Our preferences */
259 frame_module = prefs_register_protocol(proto_frame, NULL);
260 prefs_register_bool_preference(frame_module, "show_file_off",
261 "Show File Offset", "Show File Offset", &show_file_off);
265 proto_reg_handoff_frame(void)
267 data_handle = find_dissector("data");