"hex_str_to_bytes()" modifies the GByteArray supplied to it, so don't
[obnox/wireshark/wip.git] / 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  * $Id: packet-ipfc.c,v 1.6 2003/01/21 05:21:03 guy Exp $
9  *
10  * Ethereal - Network traffic analyzer
11  * By Gerald Combs <gerald@ethereal.com>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include <glib.h>
38
39 #include <epan/packet.h>
40 #include "etypes.h"
41 #include "packet-fc.h"
42 #include "packet-ipfc.h"
43 #include "packet-llc.h"
44
45 /* Initialize the protocol and registered fields */
46 static int proto_ipfc              = -1;
47 static int hf_ipfc_network_da = -1;
48 static int hf_ipfc_network_sa = -1;
49
50 /* Initialize the subtree pointers */
51 static gint ett_ipfc = -1;
52 static dissector_handle_t llc_handle;
53
54 void
55 capture_ipfc (const guchar *pd, int len, packet_counts *ld)
56 {
57   if (!BYTES_ARE_IN_FRAME(0, len, 16)) {
58     ld->other++;
59     return;
60   }
61
62   capture_llc(pd, 16, len, ld);
63 }
64
65 static void
66 dissect_ipfc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
67 {
68
69 /* Set up structures needed to add the protocol subtree and manage it */
70     proto_item *ti;
71     proto_tree *ipfc_tree;
72     int offset = 0;
73     tvbuff_t *next_tvb;
74
75     /* Make entries in Protocol column and Info column on summary display */
76     if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
77         col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/FC");
78
79     if (tree) {
80         ti = proto_tree_add_protocol_format (tree, proto_ipfc, tvb, offset, 16,
81                                          "IP Over FC Network_Header");
82         ipfc_tree = proto_item_add_subtree (ti, ett_ipfc);
83
84         proto_tree_add_string (ipfc_tree, hf_ipfc_network_da, tvb, offset, 8,
85                                fcwwn_to_str (tvb_get_ptr (tvb, offset, 8)));
86         proto_tree_add_string (ipfc_tree, hf_ipfc_network_sa, tvb, offset+8, 8,
87                                fcwwn_to_str (tvb_get_ptr (tvb, offset+8, 8)));
88     }
89
90     next_tvb = tvb_new_subset (tvb, 16, -1, -1);
91     call_dissector(llc_handle, next_tvb, pinfo, tree);
92 }
93
94 /* Register the protocol with Ethereal */
95
96 /* this format is require because a script is used to build the C function
97    that calls all the protocol registration.
98 */
99
100 void
101 proto_register_ipfc (void)
102 {                 
103
104 /* Setup list of header fields  See Section 1.6.1 for details*/
105     static hf_register_info hf[] = {
106         { &hf_ipfc_network_da,
107           {"Network DA", "ipfc.nh.da", FT_STRING, BASE_HEX, NULL,
108            0x0, "", HFILL}},
109         { &hf_ipfc_network_sa,
110           {"Network SA", "ipfc.nh.sa", FT_STRING, BASE_HEX, NULL,
111            0x0, "", HFILL}},
112     };
113
114     /* Setup protocol subtree array */
115     static gint *ett[] = {
116         &ett_ipfc,
117     };
118
119     /* Register the protocol name and description */
120     proto_ipfc = proto_register_protocol("IP Over FC", "IPFC", "ipfc");
121
122     /* Required function calls to register the header fields and subtrees used */
123     proto_register_field_array(proto_ipfc, hf, array_length(hf));
124     proto_register_subtree_array(ett, array_length(ett));
125 }
126
127 /* If this dissector uses sub-dissector registration add a registration routine.
128    This format is required because a script is used to find these routines and
129    create the code that calls these routines.
130 */
131 void
132 proto_reg_handoff_ipfc (void)
133 {
134     dissector_handle_t ipfc_handle;
135
136     ipfc_handle = create_dissector_handle (dissect_ipfc, proto_ipfc);
137     dissector_add("wtap_encap", WTAP_ENCAP_IP_OVER_FC, ipfc_handle);
138
139     llc_handle = find_dissector ("llc");
140 }