Trivial warning fixes
[obnox/wireshark/wip.git] / epan / dissectors / packet-aruba-adp.c
1 /* packet-aruba-adp.c
2  * Routines for Aruba ADP header disassembly
3  *
4  * $Id$
5  *
6  * Giles Scott < gscott <at> arubanetworks dot 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <glib.h>
34 #include <epan/packet.h>
35 #include <epan/addr_resolv.h>
36
37 #define UDP_PORT_ADP 8200
38 #define ADP_REQUEST 1
39 #define ADP_RESPONSE 2
40
41 static int proto_aruba_adp = -1;
42 static gint ett_aruba_adp  = -1;
43
44 static int hf_adp_version  = -1;
45 static int hf_adp_type     = -1;
46 static int hf_adp_id       = -1;
47 static int hf_adp_mac      = -1;
48 static int hf_adp_switchip = -1;
49
50 static const value_string adp_type_val[] =
51 {
52   {1, "Request"},
53   {2, "Response"},
54   {0, NULL},
55 };
56
57 static void
58 dissect_aruba_adp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
59 {
60   proto_tree *ti = NULL;
61   proto_tree *aruba_adp_tree = NULL;
62   guint16 type;
63   const guint8 *src_mac;
64   const guint8 *switchip;
65
66
67   if (check_col(pinfo->cinfo, COL_PROTOCOL))
68     col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADP");
69   if (check_col(pinfo->cinfo, COL_INFO))
70     col_clear(pinfo->cinfo, COL_INFO);
71
72
73   if (tree) {
74     ti = proto_tree_add_item(tree, proto_aruba_adp, tvb, 0, 0, FALSE);
75     aruba_adp_tree = proto_item_add_subtree(ti, ett_aruba_adp);
76
77     proto_tree_add_item(aruba_adp_tree, hf_adp_version, tvb, 0, 2, FALSE);
78   }
79   type = tvb_get_ntohs(tvb, 2);
80
81   if (tree) {
82     proto_tree_add_item(aruba_adp_tree, hf_adp_type, tvb, 2, 2, FALSE); 
83
84     proto_tree_add_item(aruba_adp_tree, hf_adp_id, tvb, 4, 2, FALSE);
85   }
86
87   switch(type){
88     case ADP_REQUEST:
89
90       proto_tree_add_item(aruba_adp_tree, hf_adp_mac, tvb, 6, 6, FALSE);
91       src_mac = tvb_get_ptr(tvb, 6, 6);
92
93       if (check_col(pinfo->cinfo, COL_INFO))
94         col_add_fstr(pinfo->cinfo, COL_INFO, "ADP Request Src MAC: %s", ether_to_str(src_mac));
95
96       proto_item_append_text(ti, ", Request Src MAC: %s", ether_to_str(src_mac));
97       break;
98      
99     case ADP_RESPONSE:
100        
101       proto_tree_add_item(aruba_adp_tree, hf_adp_switchip, tvb, 6, 4, FALSE);
102       switchip = tvb_get_ptr(tvb, 6, 4);
103         
104       if (check_col(pinfo->cinfo, COL_INFO))
105         col_add_fstr(pinfo->cinfo, COL_INFO, "ADP Response Switch IP: %s", ip_to_str(switchip));
106      
107       proto_item_append_text(ti, ", Response Switch IP: %s", ip_to_str(switchip)); 
108       break;
109       
110     default:
111         break;
112         
113   }
114 }
115
116 void
117 proto_register_aruba_adp(void)
118 {
119   static hf_register_info hf[] = {
120     { &hf_adp_version,
121     { "Version", "adp.version", FT_UINT16, BASE_DEC, NULL,0x0,
122     "ADP version", HFILL}},
123
124     { &hf_adp_type,
125     { "Type", "adp.type", FT_UINT16, BASE_DEC, VALS(adp_type_val), 0x0,
126     "ADP type", HFILL}},
127
128     { &hf_adp_id,
129     { "Transaction ID", "adp.id", FT_UINT16, BASE_DEC, NULL, 0x0,
130     "ADP transaction ID", HFILL}},
131
132     { &hf_adp_mac,
133     { "MAC address", "adp.mac", FT_ETHER, BASE_NONE, NULL, 0x0,
134     "MAC address", HFILL}},
135
136     { &hf_adp_switchip,
137     { "Switch IP", "adp.switch", FT_IPv4, BASE_NONE, NULL, 0x0,
138     "Switch IP address", HFILL}},
139
140     };
141
142   static gint *ett[] = {
143     &ett_aruba_adp,
144   };
145
146   proto_aruba_adp = proto_register_protocol("Aruba - Aruba Discovery Protocol",
147                     "ADP", "adp");
148   proto_register_field_array(proto_aruba_adp, hf, array_length(hf));
149   proto_register_subtree_array(ett, array_length(ett));
150 }
151
152
153 void
154 proto_reg_handoff_aruba_adp(void)
155 {
156   dissector_handle_t adp_handle;
157
158   adp_handle = create_dissector_handle(dissect_aruba_adp, proto_aruba_adp);
159   dissector_add("udp.port", UDP_PORT_ADP, adp_handle);
160 }
161
162