aboutsummaryrefslogtreecommitdiffstats
path: root/packet-arp.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>1998-10-12 01:40:57 +0000
committerGerald Combs <gerald@wireshark.org>1998-10-12 01:40:57 +0000
commit0758da11466778cbd377fade6142bbe7c19ceecd (patch)
treef57ee7de708d072038153022c1ccbd9afa448651 /packet-arp.c
parent73e19611fdb5a6b70951c140c0831c72f04beb5c (diff)
- Added match_strval function to packet.c
- Separated display and capture filters; rearranged some of the look and feel - Lots of other miscellaneous fixes and updates svn path=/trunk/; revision=38
Diffstat (limited to 'packet-arp.c')
-rw-r--r--packet-arp.c69
1 files changed, 36 insertions, 33 deletions
diff --git a/packet-arp.c b/packet-arp.c
index f8144b5e3d..1feefb59dd 100644
--- a/packet-arp.c
+++ b/packet-arp.c
@@ -1,7 +1,7 @@
/* packet-arp.c
* Routines for ARP packet disassembly
*
- * $Id: packet-arp.c,v 1.4 1998/10/10 03:32:10 gerald Exp $
+ * $Id: packet-arp.c,v 1.5 1998/10/12 01:40:52 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -46,85 +46,88 @@
void
dissect_arp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
- e_ether_arp *ea;
- guint16 ar_hrd, ar_pro, ar_op;
+ e_ether_arp ea;
GtkWidget *arp_tree, *ti;
gchar *op_str;
- value_string op_vals[] = { ARPOP_REQUEST, "ARP request",
- ARPOP_REPLY, "ARP reply",
- ARPOP_RREQUEST, "RARP request",
- ARPOP_RREPLY, "RARP reply" };
+ value_string op_vals[] = { {ARPOP_REQUEST, "ARP request" },
+ {ARPOP_REPLY, "ARP reply" },
+ {ARPOP_RREQUEST, "RARP request"},
+ {ARPOP_RREPLY, "RARP reply" } };
/* To do: Check for {cap len,pkt len} < struct len */
- ea = (e_ether_arp *) &pd[offset];
- ar_hrd = ntohs(ea->ar_hrd);
- ar_pro = ntohs(ea->ar_pro);
- /* To do: Check for bounds on ar_op */
- ar_op = ntohs(ea->ar_op);
+ ea.ar_hrd = pntohs(&pd[offset]);
+ ea.ar_pro = pntohs(&pd[offset + 2]);
+ ea.ar_hln = (guint8) pd[offset + 4];
+ ea.ar_pln = (guint8) pd[offset + 5];
+ ea.ar_op = pntohs(&pd[offset + 6]);
+ memcpy(&ea.arp_sha, &pd[offset + 8], 6);
+ memcpy(&ea.arp_spa, &pd[offset + 14], 4);
+ memcpy(&ea.arp_tha, &pd[offset + 18], 6);
+ memcpy(&ea.arp_tpa, &pd[offset + 24], 4);
if (fd->win_info[COL_NUM]) { strcpy(fd->win_info[COL_PROTOCOL], "ARP"); }
if (tree) {
- if (op_str = match_strval(ar_op, op_vals, 4))
+ if ((op_str = match_strval(ea.ar_op, op_vals, 4)))
ti = add_item_to_tree(GTK_WIDGET(tree), offset, 28, op_str);
else
ti = add_item_to_tree(GTK_WIDGET(tree), offset, 28,
- "Unkown ARP (opcode 0x%04x)", ar_op);
+ "Unkown ARP (opcode 0x%04x)", ea.ar_op);
arp_tree = gtk_tree_new();
add_subtree(ti, arp_tree, ETT_ARP);
add_item_to_tree(arp_tree, offset, 2,
- "Hardware type: 0x%04x", ar_hrd);
+ "Hardware type: 0x%04x", ea.ar_hrd);
add_item_to_tree(arp_tree, offset + 2, 2,
- "Protocol type: 0x%04x", ar_pro);
+ "Protocol type: 0x%04x", ea.ar_pro);
add_item_to_tree(arp_tree, offset + 4, 1,
- "Hardware size: 0x%02x", ea->ar_hln);
+ "Hardware size: 0x%02x", ea.ar_hln);
add_item_to_tree(arp_tree, offset + 5, 1,
- "Protocol size: 0x%02x", ea->ar_pln);
+ "Protocol size: 0x%02x", ea.ar_pln);
add_item_to_tree(arp_tree, offset + 6, 2,
- "Opcode: 0x%04x (%s)", ar_op, op_str ? op_str : "Unknown");
+ "Opcode: 0x%04x (%s)", ea.ar_op, op_str ? op_str : "Unknown");
add_item_to_tree(arp_tree, offset + 8, 6,
- "Sender ether: %s", ether_to_str((guint8 *) ea->arp_sha));
+ "Sender ether: %s", ether_to_str((guint8 *) ea.arp_sha));
add_item_to_tree(arp_tree, offset + 14, 4,
- "Sender IP: %s", ip_to_str((guint8 *) ea->arp_spa));
+ "Sender IP: %s", ip_to_str((guint8 *) ea.arp_spa));
add_item_to_tree(arp_tree, offset + 18, 6,
- "Target ether: %s", ether_to_str((guint8 *) ea->arp_tha));
+ "Target ether: %s", ether_to_str((guint8 *) ea.arp_tha));
add_item_to_tree(arp_tree, offset + 24, 4,
- "Target IP: %s", ip_to_str((guint8 *) ea->arp_tpa));
+ "Target IP: %s", ip_to_str((guint8 *) ea.arp_tpa));
}
- if (ar_pro != ETHERTYPE_IP && fd->win_info[COL_NUM]) {
+ if (ea.ar_pro != ETHERTYPE_IP && fd->win_info[COL_NUM]) {
sprintf(fd->win_info[COL_INFO], "h/w %d (%d) prot %d (%d) op 0x%04x",
- ar_hrd, ea->ar_hln, ar_pro, ea->ar_pln, ar_op);
+ ea.ar_hrd, ea.ar_hln, ea.ar_pro, ea.ar_pln, ea.ar_op);
return;
}
- switch (ar_op) {
+ switch (ea.ar_op) {
case ARPOP_REQUEST:
if (fd->win_info[COL_NUM]) {
sprintf(fd->win_info[COL_INFO], "Who has %s? Tell %s",
- ip_to_str((guint8 *) ea->arp_tpa), ip_to_str((guint8 *) ea->arp_spa));
+ ip_to_str((guint8 *) ea.arp_tpa), ip_to_str((guint8 *) ea.arp_spa));
}
break;
case ARPOP_REPLY:
if (fd->win_info[COL_NUM]) {
sprintf(fd->win_info[COL_INFO], "%s is at %s",
- ip_to_str((guint8 *) ea->arp_spa),
- ether_to_str((guint8 *) ea->arp_sha));
+ ip_to_str((guint8 *) ea.arp_spa),
+ ether_to_str((guint8 *) ea.arp_sha));
}
break;
case ARPOP_RREQUEST:
if (fd->win_info[COL_NUM]) {
strcpy(fd->win_info[COL_PROTOCOL], "RARP");
sprintf(fd->win_info[COL_INFO], "Who is %s? Tell %s",
- ether_to_str((guint8 *) ea->arp_tha),
- ether_to_str((guint8 *) ea->arp_sha));
+ ether_to_str((guint8 *) ea.arp_tha),
+ ether_to_str((guint8 *) ea.arp_sha));
}
break;
case ARPOP_RREPLY:
if (fd->win_info[COL_NUM]) {
strcpy(fd->win_info[COL_PROTOCOL], "RARP");
sprintf(fd->win_info[COL_INFO], "%s is at %s",
- ether_to_str((guint8 *) ea->arp_sha),
- ip_to_str((guint8 *) ea->arp_spa));
+ ether_to_str((guint8 *) ea.arp_sha),
+ ip_to_str((guint8 *) ea.arp_spa));
}
break;
}