Use "tvb_get_ntohieee_float()" to fetch floating-point numbers.
[obnox/wireshark/wip.git] / packet-snaeth.c
1 /* packet-snaeth.c
2  * Routines for SNA-over-Ethernet (Ethernet type 80d5)
3  *
4  * $Id: packet-snaeth.c,v 1.2 2002/02/17 00:51:19 guy Exp $
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 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32
33 #include <glib.h>
34 #include <epan/packet.h>
35 #include "etypes.h"
36
37 /*
38  * See
39  *
40  * http://www.cisco.com/univercd/cc/td/doc/product/software/ssr90/rpc_r/18059.pdf
41  */
42
43 static int proto_snaeth = -1;
44 static int hf_snaeth_len = -1;
45
46 static gint ett_snaeth = -1;
47
48 static dissector_handle_t llc_handle;
49
50 static void
51 dissect_snaeth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
52 {
53         proto_tree      *snaeth_tree;
54         proto_item      *snaeth_ti;
55         guint16         len;
56         tvbuff_t        *next_tvb;
57
58         if (check_col(pinfo->cinfo, COL_PROTOCOL))
59                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNAETH");
60         if (check_col(pinfo->cinfo, COL_INFO))
61                 col_set_str(pinfo->cinfo, COL_INFO, "SNA over Ethernet");
62
63         /* length */
64         len = tvb_get_ntohs(tvb, 0);
65
66         if (tree) {
67                 snaeth_ti = proto_tree_add_item(tree, proto_snaeth, tvb, 0, 3,
68                     FALSE);
69                 snaeth_tree = proto_item_add_subtree(snaeth_ti, ett_snaeth);
70                 proto_tree_add_uint(snaeth_tree, hf_snaeth_len, tvb, 0, 2, len);
71                 proto_tree_add_text(snaeth_tree, tvb, 2, 1, "Padding");
72         }
73
74         /*
75          * Adjust the length of this tvbuff to include only the SNA-over-
76          * Ethernet header and data.
77          */
78         set_actual_length(tvb, 3 + len);
79
80         /*
81          * Rest of packet starts with an 802.2 LLC header.
82          */
83         next_tvb = tvb_new_subset(tvb, 3, -1, -1);
84         call_dissector(llc_handle, next_tvb, pinfo, tree);
85 }
86
87 void
88 proto_register_snaeth(void)
89 {
90         static hf_register_info hf[] = {
91                 { &hf_snaeth_len,
92                 { "Length",     "snaeth_len", FT_UINT16, BASE_DEC, NULL, 0x0,
93                         "Length of LLC payload", HFILL }},
94         };
95         static gint *ett[] = {
96                 &ett_snaeth,
97         };
98
99         proto_snaeth = proto_register_protocol("SNA-over-Ethernet",
100             "SNAETH", "snaeth");
101         proto_register_field_array(proto_snaeth, hf, array_length(hf));
102         proto_register_subtree_array(ett, array_length(ett));
103 }
104
105 void
106 proto_reg_handoff_snaeth(void)
107 {
108         dissector_handle_t snaeth_handle;
109
110         /*
111          * Get handle for the LLC dissector.
112          */
113         llc_handle = find_dissector("llc");
114
115         snaeth_handle = create_dissector_handle(dissect_snaeth, proto_snaeth);
116         dissector_add("ethertype", ETHERTYPE_SNA, snaeth_handle);
117 }