2 * Routines for Appletalk ARP packet disassembly
6 * Simon Wilkinson <sxw@dcs.ed.ac.uk>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
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.
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.
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.
29 #include <epan/packet.h>
30 #include <epan/strutil.h>
31 #include <epan/wmem/wmem.h>
32 #include <epan/etypes.h>
33 #include <epan/to_str.h>
35 /* Forward declarations */
36 void proto_register_aarp(void);
37 void proto_reg_handoff_aarp(void);
39 static int proto_aarp
= -1;
40 static int hf_aarp_hard_type
= -1;
41 static int hf_aarp_proto_type
= -1;
42 static int hf_aarp_hard_size
= -1;
43 static int hf_aarp_proto_size
= -1;
44 static int hf_aarp_opcode
= -1;
45 static int hf_aarp_src_hw
= -1;
46 static int hf_aarp_src_hw_mac
= -1;
47 static int hf_aarp_src_proto
= -1;
48 static int hf_aarp_src_proto_id
= -1;
49 static int hf_aarp_dst_hw
= -1;
50 static int hf_aarp_dst_hw_mac
= -1;
51 static int hf_aarp_dst_proto
= -1;
52 static int hf_aarp_dst_proto_id
= -1;
54 static gint ett_aarp
= -1;
57 #define AARP_REQUEST 0x0001
60 #define AARP_REPLY 0x0002
63 #define AARP_PROBE 0x0003
66 /* The following is screwed up shit to deal with the fact that
67 the linux kernel edits the packet inline. */
68 #define AARP_REQUEST_SWAPPED 0x0100
69 #define AARP_REPLY_SWAPPED 0x0200
70 #define AARP_PROBE_SWAPPED 0x0300
72 static const value_string op_vals
[] = {
73 {AARP_REQUEST
, "request" },
74 {AARP_REPLY
, "reply" },
75 {AARP_PROBE
, "probe" },
76 {AARP_REQUEST_SWAPPED
, "request" },
77 {AARP_REPLY_SWAPPED
, "reply" },
78 {AARP_PROBE_SWAPPED
, "probe" },
81 /* AARP protocol HARDWARE identifiers. */
82 #define AARPHRD_ETHER 1 /* Ethernet 10Mbps */
83 #define AARPHRD_TR 2 /* Token Ring */
85 static const value_string hrd_vals
[] = {
86 {AARPHRD_ETHER
, "Ethernet" },
87 {AARPHRD_TR
, "Token Ring" },
91 * Given the hardware address type and length, check whether an address
92 * is an Ethernet address - the address must be of type "Ethernet" or
93 * "Token Ring", and the length must be 6 bytes.
95 #define AARP_HW_IS_ETHER(ar_hrd, ar_hln) \
96 (((ar_hrd) == AARPHRD_ETHER || (ar_hrd) == AARPHRD_TR) \
100 * Given the protocol address type and length, check whether an address
101 * is an Appletalk address - the address must be of type "Appletalk",
102 * and the length must be 4 bytes.
104 #define AARP_PRO_IS_ATALK(ar_pro, ar_pln) \
105 ((ar_pro) == ETHERTYPE_ATALK && (ar_pln) == 4)
108 tvb_atalkid_to_str(tvbuff_t
*tvb
, gint offset
)
113 cur
=(gchar
*)wmem_alloc(wmem_packet_scope(), 16);
114 node
=tvb_get_guint8(tvb
, offset
)<<8|tvb_get_guint8(tvb
, offset
+1);
115 g_snprintf(cur
, 16, "%d.%d",node
,tvb_get_guint8(tvb
, offset
+2));
120 tvb_aarphrdaddr_to_str(tvbuff_t
*tvb
, gint offset
, int ad_len
, guint16 type
)
122 if (AARP_HW_IS_ETHER(type
, ad_len
)) {
123 /* Ethernet address (or Token Ring address, which is the same type
125 return tvb_ether_to_str(tvb
, offset
);
127 return tvb_bytes_to_str(tvb
, offset
, ad_len
);
131 tvb_aarpproaddr_to_str(tvbuff_t
*tvb
, gint offset
, int ad_len
, guint16 type
)
133 if (AARP_PRO_IS_ATALK(type
, ad_len
)) {
134 /* Appletalk address. */
135 return tvb_atalkid_to_str(tvb
, offset
);
137 return tvb_bytes_to_str(tvb
, offset
, ad_len
);
140 /* Offsets of fields within an AARP packet. */
146 #define MIN_AARP_HEADER_SIZE 8
149 dissect_aarp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
) {
155 proto_tree
*aarp_tree
;
158 int sha_offset
, spa_offset
, tha_offset
, tpa_offset
;
159 const gchar
*sha_str
, *spa_str
, /* *tha_str, */ *tpa_str
;
161 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "AARP");
162 col_clear(pinfo
->cinfo
, COL_INFO
);
164 ar_hrd
= tvb_get_ntohs(tvb
, AR_HRD
);
165 ar_pro
= tvb_get_ntohs(tvb
, AR_PRO
);
166 ar_hln
= tvb_get_guint8(tvb
, AR_HLN
);
167 ar_pln
= tvb_get_guint8(tvb
, AR_PLN
);
168 ar_op
= tvb_get_ntohs(tvb
, AR_OP
);
170 /* Get the offsets of the addresses. */
171 sha_offset
= MIN_AARP_HEADER_SIZE
;
172 spa_offset
= sha_offset
+ ar_hln
;
173 tha_offset
= spa_offset
+ ar_pln
;
174 tpa_offset
= tha_offset
+ ar_hln
;
176 /* Extract the addresses. */
177 sha_str
= tvb_aarphrdaddr_to_str(tvb
, sha_offset
, ar_hln
, ar_hrd
);
178 spa_str
= tvb_aarpproaddr_to_str(tvb
, spa_offset
, ar_pln
, ar_pro
);
180 /* TODO: tha_str is currently not shown nor parsed */
181 tha_str
= tvb_aarphrdaddr_to_str(tvb
, tha_offset
, ar_hln
, ar_hrd
);
183 tpa_str
= tvb_aarpproaddr_to_str(tvb
, tpa_offset
, ar_pln
, ar_pro
);
187 case AARP_REQUEST_SWAPPED
:
188 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Who has %s? Tell %s", tpa_str
, spa_str
);
191 case AARP_REPLY_SWAPPED
:
192 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s is at %s", spa_str
, sha_str
);
195 case AARP_PROBE_SWAPPED
:
196 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Is there a %s", tpa_str
);
199 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unknown AARP opcode 0x%04x", ar_op
);
204 if ((op_str
= try_val_to_str(ar_op
, op_vals
)))
205 ti
= proto_tree_add_protocol_format(tree
, proto_aarp
, tvb
, 0,
206 MIN_AARP_HEADER_SIZE
+ 2*ar_hln
+
207 2*ar_pln
, "AppleTalk Address Resolution Protocol (%s)", op_str
);
209 ti
= proto_tree_add_protocol_format(tree
, proto_aarp
, tvb
, 0,
210 MIN_AARP_HEADER_SIZE
+ 2*ar_hln
+
212 "AppleTalk Address Resolution Protocol (opcode 0x%04x)", ar_op
);
213 aarp_tree
= proto_item_add_subtree(ti
, ett_aarp
);
214 proto_tree_add_uint(aarp_tree
, hf_aarp_hard_type
, tvb
, AR_HRD
, 2,
216 proto_tree_add_uint(aarp_tree
, hf_aarp_proto_type
, tvb
, AR_PRO
, 2,
218 proto_tree_add_uint(aarp_tree
, hf_aarp_hard_size
, tvb
, AR_HLN
, 1,
220 proto_tree_add_uint(aarp_tree
, hf_aarp_proto_size
, tvb
, AR_PLN
, 1,
222 proto_tree_add_uint(aarp_tree
, hf_aarp_opcode
, tvb
, AR_OP
, 2,
225 proto_tree_add_item(aarp_tree
,
226 AARP_HW_IS_ETHER(ar_hrd
, ar_hln
) ? hf_aarp_src_hw_mac
: hf_aarp_src_hw
,
227 tvb
, sha_offset
, ar_hln
, ENC_NA
);
231 if (AARP_PRO_IS_ATALK(ar_pro
, ar_pln
)) {
232 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_src_proto_id
, tvb
,
233 spa_offset
, ar_pln
, NULL
,
236 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_src_proto
, tvb
,
237 spa_offset
, ar_pln
, NULL
,
243 proto_tree_add_item(aarp_tree
,
244 AARP_HW_IS_ETHER(ar_hrd
, ar_hln
) ? hf_aarp_dst_hw_mac
: hf_aarp_dst_hw
,
245 tvb
, tha_offset
, ar_hln
, ENC_NA
);
249 if (AARP_PRO_IS_ATALK(ar_pro
, ar_pln
)) {
250 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_dst_proto_id
, tvb
,
252 NULL
, "%s", tpa_str
);
254 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_dst_proto
, tvb
,
256 NULL
, "%s", tpa_str
);
263 proto_register_aarp(void)
265 static hf_register_info hf
[] = {
266 { &hf_aarp_hard_type
,
267 { "Hardware type", "aarp.hard.type",
268 FT_UINT16
, BASE_HEX
, VALS(hrd_vals
), 0x0,
271 { &hf_aarp_proto_type
,
272 { "Protocol type", "aarp.proto.type",
273 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x0,
276 { &hf_aarp_hard_size
,
277 { "Hardware size", "aarp.hard.size",
278 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
281 { &hf_aarp_proto_size
,
282 { "Protocol size", "aarp.proto.size",
283 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
287 { "Opcode", "aarp.opcode",
288 FT_UINT16
, BASE_DEC
, VALS(op_vals
), 0x0,
292 { "Sender hardware address", "aarp.src.hw",
293 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
296 { &hf_aarp_src_hw_mac
,
297 { "Sender MAC address", "aarp.src.hw_mac",
298 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
301 { &hf_aarp_src_proto
,
302 { "Sender protocol address", "aarp.src.proto",
303 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
306 { &hf_aarp_src_proto_id
,
307 { "Sender ID", "aarp.src.proto_id",
308 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
312 { "Target hardware address", "aarp.dst.hw",
313 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
316 { &hf_aarp_dst_hw_mac
,
317 { "Target MAC address", "aarp.dst.hw_mac",
318 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
321 { &hf_aarp_dst_proto
,
322 { "Target protocol address", "aarp.dst.proto",
323 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
326 { &hf_aarp_dst_proto_id
,
327 { "Target ID", "aarp.dst.proto_id",
328 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
331 static gint
*ett
[] = {
335 proto_aarp
= proto_register_protocol("Appletalk Address Resolution Protocol",
338 proto_register_field_array(proto_aarp
, hf
, array_length(hf
));
339 proto_register_subtree_array(ett
, array_length(ett
));
343 proto_reg_handoff_aarp(void)
345 dissector_handle_t aarp_handle
;
347 aarp_handle
= create_dissector_handle(dissect_aarp
, proto_aarp
);
348 dissector_add_uint("ethertype", ETHERTYPE_AARP
, aarp_handle
);
349 dissector_add_uint("chdlc.protocol", ETHERTYPE_AARP
, aarp_handle
);