Clean up white space.
[obnox/wireshark/wip.git] / packet-lapbether.c
1 /* packet-lapbether.c
2  * Routines for lapbether frame disassembly
3  * Richard Sharpe <rsharpe@ns.aus.com> based on the lapb module by
4  * Olivier Abad <oabad@cybercable.fr>
5  *
6  * $Id: packet-lapbether.c,v 1.9 2002/01/21 07:36:36 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.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 <stdio.h>
36 #include <glib.h>
37 #include <string.h>
38 #include <epan/packet.h>
39 #include "etypes.h"
40
41 static int proto_lapbether = -1;
42
43 static int hf_lapbether_length = -1;
44
45 static gint ett_lapbether = -1;
46
47 static dissector_handle_t lapb_handle;
48
49 static void
50 dissect_lapbether(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 {
52     proto_tree          *lapbether_tree, *ti;
53     int                 len;
54     tvbuff_t            *next_tvb;
55
56     if (check_col(pinfo->cinfo, COL_PROTOCOL))
57         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPBETHER");
58     if (check_col(pinfo->cinfo, COL_INFO))
59         col_clear(pinfo->cinfo, COL_INFO);
60
61     len = tvb_get_guint8(tvb, 0) + tvb_get_guint8(tvb, 1) * 256;
62
63     if (tree) {
64
65       ti = proto_tree_add_protocol_format(tree, proto_lapbether, tvb, 0, 2, 
66                                           "LAPBETHER");
67
68       lapbether_tree = proto_item_add_subtree(ti, ett_lapbether);
69       proto_tree_add_uint_format(lapbether_tree, hf_lapbether_length, tvb, 0, 2, 
70                                  len, "Length: %u", len);
71
72     }
73
74     next_tvb = tvb_new_subset(tvb, 2, len, len);
75     call_dissector(lapb_handle, next_tvb, pinfo, tree);
76
77 }
78
79 void
80 proto_register_lapbether(void)
81 {
82     static hf_register_info hf[] = {
83       { &hf_lapbether_length,
84         { "Length Field", "lapbether.length", FT_UINT16, BASE_DEC, NULL, 0x0, 
85           "LAPBEther Length Field", HFILL }},
86
87     };
88     static gint *ett[] = {
89         &ett_lapbether,
90     };
91
92     proto_lapbether = proto_register_protocol ("Link Access Procedure Balanced Ethernet (LAPBETHER)",
93         "LAPBETHER", "lapbether");
94     proto_register_field_array (proto_lapbether, hf, array_length(hf));
95     proto_register_subtree_array(ett, array_length(ett));
96 }
97
98 /* The registration hand-off routine */
99 void
100 proto_reg_handoff_lapbether(void)
101 {
102   dissector_handle_t lapbether_handle;
103
104   /*
105    * Get a handle for the LAPB dissector.
106    */
107   lapb_handle = find_dissector("lapb");
108
109   lapbether_handle = create_dissector_handle(dissect_lapbether,
110                                              proto_lapbether);
111   dissector_add("ethertype", ETHERTYPE_DEC, lapbether_handle);
112
113 }