2 * Routines for raw packet disassembly
4 * $Id: packet-raw.c,v 1.19 2000/11/17 21:00:35 gram Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
38 #include "packet-raw.h"
39 #include "packet-ip.h"
40 #include "packet-ppp.h"
42 static gint ett_raw = -1;
44 static const char zeroes[10];
47 capture_raw(const u_char *pd, packet_counts *ld)
49 /* So far, the only time we get raw connection types are with Linux and
50 * Irix PPP connections. We can't tell what type of data is coming down
51 * the line, so our safest bet is IP. - GCC
54 /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
55 * sometimes. This check should be removed when 2.2 is out.
57 if (BYTES_ARE_IN_FRAME(0,2) && pd[0] == 0xff && pd[1] == 0x03) {
58 capture_ppp(pd, 0, ld);
60 /* The Linux ISDN driver sends a fake MAC address before the PPP header
61 * on its ippp interfaces... */
62 else if (BYTES_ARE_IN_FRAME(0,8) && pd[6] == 0xff && pd[7] == 0x03) {
63 capture_ppp(pd, 6, ld);
65 /* ...except when it just puts out one byte before the PPP header... */
66 else if (BYTES_ARE_IN_FRAME(0,3) && pd[1] == 0xff && pd[2] == 0x03) {
67 capture_ppp(pd, 1, ld);
69 /* ...and if the connection is currently down, it sends 10 bytes of zeroes
70 * instead of a fake MAC address and PPP header. */
71 else if (BYTES_ARE_IN_FRAME(0,10) && memcmp(pd, zeroes, 10) == 0) {
72 capture_ip(pd, 10, ld);
75 capture_ip(pd, 0, ld);
80 dissect_raw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
85 const guint8 *next_pd;
88 /* load the top pane info. This should be overwritten by
89 the next protocol in the stack */
90 if(check_col(pinfo->fd, COL_RES_DL_SRC))
91 col_add_str(pinfo->fd, COL_RES_DL_SRC, "N/A" );
92 if(check_col(pinfo->fd, COL_RES_DL_DST))
93 col_add_str(pinfo->fd, COL_RES_DL_DST, "N/A" );
94 if(check_col(pinfo->fd, COL_PROTOCOL))
95 col_add_str(pinfo->fd, COL_PROTOCOL, "N/A" );
96 if(check_col(pinfo->fd, COL_INFO))
97 col_add_str(pinfo->fd, COL_INFO, "Raw packet data" );
99 /* populate a tree in the second pane with the status of the link
102 ti = proto_tree_add_text(tree, tvb, 0, 0, "Raw packet data" );
103 fh_tree = proto_item_add_subtree(ti, ett_raw);
104 proto_tree_add_text(fh_tree, tvb, 0, 0, "No link information available");
107 /* So far, the only time we get raw connection types are with Linux and
108 * Irix PPP connections. We can't tell what type of data is coming down
109 * the line, so our safest bet is IP. - GCC
112 /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
113 * sometimes. This check should be removed when 2.2 is out.
115 if (tvb_get_ntohs(tvb, 0) == 0xff03) {
116 dissect_ppp(tvb, pinfo, tree);
119 /* The Linux ISDN driver sends a fake MAC address before the PPP header
120 * on its ippp interfaces... */
121 else if (tvb_get_ntohs(tvb, 6) == 0xff03) {
122 next_tvb = tvb_new_subset(tvb, 6, -1, -1);
123 dissect_ppp(next_tvb, pinfo, tree);
126 /* ...except when it just puts out one byte before the PPP header... */
127 else if (tvb_get_ntohs(tvb, 1) == 0xff03) {
128 next_tvb = tvb_new_subset(tvb, 1, -1, -1);
129 dissect_ppp(next_tvb, pinfo, tree);
132 /* ...and if the connection is currently down, it sends 10 bytes of zeroes
133 * instead of a fake MAC address and PPP header. */
134 else if (memcmp(tvb_get_ptr(tvb, 0, 10), zeroes, 10) == 0) {
135 tvb_compat(tvb, &next_pd, &next_offset);
136 dissect_ip(next_pd, next_offset + 10, pinfo->fd, tree);
140 tvb_compat(tvb, &next_pd, &next_offset);
141 dissect_ip(next_pd, next_offset, pinfo->fd, tree);
144 g_assert_not_reached();
148 proto_register_raw(void)
150 static gint *ett[] = {
154 proto_register_subtree_array(ett, array_length(ett));