Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-clip.c
1 /* packet-clip.c
2  * Routines for clip packet disassembly
3  *
4  * $Id: packet-clip.c,v 1.21 2002/08/28 21:00:08 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  *
9  * This file created by Thierry Andry <Thierry.Andry@advalvas.be>
10  * from nearly-the-same packet-raw.c created by Mike Hall <mlh@io.com>
11  * Copyright 1999
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include "packet-clip.h"
35 #include "packet-ip.h"
36
37 static gint ett_clip = -1;
38
39 static dissector_handle_t ip_handle;
40
41 void
42 capture_clip( const guchar *pd, int len, packet_counts *ld ) {
43
44     capture_ip(pd, 0, len, ld);
45 }
46
47 static void
48 dissect_clip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
49 {
50   proto_tree    *fh_tree;
51   proto_item    *ti;
52
53   pinfo->current_proto = "CLIP";
54
55   /* load the top pane info. This should be overwritten by
56      the next protocol in the stack */
57   if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
58     col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A" );
59   if(check_col(pinfo->cinfo, COL_RES_DL_DST))
60     col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A" );
61   if(check_col(pinfo->cinfo, COL_PROTOCOL))
62     col_set_str(pinfo->cinfo, COL_PROTOCOL, "CLIP" );
63   if(check_col(pinfo->cinfo, COL_INFO))
64     col_set_str(pinfo->cinfo, COL_INFO, "Classical IP frame" );
65
66   /* populate a tree in the second pane with the status of the link
67      layer (ie none)
68
69      XXX - the Linux Classical IP code supports both LLC Encapsulation,
70      which puts an LLC header and possibly a SNAP header in front of
71      the network-layer header, and VC Based Multiplexing, which puts
72      no headers in front of the network-layer header.
73
74      The ATM on Linux code includes a patch to "tcpdump"
75      that compares the first few bytes of the packet with the
76      LLC header that Classical IP frames may have and, if there's
77      a SNAP LLC header at the beginning of the packet, it gets
78      the packet type from that header and uses that, otherwise
79      it treats the packet as being raw IP with no link-level
80      header, in order to handle both of those.
81
82      This code, however, won't handle LLC Encapsulation.  We've
83      not yet seen a capture taken on a machine using LLC Encapsulation,
84      however.  If we see one, we can modify the code.
85
86      A future version of libpcap, however, will probably use DLT_LINUX_SLL
87      for both of those cases, to avoid the headache of having to
88      generate capture-filter code to handle both of those cases. */
89   if(tree) {
90     ti = proto_tree_add_text(tree, tvb, 0, 0, "Classical IP frame" );
91     fh_tree = proto_item_add_subtree(ti, ett_clip);
92     proto_tree_add_text(fh_tree, tvb, 0, 0, "No link information available");
93   }
94   call_dissector(ip_handle, tvb, pinfo, tree);
95 }
96
97 void
98 proto_register_clip(void)
99 {
100   static gint *ett[] = {
101     &ett_clip,
102   };
103
104   proto_register_subtree_array(ett, array_length(ett));
105 }
106
107 void
108 proto_reg_handoff_clip(void)
109 {
110   dissector_handle_t clip_handle;
111
112   /*
113    * Get a handle for the IP dissector.
114    */
115   ip_handle = find_dissector("ip");
116
117   clip_handle = create_dissector_handle(dissect_clip, -1);
118       /* XXX - no protocol, can't be disabled */
119   dissector_add("wtap_encap", WTAP_ENCAP_LINUX_ATM_CLIP, clip_handle);
120 }