create_dissector_handle -> new_create_dissector_handle
[metze/wireshark/wip.git] / epan / dissectors / packet-ipfc.c
1 /* packet-ipfc.c
2  * Routines for Decoding Network_Header for IP-over-FC when we only
3  * capture the frame starting at the Network_Header (as opposed to
4  * when we have the full FC frame).
5  * See RFC 2625.
6  * Copyright 2001, Dinesh G Dutt <ddutt@cisco.com>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <epan/packet.h>
30 #include <wiretap/wtap.h>
31 #include <epan/to_str.h>
32
33 #include "packet-ipfc.h"
34 #include "packet-llc.h"
35
36 void proto_register_ipfc(void);
37 void proto_reg_handoff_ipfc(void);
38
39 /* Initialize the protocol and registered fields */
40 static int proto_ipfc              = -1;
41 static int hf_ipfc_network_da = -1;
42 static int hf_ipfc_network_sa = -1;
43
44 /* Initialize the subtree pointers */
45 static gint ett_ipfc = -1;
46 static dissector_handle_t llc_handle;
47
48 void
49 capture_ipfc (const guchar *pd, int len, packet_counts *ld)
50 {
51   if (!BYTES_ARE_IN_FRAME(0, len, 16)) {
52     ld->other++;
53     return;
54   }
55
56   capture_llc(pd, 16, len, ld);
57 }
58
59 static int
60 dissect_ipfc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
61 {
62
63 /* Set up structures needed to add the protocol subtree and manage it */
64     proto_item *ti;
65     proto_tree *ipfc_tree;
66     int offset = 0;
67     tvbuff_t *next_tvb;
68
69     /* Make entries in Protocol column and Info column on summary display */
70     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/FC");
71
72     if (tree) {
73         ti = proto_tree_add_protocol_format (tree, proto_ipfc, tvb, offset, 16,
74                                          "IP Over FC Network_Header");
75         ipfc_tree = proto_item_add_subtree (ti, ett_ipfc);
76
77         proto_tree_add_item (ipfc_tree, hf_ipfc_network_da, tvb, offset, 8, ENC_NA);
78         proto_tree_add_item (ipfc_tree, hf_ipfc_network_sa, tvb, offset+8, 8, ENC_NA);
79     }
80
81     next_tvb = tvb_new_subset_remaining (tvb, 16);
82     call_dissector(llc_handle, next_tvb, pinfo, tree);
83     return tvb_captured_length(tvb);
84 }
85
86 /* Register the protocol with Wireshark */
87
88 /* this format is require because a script is used to build the C function
89    that calls all the protocol registration.
90 */
91
92 void
93 proto_register_ipfc (void)
94 {
95
96 /* Setup list of header fields  See Section 1.6.1 for details*/
97     static hf_register_info hf[] = {
98         { &hf_ipfc_network_da,
99           {"Network DA", "ipfc.nh.da", FT_FCWWN, BASE_NONE, NULL,
100            0x0, NULL, HFILL}},
101         { &hf_ipfc_network_sa,
102           {"Network SA", "ipfc.nh.sa", FT_FCWWN, BASE_NONE, NULL,
103            0x0, NULL, HFILL}},
104     };
105
106     /* Setup protocol subtree array */
107     static gint *ett[] = {
108         &ett_ipfc,
109     };
110
111     /* Register the protocol name and description */
112     proto_ipfc = proto_register_protocol("IP Over FC", "IPFC", "ipfc");
113
114     /* Required function calls to register the header fields and subtrees used */
115     proto_register_field_array(proto_ipfc, hf, array_length(hf));
116     proto_register_subtree_array(ett, array_length(ett));
117 }
118
119 /* If this dissector uses sub-dissector registration add a registration routine.
120    This format is required because a script is used to find these routines and
121    create the code that calls these routines.
122 */
123 void
124 proto_reg_handoff_ipfc (void)
125 {
126     dissector_handle_t ipfc_handle;
127
128     ipfc_handle = new_create_dissector_handle (dissect_ipfc, proto_ipfc);
129     dissector_add_uint("wtap_encap", WTAP_ENCAP_IP_OVER_FC, ipfc_handle);
130
131     llc_handle = find_dissector ("llc");
132 }
133
134 /*
135  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
136  *
137  * Local variables:
138  * c-basic-offset: 4
139  * tab-width: 8
140  * indent-tabs-mode: nil
141  * End:
142  *
143  * vi: set shiftwidth=4 tabstop=8 expandtab:
144  * :indentSize=4:tabSize=8:noTabs=true:
145  */