fix usage of "if(tree) {" to display the right things, even if no coloring rule is set
[obnox/wireshark/wip.git] / epan / dissectors / packet-snaeth.c
1 /* packet-snaeth.c
2  * Routines for SNA-over-Ethernet (Ethernet type 80d5)
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include "etypes.h"
32
33 /*
34  * See
35  *
36  * http://www.cisco.com/univercd/cc/td/doc/product/software/ssr90/rpc_r/18059.pdf
37  */
38
39 static int proto_snaeth = -1;
40 static int hf_snaeth_len = -1;
41
42 static gint ett_snaeth = -1;
43
44 static dissector_handle_t llc_handle;
45
46 static void
47 dissect_snaeth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
48 {
49         proto_tree      *snaeth_tree;
50         proto_item      *snaeth_ti;
51         guint16         len;
52         tvbuff_t        *next_tvb;
53
54         if (check_col(pinfo->cinfo, COL_PROTOCOL))
55                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNAETH");
56         if (check_col(pinfo->cinfo, COL_INFO))
57                 col_set_str(pinfo->cinfo, COL_INFO, "SNA over Ethernet");
58
59         /* length */
60         len = tvb_get_ntohs(tvb, 0);
61
62         if (tree) {
63                 snaeth_ti = proto_tree_add_item(tree, proto_snaeth, tvb, 0, 3,
64                     FALSE);
65                 snaeth_tree = proto_item_add_subtree(snaeth_ti, ett_snaeth);
66                 proto_tree_add_uint(snaeth_tree, hf_snaeth_len, tvb, 0, 2, len);
67                 proto_tree_add_text(snaeth_tree, tvb, 2, 1, "Padding");
68         }
69
70         /*
71          * Adjust the length of this tvbuff to include only the SNA-over-
72          * Ethernet header and data.
73          */
74         set_actual_length(tvb, 3 + len);
75
76         /*
77          * Rest of packet starts with an 802.2 LLC header.
78          */
79         next_tvb = tvb_new_subset(tvb, 3, -1, -1);
80         call_dissector(llc_handle, next_tvb, pinfo, tree);
81 }
82
83 void
84 proto_register_snaeth(void)
85 {
86         static hf_register_info hf[] = {
87                 { &hf_snaeth_len,
88                 { "Length",     "snaeth_len", FT_UINT16, BASE_DEC, NULL, 0x0,
89                         "Length of LLC payload", HFILL }},
90         };
91         static gint *ett[] = {
92                 &ett_snaeth,
93         };
94
95         proto_snaeth = proto_register_protocol("SNA-over-Ethernet",
96             "SNAETH", "snaeth");
97         proto_register_field_array(proto_snaeth, hf, array_length(hf));
98         proto_register_subtree_array(ett, array_length(ett));
99 }
100
101 void
102 proto_reg_handoff_snaeth(void)
103 {
104         dissector_handle_t snaeth_handle;
105
106         /*
107          * Get handle for the LLC dissector.
108          */
109         llc_handle = find_dissector("llc");
110
111         snaeth_handle = create_dissector_handle(dissect_snaeth, proto_snaeth);
112         dissector_add("ethertype", ETHERTYPE_SNA, snaeth_handle);
113 }