2 * Routines for Appletalk ARP packet disassembly
4 * Simon Wilkinson <sxw@dcs.ed.ac.uk>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
17 #include <epan/expert.h>
18 #include <epan/to_str.h>
20 /* Forward declarations */
21 void proto_register_aarp(void);
22 void proto_reg_handoff_aarp(void);
24 static int proto_aarp
;
25 static int hf_aarp_hard_type
;
26 static int hf_aarp_proto_type
;
27 static int hf_aarp_hard_size
;
28 static int hf_aarp_proto_size
;
29 static int hf_aarp_opcode
;
30 static int hf_aarp_src_hw
;
31 static int hf_aarp_src_hw_mac
;
32 static int hf_aarp_src_proto
;
33 static int hf_aarp_src_proto_id
;
34 static int hf_aarp_dst_hw
;
35 static int hf_aarp_dst_hw_mac
;
36 static int hf_aarp_dst_proto
;
37 static int hf_aarp_dst_proto_id
;
41 static expert_field ei_aarp_length_invalid
;
44 #define AARP_REQUEST 0x0001
47 #define AARP_REPLY 0x0002
50 #define AARP_PROBE 0x0003
53 /* The following is screwed up shit to deal with the fact that
54 the linux kernel edits the packet inline. */
55 #define AARP_REQUEST_SWAPPED 0x0100
56 #define AARP_REPLY_SWAPPED 0x0200
57 #define AARP_PROBE_SWAPPED 0x0300
59 static const value_string op_vals
[] = {
60 {AARP_REQUEST
, "request" },
61 {AARP_REPLY
, "reply" },
62 {AARP_PROBE
, "probe" },
63 {AARP_REQUEST_SWAPPED
, "request" },
64 {AARP_REPLY_SWAPPED
, "reply" },
65 {AARP_PROBE_SWAPPED
, "probe" },
68 /* AARP protocol HARDWARE identifiers. */
69 #define AARPHRD_ETHER 1 /* Ethernet 10Mbps */
70 #define AARPHRD_TR 2 /* Token Ring */
72 static const value_string hrd_vals
[] = {
73 {AARPHRD_ETHER
, "Ethernet" },
74 {AARPHRD_TR
, "Token Ring" },
78 * Given the hardware address type and length, check whether an address
79 * is an Ethernet address - the address must be of type "Ethernet" or
80 * "Token Ring", and the length must be 6 bytes.
82 #define AARP_HW_IS_ETHER(ar_hrd, ar_hln) \
83 (((ar_hrd) == AARPHRD_ETHER || (ar_hrd) == AARPHRD_TR) \
87 * Given the protocol address type and length, check whether an address
88 * is an Appletalk address - the address must be of type "Appletalk",
89 * and the length must be 4 bytes.
91 #define AARP_PRO_IS_ATALK(ar_pro, ar_pln) \
92 ((ar_pro) == ETHERTYPE_ATALK && (ar_pln) == 4)
95 tvb_atalkid_to_str(wmem_allocator_t
*scope
, tvbuff_t
*tvb
, int offset
)
100 cur
=(char *)wmem_alloc(scope
, 16);
101 node
=tvb_get_uint8(tvb
, offset
+1)<<8|tvb_get_uint8(tvb
, offset
+2);
102 snprintf(cur
, 16, "%d.%d",node
,tvb_get_uint8(tvb
, offset
+3));
107 tvb_aarphrdaddr_to_str(wmem_allocator_t
*scope
, tvbuff_t
*tvb
, int offset
, int ad_len
, uint16_t type
)
109 if (AARP_HW_IS_ETHER(type
, ad_len
)) {
110 /* Ethernet address (or Token Ring address, which is the same type
112 return tvb_ether_to_str(scope
, tvb
, offset
);
114 return tvb_bytes_to_str(scope
, tvb
, offset
, ad_len
);
118 tvb_aarpproaddr_to_str(wmem_allocator_t
*scope
, tvbuff_t
*tvb
, int offset
, int ad_len
, uint16_t type
)
120 if (AARP_PRO_IS_ATALK(type
, ad_len
)) {
121 /* Appletalk address. */
122 return tvb_atalkid_to_str(scope
, tvb
, offset
);
124 return tvb_bytes_to_str(scope
, tvb
, offset
, ad_len
);
127 /* Offsets of fields within an AARP packet. */
133 #define MIN_AARP_HEADER_SIZE 8
136 dissect_aarp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
) {
142 proto_tree
*aarp_tree
;
145 int sha_offset
, spa_offset
, tha_offset
, tpa_offset
;
146 const char *sha_str
, *spa_str
, /* *tha_str, */ *tpa_str
;
148 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "AARP");
149 col_clear(pinfo
->cinfo
, COL_INFO
);
151 ar_hrd
= tvb_get_ntohs(tvb
, AR_HRD
);
152 ar_pro
= tvb_get_ntohs(tvb
, AR_PRO
);
153 ar_hln
= tvb_get_uint8(tvb
, AR_HLN
);
154 ar_pln
= tvb_get_uint8(tvb
, AR_PLN
);
155 ar_op
= tvb_get_ntohs(tvb
, AR_OP
);
157 /* Get the offsets of the addresses. */
158 sha_offset
= MIN_AARP_HEADER_SIZE
;
159 spa_offset
= sha_offset
+ ar_hln
;
160 tha_offset
= spa_offset
+ ar_pln
;
161 tpa_offset
= tha_offset
+ ar_hln
;
163 /* Extract the addresses. */
166 expert_add_info_format(pinfo
, tree
, &ei_aarp_length_invalid
,
167 "Invalid hardware address length: %d", ar_hln
);
173 sha_str
= tvb_aarphrdaddr_to_str(pinfo
->pool
, tvb
, sha_offset
, ar_hln
, ar_hrd
);
175 /* TODO: tha_str is currently not shown nor parsed */
176 tha_str
= tvb_aarphrdaddr_to_str(pinfo
->pool
, tvb
, tha_offset
, ar_hln
, ar_hrd
);
181 expert_add_info_format(pinfo
, tree
, &ei_aarp_length_invalid
,
182 "Invalid protocol address length: %d", ar_pln
);
186 spa_str
= tvb_aarpproaddr_to_str(pinfo
->pool
, tvb
, spa_offset
, ar_pln
, ar_pro
);
187 tpa_str
= tvb_aarpproaddr_to_str(pinfo
->pool
, tvb
, tpa_offset
, ar_pln
, ar_pro
);
192 case AARP_REQUEST_SWAPPED
:
193 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Who has %s? Tell %s", tpa_str
, spa_str
);
196 case AARP_REPLY_SWAPPED
:
197 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s is at %s", spa_str
, sha_str
);
200 case AARP_PROBE_SWAPPED
:
201 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Is there a %s", tpa_str
);
204 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unknown AARP opcode 0x%04x", ar_op
);
209 if ((op_str
= try_val_to_str(ar_op
, op_vals
)))
210 ti
= proto_tree_add_protocol_format(tree
, proto_aarp
, tvb
, 0,
211 MIN_AARP_HEADER_SIZE
+ 2*ar_hln
+
212 2*ar_pln
, "AppleTalk Address Resolution Protocol (%s)", op_str
);
214 ti
= proto_tree_add_protocol_format(tree
, proto_aarp
, tvb
, 0,
215 MIN_AARP_HEADER_SIZE
+ 2*ar_hln
+
217 "AppleTalk Address Resolution Protocol (opcode 0x%04x)", ar_op
);
218 aarp_tree
= proto_item_add_subtree(ti
, ett_aarp
);
219 proto_tree_add_uint(aarp_tree
, hf_aarp_hard_type
, tvb
, AR_HRD
, 2,
221 proto_tree_add_uint(aarp_tree
, hf_aarp_proto_type
, tvb
, AR_PRO
, 2,
223 proto_tree_add_uint(aarp_tree
, hf_aarp_hard_size
, tvb
, AR_HLN
, 1,
225 proto_tree_add_uint(aarp_tree
, hf_aarp_proto_size
, tvb
, AR_PLN
, 1,
227 proto_tree_add_uint(aarp_tree
, hf_aarp_opcode
, tvb
, AR_OP
, 2,
230 proto_tree_add_item(aarp_tree
,
231 AARP_HW_IS_ETHER(ar_hrd
, ar_hln
) ? hf_aarp_src_hw_mac
: hf_aarp_src_hw
,
232 tvb
, sha_offset
, ar_hln
, ENC_NA
);
236 if (AARP_PRO_IS_ATALK(ar_pro
, ar_pln
)) {
237 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_src_proto_id
, tvb
,
238 spa_offset
, ar_pln
, NULL
,
241 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_src_proto
, tvb
,
242 spa_offset
, ar_pln
, NULL
,
248 proto_tree_add_item(aarp_tree
,
249 AARP_HW_IS_ETHER(ar_hrd
, ar_hln
) ? hf_aarp_dst_hw_mac
: hf_aarp_dst_hw
,
250 tvb
, tha_offset
, ar_hln
, ENC_NA
);
254 if (AARP_PRO_IS_ATALK(ar_pro
, ar_pln
)) {
255 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_dst_proto_id
, tvb
,
257 NULL
, "%s", tpa_str
);
259 proto_tree_add_bytes_format_value(aarp_tree
, hf_aarp_dst_proto
, tvb
,
261 NULL
, "%s", tpa_str
);
265 return tvb_captured_length(tvb
);
269 proto_register_aarp(void)
271 static hf_register_info hf
[] = {
272 { &hf_aarp_hard_type
,
273 { "Hardware type", "aarp.hard.type",
274 FT_UINT16
, BASE_HEX
, VALS(hrd_vals
), 0x0,
277 { &hf_aarp_proto_type
,
278 { "Protocol type", "aarp.proto.type",
279 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x0,
282 { &hf_aarp_hard_size
,
283 { "Hardware size", "aarp.hard.size",
284 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
287 { &hf_aarp_proto_size
,
288 { "Protocol size", "aarp.proto.size",
289 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
293 { "Opcode", "aarp.opcode",
294 FT_UINT16
, BASE_DEC
, VALS(op_vals
), 0x0,
298 { "Sender hardware address", "aarp.src.hw",
299 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
302 { &hf_aarp_src_hw_mac
,
303 { "Sender MAC address", "aarp.src.hw_mac",
304 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
307 { &hf_aarp_src_proto
,
308 { "Sender protocol address", "aarp.src.proto",
309 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
312 { &hf_aarp_src_proto_id
,
313 { "Sender ID", "aarp.src.proto_id",
314 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
318 { "Target hardware address", "aarp.dst.hw",
319 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
322 { &hf_aarp_dst_hw_mac
,
323 { "Target MAC address", "aarp.dst.hw_mac",
324 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
327 { &hf_aarp_dst_proto
,
328 { "Target protocol address", "aarp.dst.proto",
329 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
332 { &hf_aarp_dst_proto_id
,
333 { "Target ID", "aarp.dst.proto_id",
334 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
337 static int *ett
[] = {
341 static ei_register_info ei
[] = {
342 { &ei_aarp_length_invalid
, { "aarp.length.invalid", PI_PROTOCOL
, PI_WARN
, "Invalid length", EXPFILL
}},
345 proto_aarp
= proto_register_protocol("Appletalk Address Resolution Protocol",
348 register_dissector("aarp", dissect_aarp
, proto_aarp
);
349 proto_register_field_array(proto_aarp
, hf
, array_length(hf
));
350 proto_register_subtree_array(ett
, array_length(ett
));
352 expert_module_t
* expert_aarp
= expert_register_protocol(proto_aarp
);
353 expert_register_field_array(expert_aarp
, ei
, array_length(ei
));
358 proto_reg_handoff_aarp(void)
360 dissector_handle_t aarp_handle
= find_dissector("aarp");
362 dissector_add_uint("ethertype", ETHERTYPE_AARP
, aarp_handle
);
363 dissector_add_uint("chdlc.protocol", ETHERTYPE_AARP
, aarp_handle
);
367 * Editor modelines - https://www.wireshark.org/tools/modelines.html
372 * indent-tabs-mode: nil
375 * ex: set shiftwidth=2 tabstop=8 expandtab:
376 * :indentSize=2:tabSize=8:noTabs=true: