2 * Routines for raw packet disassembly
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
9 * This file created and by Mike Hall <mlh@io.com>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include "packet-raw.h"
34 #include "packet-ip.h"
35 #include "packet-ppp.h"
37 static int proto_raw
= -1;
38 static gint ett_raw
= -1;
40 static const char zeroes
[10] = {0,0,0,0,0,0,0,0,0,0};
42 static dissector_handle_t ip_handle
;
43 static dissector_handle_t ipv6_handle
;
44 static dissector_handle_t data_handle
;
45 static dissector_handle_t ppp_hdlc_handle
;
48 capture_raw(const guchar
*pd
, int len
, packet_counts
*ld
)
50 /* So far, the only time we get raw connection types are with Linux and
51 * Irix PPP connections. We can't tell what type of data is coming down
52 * the line, so our safest bet is IP. - GCC
55 /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
56 * sometimes. This check should be removed when 2.2 is out.
58 if (BYTES_ARE_IN_FRAME(0,len
,2) && pd
[0] == 0xff && pd
[1] == 0x03) {
59 capture_ppp_hdlc(pd
, 0, len
, ld
);
61 /* The Linux ISDN driver sends a fake MAC address before the PPP header
62 * on its ippp interfaces... */
63 else if (BYTES_ARE_IN_FRAME(0,len
,8) && pd
[6] == 0xff && pd
[7] == 0x03) {
64 capture_ppp_hdlc(pd
, 6, len
, ld
);
66 /* ...except when it just puts out one byte before the PPP header... */
67 else if (BYTES_ARE_IN_FRAME(0,len
,3) && pd
[1] == 0xff && pd
[2] == 0x03) {
68 capture_ppp_hdlc(pd
, 1, len
, ld
);
70 /* ...and if the connection is currently down, it sends 10 bytes of zeroes
71 * instead of a fake MAC address and PPP header. */
72 else if (BYTES_ARE_IN_FRAME(0,len
,10) && memcmp(pd
, zeroes
, 10) == 0) {
73 capture_ip(pd
, 10, len
, ld
);
77 * OK, is this IPv4 or IPv6?
79 if (BYTES_ARE_IN_FRAME(0,len
,1)) {
80 switch (pd
[0] & 0xF0) {
84 capture_ip(pd
, 0, len
, ld
);
90 capture_ipv6(pd
, 0, len
, ld
);
99 dissect_raw(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
105 /* load the top pane info. This should be overwritten by
106 the next protocol in the stack */
107 col_set_str(pinfo
->cinfo
, COL_RES_DL_SRC
, "N/A");
108 col_set_str(pinfo
->cinfo
, COL_RES_DL_DST
, "N/A");
109 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "N/A");
110 col_set_str(pinfo
->cinfo
, COL_INFO
, "Raw packet data");
112 /* populate a tree in the second pane with the status of the link
115 ti
= proto_tree_add_item(tree
, proto_raw
, tvb
, 0, 0, ENC_NA
);
116 fh_tree
= proto_item_add_subtree(ti
, ett_raw
);
117 proto_tree_add_text(fh_tree
, tvb
, 0, 0, "No link information available");
120 if (pinfo
->fd
->lnk_t
== WTAP_ENCAP_RAW_IP4
) {
121 call_dissector(ip_handle
, tvb
, pinfo
, tree
);
123 else if (pinfo
->fd
->lnk_t
== WTAP_ENCAP_RAW_IP6
) {
124 call_dissector(ipv6_handle
, tvb
, pinfo
, tree
);
128 /* So far, the only time we get raw connection types are with Linux and
129 * Irix PPP connections. We can't tell what type of data is coming down
130 * the line, so our safest bet is IP. - GCC
133 /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
134 * sometimes. This check should be removed when 2.2 is out.
136 if (tvb_get_ntohs(tvb
, 0) == 0xff03) {
137 call_dissector(ppp_hdlc_handle
, tvb
, pinfo
, tree
);
139 /* The Linux ISDN driver sends a fake MAC address before the PPP header
140 * on its ippp interfaces... */
141 else if (tvb_get_ntohs(tvb
, 6) == 0xff03) {
142 next_tvb
= tvb_new_subset_remaining(tvb
, 6);
143 call_dissector(ppp_hdlc_handle
, next_tvb
, pinfo
, tree
);
145 /* ...except when it just puts out one byte before the PPP header... */
146 else if (tvb_get_ntohs(tvb
, 1) == 0xff03) {
147 next_tvb
= tvb_new_subset_remaining(tvb
, 1);
148 call_dissector(ppp_hdlc_handle
, next_tvb
, pinfo
, tree
);
150 /* ...and if the connection is currently down, it sends 10 bytes of zeroes
151 * instead of a fake MAC address and PPP header. */
152 else if (tvb_memeql(tvb
, 0, zeroes
,10) == 0) {
153 next_tvb
= tvb_new_subset_remaining(tvb
, 10);
154 call_dissector(ip_handle
, next_tvb
, pinfo
, tree
);
158 * OK, is this IPv4 or IPv6?
160 switch (tvb_get_guint8(tvb
, 0) & 0xF0) {
164 call_dissector(ip_handle
, tvb
, pinfo
, tree
);
169 call_dissector(ipv6_handle
, tvb
, pinfo
, tree
);
173 /* None of the above. */
174 call_dissector(data_handle
, tvb
, pinfo
, tree
);
181 proto_register_raw(void)
183 static gint
*ett
[] = {
187 proto_raw
= proto_register_protocol("Raw packet data", "Raw", "raw");
188 proto_register_subtree_array(ett
, array_length(ett
));
192 proto_reg_handoff_raw(void)
194 dissector_handle_t raw_handle
;
197 * Get handles for the IP, IPv6, undissected-data, and
198 * PPP-in-HDLC-like-framing dissectors.
200 ip_handle
= find_dissector("ip");
201 ipv6_handle
= find_dissector("ipv6");
202 data_handle
= find_dissector("data");
203 ppp_hdlc_handle
= find_dissector("ppp_hdlc");
204 raw_handle
= create_dissector_handle(dissect_raw
, proto_raw
);
205 dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP
, raw_handle
);
206 dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP4
, raw_handle
);
207 dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP6
, raw_handle
);