Put the value(s) of a parameter into the top-level item for that
[obnox/wireshark/wip.git] / packet-arp.c
index 3fd6bf47b2049aa6098a63858c91580b0b5ec902..a49404fe5ee2a436a62021d761363ed112b11d66 100644 (file)
@@ -1,22 +1,22 @@
 /* packet-arp.c
  * Routines for ARP packet disassembly
  *
- * $Id: packet-arp.c,v 1.51 2002/03/10 00:05:20 guy Exp $
+ * $Id: packet-arp.c,v 1.58 2004/02/28 22:56:35 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * 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.
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
 #include <epan/packet.h>
@@ -37,6 +33,7 @@
 #include <epan/resolv.h>
 #include "packet-arp.h"
 #include "etypes.h"
+#include "arcnet_pids.h"
 
 static int proto_arp = -1;
 static int hf_arp_hard_type = -1;
@@ -77,7 +74,7 @@ static dissector_handle_t atmarp_handle;
 
 /* Definitions taken from Linux "linux/if_arp.h" header file, and from
 
-       http://www.isi.edu/in-notes/iana/assignments/arp-parameters
+       http://www.iana.org/assignments/arp-parameters
 
  */
 
@@ -450,7 +447,7 @@ dissect_atmarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
   tot_len = MIN_ATMARP_HEADER_SIZE + ar_shl + ar_ssl + ar_spln +
                                ar_thl + ar_tsl + ar_tpln;
-  
+
   /* Adjust the length of this tvbuff to include only the ARP datagram.
      Our caller may use that to determine how much of its packet
      was padding. */
@@ -562,7 +559,7 @@ dissect_atmarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   if (tree) {
     if ((op_str = match_strval(ar_op, atmop_vals)))
       ti = proto_tree_add_protocol_format(tree, proto_arp, tvb, 0, tot_len,
-                                       "ATM Address Resolution Protocol (%s)", 
+                                       "ATM Address Resolution Protocol (%s)",
                                        op_str);
     else
       ti = proto_tree_add_protocol_format(tree, proto_arp, tvb, 0, tot_len,
@@ -656,6 +653,7 @@ dissect_atmarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 }
 
 static const guint8 mac_broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+static const guint8 mac_allzero[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
 static void
 dissect_arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
@@ -695,7 +693,7 @@ dissect_arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   ar_op  = tvb_get_ntohs(tvb, AR_OP);
 
   tot_len = MIN_ARP_HEADER_SIZE + ar_hln*2 + ar_pln*2;
-  
+
   /* Adjust the length of this tvbuff to include only the ARP datagram.
      Our caller may use that to determine how much of its packet
      was padding. */
@@ -706,7 +704,7 @@ dissect_arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   spa_offset = sha_offset + ar_hln;
   tha_offset = spa_offset + ar_pln;
   tpa_offset = tha_offset + ar_hln;
-  
+
   if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
     switch (ar_op) {
 
@@ -769,22 +767,24 @@ dissect_arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
     /* inform resolv.c module of the new discovered addresses */
 
-    u_int ip;
+    guint ip;
     const guint8 *mac;
 
-    /* add sender address in all cases */
-
+    /* Add sender address if sender MAC address is neither a broadcast/
+       multicast address nor an all-zero address and if sender IP address
+       isn't all zeroes. */
     tvb_memcpy(tvb, (guint8 *)&ip, spa_offset, sizeof(ip));
-    add_ether_byip(ip, tvb_get_ptr(tvb, sha_offset, 6));
-    
-    if (ar_op == ARPOP_REQUEST) {
-      /* Add target address *if* the target MAC address isn't a
-         broadcast address. */
-      tvb_memcpy(tvb, (guint8 *)&ip, tpa_offset, sizeof(ip));
-      mac = tvb_get_ptr(tvb, tha_offset, 6);
-      if (memcmp(mac, mac_broadcast, 6) != 0)
-        add_ether_byip(ip, mac);
-    }
+    mac = tvb_get_ptr(tvb, sha_offset, 6);
+    if ((mac[0] & 0x01) == 0 && memcmp(mac, mac_allzero, 6) != 0 && ip != 0)
+      add_ether_byip(ip, mac);
+
+    /* Add target address if target MAC address is neither a broadcast/
+       multicast address nor an all-zero address and if target IP address
+       isn't all zeroes. */
+    tvb_memcpy(tvb, (guint8 *)&ip, tpa_offset, sizeof(ip));
+    mac = tvb_get_ptr(tvb, tha_offset, 6);
+    if ((mac[0] & 0x01) == 0 && memcmp(mac, mac_allzero, 6) != 0 && ip != 0)
+      add_ether_byip(ip, mac);
   }
 
   if (tree) {
@@ -832,7 +832,7 @@ proto_register_arp(void)
 
   static hf_register_info hf[] = {
     { &hf_arp_hard_type,
-      { "Hardware type",               "arp.hw.type",   
+      { "Hardware type",               "arp.hw.type",
        FT_UINT16,      BASE_HEX,       VALS(hrd_vals), 0x0,
        "", HFILL }},
 
@@ -988,6 +988,8 @@ proto_register_arp(void)
   proto_register_subtree_array(ett, array_length(ett));
 
   atmarp_handle = create_dissector_handle(dissect_atmarp, proto_arp);
+
+  register_dissector( "arp" , dissect_arp, proto_arp );
 }
 
 void
@@ -995,7 +997,12 @@ proto_reg_handoff_arp(void)
 {
   dissector_handle_t arp_handle;
 
-  arp_handle = create_dissector_handle(dissect_arp, proto_arp);
+  arp_handle = find_dissector("arp");
+
   dissector_add("ethertype", ETHERTYPE_ARP, arp_handle);
   dissector_add("ethertype", ETHERTYPE_REVARP, arp_handle);
+  dissector_add("arcnet.protocol_id", ARCNET_PROTO_ARP_1051, arp_handle);
+  dissector_add("arcnet.protocol_id", ARCNET_PROTO_ARP_1201, arp_handle);
+  dissector_add("arcnet.protocol_id", ARCNET_PROTO_RARP_1201, arp_handle);
+
 }