3 * Top-most dissector. Decides dissector based on Wiretap Encapsulation Type.
5 * $Id: packet-frame.c,v 1.3 2000/11/29 05:16:15 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 2000 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "timestamp.h"
35 #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_number = -1;
41 static int hf_frame_packet_len = -1;
42 static int hf_frame_capture_len = -1;
43 static int hf_frame_p2p_dir = -1;
44 static int proto_short = -1;
45 int proto_malformed = -1;
47 static gint ett_frame = -1;
49 static const value_string p2p_dirs[] = {
50 { P2P_DIR_SENT, "Sent" },
51 { P2P_DIR_RECV, "Received" },
55 static dissector_table_t wtap_encap_dissector_table;
58 dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
65 pinfo->current_proto = "Frame";
67 if (pinfo->fd->lnk_t == WTAP_ENCAP_LAPD ||
68 pinfo->fd->lnk_t == WTAP_ENCAP_PPP_WITH_PHDR) {
70 pinfo->p2p_dir = pinfo->pseudo_header->p2p.sent ? P2P_DIR_SENT : P2P_DIR_RECV;
73 /* Put in frame header information. */
76 cap_len = tvb_length(tvb);
77 pkt_len = tvb_reported_length(tvb);
79 ti = proto_tree_add_protocol_format(tree, proto_frame, tvb, 0, tvb_length(tvb),
80 "Frame %u (%u on wire, %u captured)", pinfo->fd->num, pkt_len, cap_len);
82 fh_tree = proto_item_add_subtree(ti, ett_frame);
84 tv.tv_sec = pinfo->fd->abs_secs;
85 tv.tv_usec = pinfo->fd->abs_usecs;
87 proto_tree_add_time(fh_tree, hf_frame_arrival_time, tvb,
90 tv.tv_sec = pinfo->fd->del_secs;
91 tv.tv_usec = pinfo->fd->del_usecs;
93 proto_tree_add_time(fh_tree, hf_frame_time_delta, tvb,
96 proto_tree_add_uint(fh_tree, hf_frame_number, tvb,
97 0, 0, pinfo->fd->num);
99 proto_tree_add_uint_format(fh_tree, hf_frame_packet_len, tvb,
100 0, 0, pkt_len, "Packet Length: %d byte%s", pkt_len,
101 plurality(pkt_len, "", "s"));
103 proto_tree_add_uint_format(fh_tree, hf_frame_capture_len, tvb,
104 0, 0, cap_len, "Capture Length: %d byte%s", cap_len,
105 plurality(cap_len, "", "s"));
107 /* Check for existences of P2P pseudo header */
108 if (pinfo->p2p_dir != P2P_DIR_UNKNOWN) {
109 proto_tree_add_uint(fh_tree, hf_frame_p2p_dir, tvb,
110 0, 0, pinfo->p2p_dir);
116 if (!dissector_try_port(wtap_encap_dissector_table, pinfo->fd->lnk_t,
119 if (check_col(pinfo->fd, COL_PROTOCOL))
120 col_set_str(pinfo->fd, COL_PROTOCOL, "UNKNOWN");
121 if (check_col(pinfo->fd, COL_INFO))
122 col_add_fstr(pinfo->fd, COL_INFO, "WTAP_ENCAP = 0x%x", pinfo->fd->lnk_t);
123 dissect_data(tvb, 0, pinfo, tree);
127 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
128 "[Short Frame: %s]", pinfo->current_proto );
130 CATCH(ReportedBoundsError) {
131 proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
132 "[Malformed Frame: %s]", pinfo->current_proto );
138 proto_register_frame(void)
140 static hf_register_info hf[] = {
141 { &hf_frame_arrival_time,
142 { "Arrival Time", "frame.time", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
145 { &hf_frame_time_delta,
146 { "Time delta from previous packet", "frame.time_delta", FT_RELATIVE_TIME, BASE_NONE, NULL,
151 { "Frame Number", "frame.number", FT_UINT32, BASE_DEC, NULL, 0x0,
154 { &hf_frame_packet_len,
155 { "Total Frame Length", "frame.pkt_len", FT_UINT32, BASE_DEC, NULL, 0x0,
158 { &hf_frame_capture_len,
159 { "Capture Frame Length", "frame.cap_len", FT_UINT32, BASE_DEC, NULL, 0x0,
163 { "Point-to-Point Direction", "frame.p2p_dir", FT_UINT8, BASE_DEC, VALS(p2p_dirs), 0x0,
166 static gint *ett[] = {
170 wtap_encap_dissector_table = register_dissector_table("wtap_encap");
172 proto_frame = proto_register_protocol("Frame", "frame");
173 proto_register_field_array(proto_frame, hf, array_length(hf));
174 proto_register_subtree_array(ett, array_length(ett));
176 proto_short = proto_register_protocol("Short Frame", "short");
177 proto_malformed = proto_register_protocol("Malformed Frame", "malformed");