5a3497751d35ae283d83ed0e2817937142f0b501
[obnox/wireshark/wip.git] / packet-raw.c
1 /* packet-raw.c
2  * Routines for raw packet disassembly
3  *
4  * $Id: packet-raw.c,v 1.15 2000/05/19 05:29:42 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  *
9  * This file created and by Mike Hall <mlh@io.com>
10  * Copyright 1998
11  * 
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.
16  * 
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.
21  * 
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <glib.h>
36 #include "packet.h"
37 #include "packet-raw.h"
38 #include "packet-ip.h"
39
40 static gint ett_raw = -1;
41
42 void
43 capture_raw( const u_char *pd, packet_counts *ld ) {
44
45   /* So far, the only time we get raw connection types are with Linux and
46    * Irix PPP connections.  We can't tell what type of data is coming down
47    * the line, so our safest bet is IP. - GCC
48    */
49    
50   /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
51    * sometimes.  This check should be removed when 2.2 is out.
52    */
53   if (pd[0] == 0xff && pd[1] == 0x03)
54     capture_ip(pd, 4, ld);
55   else
56     capture_ip(pd, 0, ld);
57 }
58
59 void
60 dissect_raw( const u_char *pd, frame_data *fd, proto_tree *tree ) {
61   proto_tree *fh_tree;
62   proto_item *ti;
63
64   /* load the top pane info. This should be overwritten by
65      the next protocol in the stack */
66   if(check_col(fd, COL_RES_DL_SRC))
67     col_add_str(fd, COL_RES_DL_SRC, "N/A" );
68   if(check_col(fd, COL_RES_DL_DST))
69     col_add_str(fd, COL_RES_DL_DST, "N/A" );
70   if(check_col(fd, COL_PROTOCOL))
71     col_add_str(fd, COL_PROTOCOL, "N/A" );
72   if(check_col(fd, COL_INFO))
73     col_add_str(fd, COL_INFO, "Raw packet data" );
74
75   /* populate a tree in the second pane with the status of the link
76      layer (ie none) */
77   if(tree) {
78     ti = proto_tree_add_text(tree, NullTVB, 0, 0, "Raw packet data" );
79     fh_tree = proto_item_add_subtree(ti, ett_raw);
80     proto_tree_add_text(fh_tree, NullTVB, 0, 0, "No link information available");
81   }
82
83   /* So far, the only time we get raw connection types are with Linux and
84    * Irix PPP connections.  We can't tell what type of data is coming down
85    * the line, so our safest bet is IP. - GCC
86    */
87    
88   /* Currently, the Linux 2.1.xxx PPP driver passes back some of the header
89    * sometimes.  This check should be removed when 2.2 is out.
90    */
91   if (pd[0] == 0xff && pd[1] == 0x03)
92     dissect_ip(pd, 4, fd, tree);
93   else
94     dissect_ip(pd, 0, fd, tree);
95 }
96
97 void
98 proto_register_raw(void)
99 {
100   static gint *ett[] = {
101     &ett_raw,
102   };
103
104   proto_register_subtree_array(ett, array_length(ett));
105 }