1998-10-16 01:18:35 +00:00
|
|
|
/* packet-aarp.c
|
|
|
|
* Routines for Appletalk ARP packet disassembly
|
|
|
|
*
|
2001-01-22 00:20:29 +00:00
|
|
|
* $Id: packet-aarp.c,v 1.28 2001/01/22 00:20:29 guy Exp $
|
1999-09-23 05:26:18 +00:00
|
|
|
*
|
1998-10-16 01:18:35 +00:00
|
|
|
* Simon Wilkinson <sxw@dcs.ed.ac.uk>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
1998-10-16 01:18:35 +00:00
|
|
|
#include "packet.h"
|
2000-11-13 07:19:37 +00:00
|
|
|
#include "strutil.h"
|
1998-10-16 01:18:35 +00:00
|
|
|
#include "etypes.h"
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
static int proto_aarp = -1;
|
1999-10-03 15:06:28 +00:00
|
|
|
static int hf_aarp_hard_type = -1;
|
|
|
|
static int hf_aarp_proto_type = -1;
|
|
|
|
static int hf_aarp_hard_size = -1;
|
|
|
|
static int hf_aarp_proto_size = -1;
|
|
|
|
static int hf_aarp_opcode = -1;
|
|
|
|
static int hf_aarp_src_ether = -1;
|
|
|
|
static int hf_aarp_src_id = -1;
|
|
|
|
static int hf_aarp_dst_ether = -1;
|
|
|
|
static int hf_aarp_dst_id = -1;
|
1999-07-29 05:47:07 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_aarp = -1;
|
|
|
|
|
1998-10-16 01:18:35 +00:00
|
|
|
#ifndef AARP_REQUEST
|
|
|
|
#define AARP_REQUEST 0x0001
|
|
|
|
#endif
|
|
|
|
#ifndef AARP_REPLY
|
|
|
|
#define AARP_REPLY 0x0002
|
|
|
|
#endif
|
|
|
|
#ifndef AARP_PROBE
|
|
|
|
#define AARP_PROBE 0x0003
|
|
|
|
#endif
|
|
|
|
|
1999-12-10 00:45:15 +00:00
|
|
|
/* The following is screwed up shit to deal with the fact that
|
|
|
|
the linux kernel edits the packet inline. */
|
|
|
|
#define AARP_REQUEST_SWAPPED 0x0100
|
|
|
|
#define AARP_REPLY_SWAPPED 0x0200
|
|
|
|
#define AARP_PROBE_SWAPPED 0x0300
|
|
|
|
|
1999-11-04 08:21:04 +00:00
|
|
|
static const value_string op_vals[] = {
|
1999-12-08 18:12:06 +00:00
|
|
|
{AARP_REQUEST, "request" },
|
|
|
|
{AARP_REPLY, "reply" },
|
|
|
|
{AARP_PROBE, "probe" },
|
1999-12-10 00:45:15 +00:00
|
|
|
{AARP_REQUEST_SWAPPED, "request" },
|
|
|
|
{AARP_REPLY_SWAPPED, "reply" },
|
|
|
|
{AARP_PROBE_SWAPPED, "probe" },
|
1999-11-04 08:21:04 +00:00
|
|
|
{0, NULL } };
|
|
|
|
|
|
|
|
/* AARP protocol HARDWARE identifiers. */
|
|
|
|
#define AARPHRD_ETHER 1 /* Ethernet 10Mbps */
|
|
|
|
#define AARPHRD_TR 2 /* Token Ring */
|
|
|
|
|
|
|
|
static const value_string hrd_vals[] = {
|
|
|
|
{AARPHRD_ETHER, "Ethernet" },
|
|
|
|
{AARPHRD_TR, "Token Ring" },
|
|
|
|
{0, NULL } };
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
atalkid_to_str(const guint8 *ad) {
|
1998-10-16 01:18:35 +00:00
|
|
|
gint node;
|
|
|
|
static gchar str[3][16];
|
|
|
|
static gchar *cur;
|
|
|
|
|
|
|
|
if (cur == &str[0][0]) {
|
|
|
|
cur = &str[1][0];
|
|
|
|
} else if (cur == &str[1][0]) {
|
|
|
|
cur = &str[2][0];
|
|
|
|
} else {
|
|
|
|
cur = &str[0][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
node=ad[1]<<8|ad[2];
|
|
|
|
sprintf(cur, "%d.%d",node,ad[3]);
|
|
|
|
return cur;
|
|
|
|
}
|
1999-11-04 08:21:04 +00:00
|
|
|
|
|
|
|
static gchar *
|
|
|
|
aarphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type) {
|
|
|
|
if ((type == AARPHRD_ETHER || type == AARPHRD_TR) && ad_len == 6) {
|
|
|
|
/* Ethernet address (or Token Ring address, which is the same type
|
|
|
|
of address). */
|
|
|
|
return ether_to_str(ad);
|
|
|
|
}
|
|
|
|
return bytes_to_str(ad, ad_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
aarpproaddr_to_str(guint8 *ad, int ad_len, guint16 type) {
|
|
|
|
if (type == ETHERTYPE_ATALK && ad_len == 4) {
|
|
|
|
/* IP address. */
|
|
|
|
return atalkid_to_str(ad);
|
|
|
|
}
|
|
|
|
return bytes_to_str(ad, ad_len);
|
|
|
|
}
|
1998-10-16 01:18:35 +00:00
|
|
|
|
1999-11-04 08:21:04 +00:00
|
|
|
/* Offsets of fields within an AARP packet. */
|
|
|
|
#define AR_HRD 0
|
|
|
|
#define AR_PRO 2
|
|
|
|
#define AR_HLN 4
|
|
|
|
#define AR_PLN 5
|
|
|
|
#define AR_OP 6
|
|
|
|
#define MIN_AARP_HEADER_SIZE 8
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
static void
|
2000-11-13 04:26:53 +00:00
|
|
|
dissect_aarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
|
1999-11-04 08:21:04 +00:00
|
|
|
guint16 ar_hrd;
|
|
|
|
guint16 ar_pro;
|
|
|
|
guint8 ar_hln;
|
|
|
|
guint8 ar_pln;
|
|
|
|
guint16 ar_op;
|
|
|
|
proto_tree *aarp_tree;
|
|
|
|
proto_item *ti;
|
|
|
|
gchar *op_str;
|
|
|
|
int sha_offset, spa_offset, tha_offset, tpa_offset;
|
2000-11-13 04:26:53 +00:00
|
|
|
guint8 *sha_val, *spa_val, *tha_val, *tpa_val;
|
1999-11-04 08:21:04 +00:00
|
|
|
gchar *sha_str, *spa_str, *tha_str, *tpa_str;
|
|
|
|
|
2001-01-22 00:20:29 +00:00
|
|
|
if(check_col(pinfo->fd, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->fd, COL_PROTOCOL, "AARP");
|
|
|
|
if(check_col(pinfo->fd, COL_INFO))
|
|
|
|
col_clear(pinfo->fd, COL_INFO);
|
1999-10-03 15:21:11 +00:00
|
|
|
|
2000-11-13 04:26:53 +00:00
|
|
|
ar_hrd = tvb_get_ntohs(tvb, AR_HRD);
|
|
|
|
ar_pro = tvb_get_ntohs(tvb, AR_PRO);
|
|
|
|
ar_hln = tvb_get_guint8(tvb, AR_HLN);
|
|
|
|
ar_pln = tvb_get_guint8(tvb, AR_PLN);
|
|
|
|
ar_op = tvb_get_ntohs(tvb, AR_OP);
|
1999-11-04 08:21:04 +00:00
|
|
|
|
|
|
|
/* Extract the addresses. */
|
2000-11-13 04:26:53 +00:00
|
|
|
sha_offset = MIN_AARP_HEADER_SIZE;
|
|
|
|
sha_val = tvb_get_ptr(tvb, sha_offset, ar_hln);
|
|
|
|
sha_str = aarphrdaddr_to_str(sha_val, ar_hln, ar_hrd);
|
|
|
|
|
1999-11-04 08:21:04 +00:00
|
|
|
spa_offset = sha_offset + ar_hln;
|
2000-11-13 04:26:53 +00:00
|
|
|
spa_val = tvb_get_ptr(tvb, spa_offset, ar_pln);
|
|
|
|
spa_str = aarpproaddr_to_str(spa_val, ar_pln, ar_pro);
|
|
|
|
|
1999-11-04 08:21:04 +00:00
|
|
|
tha_offset = spa_offset + ar_pln;
|
2000-11-13 04:26:53 +00:00
|
|
|
tha_val = tvb_get_ptr(tvb, tha_offset, ar_hln);
|
|
|
|
tha_str = aarphrdaddr_to_str(tha_val, ar_hln, ar_hrd);
|
|
|
|
|
1999-11-04 08:21:04 +00:00
|
|
|
tpa_offset = tha_offset + ar_hln;
|
2000-11-13 04:26:53 +00:00
|
|
|
tpa_val = tvb_get_ptr(tvb, tpa_offset, ar_pln);
|
|
|
|
tpa_str = aarpproaddr_to_str(tpa_val, ar_pln, ar_pro);
|
1998-10-16 01:18:35 +00:00
|
|
|
|
2000-11-13 04:26:53 +00:00
|
|
|
if (check_col(pinfo->fd, COL_INFO)) {
|
1999-11-04 08:21:04 +00:00
|
|
|
switch (ar_op) {
|
1998-11-17 04:29:13 +00:00
|
|
|
case AARP_REQUEST:
|
1999-12-10 00:45:15 +00:00
|
|
|
case AARP_REQUEST_SWAPPED:
|
2000-11-13 04:26:53 +00:00
|
|
|
col_add_fstr(pinfo->fd, COL_INFO, "Who has %s? Tell %s", tpa_str, spa_str);
|
1998-11-17 04:29:13 +00:00
|
|
|
break;
|
|
|
|
case AARP_REPLY:
|
1999-12-10 00:45:15 +00:00
|
|
|
case AARP_REPLY_SWAPPED:
|
2000-11-13 04:26:53 +00:00
|
|
|
col_add_fstr(pinfo->fd, COL_INFO, "%s is at %s", spa_str, sha_str);
|
1998-11-17 04:29:13 +00:00
|
|
|
break;
|
|
|
|
case AARP_PROBE:
|
1999-12-10 00:45:15 +00:00
|
|
|
case AARP_PROBE_SWAPPED:
|
2000-11-13 04:26:53 +00:00
|
|
|
col_add_fstr(pinfo->fd, COL_INFO, "Is there a %s", tpa_str);
|
1999-11-04 08:21:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-11-13 04:26:53 +00:00
|
|
|
col_add_fstr(pinfo->fd, COL_INFO, "Unknown AARP opcode 0x%04x", ar_op);
|
1998-11-17 04:29:13 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-10-16 01:18:35 +00:00
|
|
|
}
|
1999-11-04 08:21:04 +00:00
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
if ((op_str = match_strval(ar_op, op_vals)))
|
2000-11-13 04:26:53 +00:00
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_aarp, tvb, 0,
|
1999-11-04 08:21:04 +00:00
|
|
|
MIN_AARP_HEADER_SIZE + 2*ar_hln +
|
2000-03-12 04:48:32 +00:00
|
|
|
2*ar_pln, "AppleTalk Address Resolution Protocol (%s)", op_str);
|
1999-11-04 08:21:04 +00:00
|
|
|
else
|
2000-11-13 04:26:53 +00:00
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_aarp, tvb, 0,
|
1999-11-04 08:21:04 +00:00
|
|
|
MIN_AARP_HEADER_SIZE + 2*ar_hln +
|
2000-03-12 04:48:32 +00:00
|
|
|
2*ar_pln,
|
1999-12-08 18:12:06 +00:00
|
|
|
"AppleTalk Address Resolution Protocol (opcode 0x%04x)", ar_op);
|
1999-11-16 11:44:20 +00:00
|
|
|
aarp_tree = proto_item_add_subtree(ti, ett_aarp);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_uint(aarp_tree, hf_aarp_hard_type, tvb, AR_HRD, 2,
|
1999-11-04 08:21:04 +00:00
|
|
|
ar_hrd);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_uint(aarp_tree, hf_aarp_proto_type, tvb, AR_PRO, 2,
|
1999-11-04 08:21:04 +00:00
|
|
|
ar_pro);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_uint(aarp_tree, hf_aarp_hard_size, tvb, AR_HLN, 1,
|
1999-11-04 08:21:04 +00:00
|
|
|
ar_hln);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_uint(aarp_tree, hf_aarp_proto_size, tvb, AR_PLN, 1,
|
1999-11-04 08:21:04 +00:00
|
|
|
ar_pln);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_uint(aarp_tree, hf_aarp_opcode, tvb, AR_OP, 2,
|
1999-11-04 08:21:04 +00:00
|
|
|
ar_op);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_bytes_format(aarp_tree, hf_aarp_src_ether, tvb, sha_offset, ar_hln,
|
|
|
|
sha_val,
|
1999-11-04 08:21:04 +00:00
|
|
|
"Sender hardware address: %s", sha_str);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_bytes_format(aarp_tree, hf_aarp_src_id, tvb, spa_offset, ar_pln,
|
|
|
|
spa_val,
|
1999-11-04 08:21:04 +00:00
|
|
|
"Sender ID: %s", spa_str);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_bytes_format(aarp_tree, hf_aarp_dst_ether, tvb, tha_offset, ar_hln,
|
|
|
|
tha_val,
|
1999-11-04 08:21:04 +00:00
|
|
|
"Target hardware address: %s", tha_str);
|
2000-11-13 04:26:53 +00:00
|
|
|
proto_tree_add_bytes_format(aarp_tree, hf_aarp_dst_id, tvb, tpa_offset, ar_pln,
|
|
|
|
tpa_val,
|
1999-11-04 08:21:04 +00:00
|
|
|
"Target ID: %s", tpa_str);
|
|
|
|
}
|
1998-10-16 01:18:35 +00:00
|
|
|
}
|
1999-07-29 05:47:07 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_aarp(void)
|
|
|
|
{
|
1999-10-03 15:06:28 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_aarp_hard_type,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Hardware type", "aarp.hard.type",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_UINT16, BASE_HEX, VALS(hrd_vals), 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_proto_type,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Protocol type", "aarp.proto.type",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_hard_size,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Hardware size", "aarp.hard.size",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_proto_size,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Protocol size", "aarp.proto.size",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_opcode,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Opcode", "aarp.opcode",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_UINT16, BASE_DEC, VALS(op_vals), 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_src_ether,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Sender ether", "aarp.src.ether",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_src_id,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Sender ID", "aarp.src.id",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_BYTES, BASE_HEX, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_dst_ether,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Target ether", "aarp.dst.ether",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
{ &hf_aarp_dst_id,
|
1999-10-16 08:27:25 +00:00
|
|
|
{ "Target ID", "aarp.dst.id",
|
1999-11-04 08:21:04 +00:00
|
|
|
FT_BYTES, BASE_HEX, NULL, 0x0,
|
1999-10-12 06:21:15 +00:00
|
|
|
"" }},
|
1999-10-03 15:06:28 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_aarp,
|
|
|
|
};
|
1999-07-29 05:47:07 +00:00
|
|
|
|
1999-10-03 15:06:28 +00:00
|
|
|
proto_aarp = proto_register_protocol("Appletalk Address Resolution Protocol",
|
2001-01-03 06:56:03 +00:00
|
|
|
"AARP",
|
1999-10-03 15:06:28 +00:00
|
|
|
"aarp");
|
|
|
|
proto_register_field_array(proto_aarp, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-07-29 05:47:07 +00:00
|
|
|
}
|
Change the sub-dissector handoff registration routines so that the
sub-dissector table is not stored in the header_field_info struct, but
in a separate namespace. Dissector tables are now registered by name
and not by field ID. For example:
udp_dissector_table = register_dissector_table("udp.port");
Because of this different namespace, dissector tables can have names
that are not field names. This is useful for ethertype, since multiple
fields are "ethertypes".
packet-ethertype.c replaces ethertype.c (the name was changed so that it
would be named in the same fashion as all the filenames passed to make-reg-dotc)
Although it registers no protocol or field, it registers one dissector table:
ethertype_dissector_table = register_dissector_table("ethertype");
All protocols that can be called because of an ethertype field now register
that fact with dissector_add() calls.
In this way, one dissector_table services all ethertype fields
(hf_eth_type, hf_llc_type, hf_null_etype, hf_vlan_etype)
Furthermore, the code allows for names of protocols to exist in the
etype_vals, yet a dissector for that protocol doesn't exist. The name
of the dissector is printed in COL_INFO. You're welcome, Richard. :-)
svn path=/trunk/; revision=1848
2000-04-13 18:18:56 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_aarp(void)
|
|
|
|
{
|
2001-01-09 06:32:10 +00:00
|
|
|
dissector_add("ethertype", ETHERTYPE_AARP, dissect_aarp, proto_aarp);
|
Change the sub-dissector handoff registration routines so that the
sub-dissector table is not stored in the header_field_info struct, but
in a separate namespace. Dissector tables are now registered by name
and not by field ID. For example:
udp_dissector_table = register_dissector_table("udp.port");
Because of this different namespace, dissector tables can have names
that are not field names. This is useful for ethertype, since multiple
fields are "ethertypes".
packet-ethertype.c replaces ethertype.c (the name was changed so that it
would be named in the same fashion as all the filenames passed to make-reg-dotc)
Although it registers no protocol or field, it registers one dissector table:
ethertype_dissector_table = register_dissector_table("ethertype");
All protocols that can be called because of an ethertype field now register
that fact with dissector_add() calls.
In this way, one dissector_table services all ethertype fields
(hf_eth_type, hf_llc_type, hf_null_etype, hf_vlan_etype)
Furthermore, the code allows for names of protocols to exist in the
etype_vals, yet a dissector for that protocol doesn't exist. The name
of the dissector is printed in COL_INFO. You're welcome, Richard. :-)
svn path=/trunk/; revision=1848
2000-04-13 18:18:56 +00:00
|
|
|
}
|