Don't try to reassemble short frames - but do still pass them through at
[obnox/wireshark/wip.git] / packet-hsrp.c
index 49805669602e708ba08f1b6a367f834a41f8e03f..6b6976cdc8e62b65ed332b9f4389b77fea43b187 100644 (file)
@@ -4,10 +4,10 @@
  *
  * Heikki Vatiainen <hessu@cs.tut.fi>
  *
- * $Id: packet-hsrp.c,v 1.13 2001/01/03 06:55:28 guy Exp $
+ * $Id: packet-hsrp.c,v 1.22 2002/01/24 09:20:48 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-vrrp.c
@@ -41,7 +41,7 @@
 
 #include <string.h>
 #include <glib.h>
-#include "packet.h"
+#include <epan/packet.h>
 
 static gint proto_hsrp = -1;
 
@@ -82,7 +82,8 @@ struct hsrp_packet {          /* Multicast to 224.0.0.2, TTL 1, UDP, port 1985 *
 static const value_string hsrp_opcode_vals[] = {
         {HSRP_OPCODE_HELLO,  "Hello"},
         {HSRP_OPCODE_COUP,   "Coup"},
-        {HSRP_OPCODE_RESIGN, "Resign"}
+        {HSRP_OPCODE_RESIGN, "Resign"},
+       {0, NULL},
 };
 
 #define HSRP_STATE_INITIAL  0
@@ -97,7 +98,8 @@ static const value_string hsrp_state_vals[] = {
         {HSRP_STATE_LISTEN,  "Listen"},
         {HSRP_STATE_SPEAK,   "Speak"},
         {HSRP_STATE_STANDBY, "Standby"},
-        {HSRP_STATE_ACTIVE,  "Active"}
+        {HSRP_STATE_ACTIVE,  "Active"},
+       {0, NULL},
 };
 
 static void
@@ -105,17 +107,15 @@ dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
         guint8 opcode, state;
 
-        CHECK_DISPLAY_AS_DATA(proto_hsrp, tvb, pinfo, tree);
-
-        pinfo->current_proto = "HSRP";
-
-        if (check_col(pinfo->fd, COL_PROTOCOL))
-                col_set_str(pinfo->fd, COL_PROTOCOL, "HSRP");
+        if (check_col(pinfo->cinfo, COL_PROTOCOL))
+                col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSRP");
+        if (check_col(pinfo->cinfo, COL_INFO))
+                col_clear(pinfo->cinfo, COL_INFO);
         
         opcode = tvb_get_guint8(tvb, 1);
         state = tvb_get_guint8(tvb, 2);
-        if (check_col(pinfo->fd, COL_INFO)) {
-                col_add_fstr(pinfo->fd, COL_INFO, "%s (state %s)",
+        if (check_col(pinfo->cinfo, COL_INFO)) {
+                col_add_fstr(pinfo->cinfo, COL_INFO, "%s (state %s)",
                              val_to_str(opcode, hsrp_opcode_vals, "Unknown"),
                              val_to_str(state, hsrp_state_vals, "Unknown"));
         }
@@ -126,13 +126,12 @@ dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                 int offset;
                 guint8 hellotime, holdtime;
                 guint8 auth_buf[8 + 1];
-                guint32 virt_ip_addr;
 
                 offset = 0;
-                ti = proto_tree_add_item(tree, proto_hsrp, tvb, offset, tvb_length(tvb), FALSE);
+                ti = proto_tree_add_item(tree, proto_hsrp, tvb, offset, -1, FALSE);
                 hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
 
-                proto_tree_add_uint(hsrp_tree, hf_hsrp_version, tvb, offset, 1, tvb_get_guint8(tvb, offset));
+                proto_tree_add_item(hsrp_tree, hf_hsrp_version, tvb, offset, 1, FALSE);
                 offset++;
                 proto_tree_add_uint(hsrp_tree, hf_hsrp_opcode, tvb, offset, 1, opcode);
                 offset++;
@@ -150,11 +149,11 @@ dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                            (holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "Non-",
                                            holdtime);
                 offset++;
-                proto_tree_add_item(hsrp_tree, hf_hsrp_priority, tvb, offset, 1, tvb_get_guint8(tvb, offset));
+                proto_tree_add_item(hsrp_tree, hf_hsrp_priority, tvb, offset, 1, FALSE);
                 offset++;
-                proto_tree_add_item(hsrp_tree, hf_hsrp_group, tvb, offset, 1, tvb_get_guint8(tvb, offset));
+                proto_tree_add_item(hsrp_tree, hf_hsrp_group, tvb, offset, 1, FALSE);
                 offset++;
-                proto_tree_add_item(hsrp_tree, hf_hsrp_reserved, tvb, offset, 1, tvb_get_guint8(tvb, offset));
+                proto_tree_add_item(hsrp_tree, hf_hsrp_reserved, tvb, offset, 1, FALSE);
                 offset++;
                 tvb_memcpy(tvb, auth_buf, offset, 8);
                 auth_buf[sizeof auth_buf - 1] = '\0';
@@ -163,8 +162,7 @@ dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                              (tvb_strneql(tvb, offset, "cisco", strlen("cisco"))) == 0 ? "" : "Non-",
                                              auth_buf);
                 offset += 8;
-                tvb_memcpy(tvb, (guint8 *)&virt_ip_addr, offset, 4);
-                proto_tree_add_ipv4(hsrp_tree, hf_hsrp_virt_ip_addr, tvb, offset, 4, virt_ip_addr);
+                proto_tree_add_item(hsrp_tree, hf_hsrp_virt_ip_addr, tvb, offset, 4, FALSE);
                 offset += 4;
                 
         }
@@ -178,52 +176,52 @@ void proto_register_hsrp(void)
                 { &hf_hsrp_version,
                   { "Version", "hsrp.version",  
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "The version of the HSRP messages"}},
+                    "The version of the HSRP messages", HFILL }},
 
                 { &hf_hsrp_opcode,
                   { "Op Code", "hsrp.opcode",
                     FT_UINT8, BASE_DEC, VALS(hsrp_opcode_vals), 0x0,
-                    "The type of message contained in this packet" }},
+                    "The type of message contained in this packet", HFILL }},
 
                 { &hf_hsrp_state,
                   { "State", "hsrp.state",
                     FT_UINT8, BASE_DEC, VALS(hsrp_state_vals), 0x0,
-                    "The current state of the router sending the message" }},
+                    "The current state of the router sending the message", HFILL }},
 
                 { &hf_hsrp_hellotime,
                   { "Hellotime", "hsrp.hellotime",
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "The approximate period between the Hello messages that the router sends" }},
+                    "The approximate period between the Hello messages that the router sends", HFILL }},
 
                 { &hf_hsrp_holdtime,
                   { "Holdtime", "hsrp.holdtime",
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "Time that the current Hello message should be considered valid" }},
+                    "Time that the current Hello message should be considered valid", HFILL }},
 
                 { &hf_hsrp_priority,
                   { "Priority", "hsrp.priority",
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "Used to elect the active and standby routers. Numerically higher priority wins vote" }},
+                    "Used to elect the active and standby routers. Numerically higher priority wins vote", HFILL }},
 
                 { &hf_hsrp_group,
                   { "Group", "hsrp.group",
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "This field identifies the standby group" }},
+                    "This field identifies the standby group", HFILL }},
 
                 { &hf_hsrp_reserved,
                   { "Reserved", "hsrp.reserved",
                     FT_UINT8, BASE_DEC, NULL, 0x0,
-                    "Reserved" }},
+                    "Reserved", HFILL }},
 
                 { &hf_hsrp_auth_data,
                   { "Authentication Data", "hsrp.auth_data",
                     FT_STRING, 0, NULL, 0x0,
-                    "Contains a clear-text 8 character reused password" }},
+                    "Contains a clear-text 8 character reused password", HFILL }},
 
                 { &hf_hsrp_virt_ip_addr,
                   { "Virtual IP Address", "hsrp.virt_ip",
                     FT_IPv4, 0, NULL, 0x0,
-                    "The virtual IP address used by this group" }},
+                    "The virtual IP address used by this group", HFILL }},
 
         };
 
@@ -242,5 +240,8 @@ void proto_register_hsrp(void)
 void
 proto_reg_handoff_hsrp(void)
 {
-       dissector_add("udp.port", UDP_PORT_HSRP, dissect_hsrp);
+       dissector_handle_t hsrp_handle;
+
+       hsrp_handle = create_dissector_handle(dissect_hsrp, proto_hsrp);
+       dissector_add("udp.port", UDP_PORT_HSRP, hsrp_handle);
 }