Christophe Tronche's BPDU dissector.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 8 Oct 1999 20:50:39 +0000 (20:50 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 8 Oct 1999 20:50:39 +0000 (20:50 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@790 f5534014-38df-0310-8fa8-9805f1628bb7

Makefile.am
packet-bpdu.c [new file with mode: 0644]
packet-llc.c
packet.h
proto.c

index d097ec4e3331ea9c9441539136fa109ff8ec54bd..68abb4736388ccd527f86258d0697a4b85823031 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.77 1999/10/01 21:41:38 guy Exp $
+# $Id: Makefile.am,v 1.78 1999/10/08 20:50:39 guy Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@zing.org>
@@ -59,6 +59,7 @@ ethereal_SOURCES = \
        packet-atalk.c \
        packet-atm.c   \
        packet-bootp.c \
+       packet-bpdu.c  \
        packet-cdp.c   \
        packet-clip.c  \
        packet-data.c  \
diff --git a/packet-bpdu.c b/packet-bpdu.c
new file mode 100644 (file)
index 0000000..c2f4f70
--- /dev/null
@@ -0,0 +1,160 @@
+/* packet-bpdu.c
+ * Routines for BPDU (Spanning Tree Protocol) disassembly
+ *
+ * $Id: packet-bpdu.c,v 1.1 1999/10/08 20:50:38 guy Exp $
+ *
+ * Copyright 1999 Christophe Tronche <ch.tronche@computer.org>
+ * 
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include "packet.h"
+#include "resolv.h"
+#include "util.h"
+
+/*  #ifndef __PACKET_IP_H__ */
+/*  #include "packet-ip.h" */
+/*  #endif */
+
+/* Offsets of fields within a BPDU */
+
+#define BPDU_IDENTIFIER          0
+#define BPDU_VERSION_IDENTIFIER  2
+#define BPDU_TYPE                3
+#define BPDU_FLAGS               4
+#define BPDU_ROOT_IDENTIFIER     5
+#define BPDU_ROOT_PATH_COST     13
+#define BPDU_BRIDGE_IDENTIFIER  17
+#define BPDU_PORT_IDENTIFIER    25
+#define BPDU_MESSAGE_AGE        27
+#define BPDU_MAX_AGE            29
+#define BPDU_HELLO_TIME         31
+#define BPDU_FORWARD_DELAY      33
+
+static int proto_bpdu = -1;
+
+void dissect_bpdu(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
+      guint16 protocol_identifier;
+      guint8  protocol_version_identifier;
+      guint8  bpdu_type;
+      guint8  flags;
+      guint16 root_identifier_bridge_priority;
+      gchar   *root_identifier_mac;
+      guint32 root_path_cost;
+      guint16 bridge_identifier_bridge_priority;
+      gchar   *bridge_identifier_mac;
+      guint16 port_identifier;
+      double message_age;
+      double max_age;
+      double hello_time;
+      double forward_delay;
+      
+      proto_tree *bpdu_tree;
+      proto_item *ti;
+      const u_char *bpdu;
+
+      bpdu = pd + offset;
+      bpdu_type = (guint8) bpdu[BPDU_TYPE];
+      flags = (guint8) bpdu[BPDU_FLAGS];
+      root_identifier_bridge_priority = pntohs(bpdu + BPDU_ROOT_IDENTIFIER);
+      root_identifier_mac = ether_to_str(bpdu + BPDU_ROOT_IDENTIFIER + 2);
+      root_path_cost = pntohl(bpdu + BPDU_ROOT_PATH_COST);
+      port_identifier = pntohs(bpdu + BPDU_PORT_IDENTIFIER);
+
+      if (check_col(fd, COL_PROTOCOL)) {
+           col_add_str(fd, COL_PROTOCOL, "STP"); /* Spanning Tree Protocol */
+      }
+
+      if (check_col(fd, COL_INFO)) {
+           if (bpdu_type == 0)
+                 col_add_fstr(fd, COL_INFO, "Conf. %sRoot = %d/%s  Cost = %d  Port = 0x%04x", 
+                              flags & 0x1 ? "TC + " : "",
+                              root_identifier_bridge_priority, root_identifier_mac, root_path_cost,
+                              port_identifier);
+           else if (bpdu_type == 0x80)
+                 col_add_fstr(fd, COL_INFO, "Topology Change Notification");
+      }
+
+      if (tree) {
+           protocol_identifier = pntohs(bpdu + BPDU_IDENTIFIER);
+           protocol_version_identifier = (guint8) bpdu[BPDU_VERSION_IDENTIFIER];
+
+           ti = proto_tree_add_item_format(tree, proto_bpdu, offset, 35, NULL, "Spanning Tree Protocol");
+           bpdu_tree = proto_item_add_subtree(ti, ETT_BPDU);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_IDENTIFIER, 2, "Protocol Identifier: 0x%04x (%s)", 
+                               protocol_identifier,
+                               protocol_identifier == 0 ? "Spanning Tree" : "Unknown Protocol");
+
+           proto_tree_add_text(bpdu_tree, offset + BPDU_VERSION_IDENTIFIER, 1, "Protocol Version Identifier: %d", protocol_version_identifier);
+           if (protocol_version_identifier != 0)
+                 proto_tree_add_text(bpdu_tree, offset + BPDU_VERSION_IDENTIFIER, 1, "   (Warning: this version of packet-bpdu only knows about version = 0)");
+           proto_tree_add_text(bpdu_tree, offset + BPDU_TYPE, 1, "BPDU Type: 0x%02x (%s)", 
+                               bpdu_type,
+                               bpdu_type == 0 ? "Configuration" :
+                               bpdu_type == 0x80 ? "Topology Change Notification" : "Unknown");
+
+           if (bpdu_type != 0) return;
+
+           bridge_identifier_bridge_priority = pntohs(bpdu + BPDU_BRIDGE_IDENTIFIER);
+           bridge_identifier_mac = ether_to_str(bpdu + BPDU_BRIDGE_IDENTIFIER + 2);
+           message_age = pntohs(bpdu + BPDU_MESSAGE_AGE) / 256.0;
+           max_age = pntohs(bpdu + BPDU_MAX_AGE) / 256.0;
+           hello_time = pntohs(bpdu + BPDU_HELLO_TIME) / 256.0;
+           forward_delay = pntohs(bpdu + BPDU_FORWARD_DELAY) / 256.0;
+
+           proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, "Flags: 0x%02x", flags);
+           if (flags & 0x80)
+                 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, "   1... ....  Topology Change Acknowledgment");
+           if (flags & 0x01)
+                 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, "   .... ...1  Topology Change");
+
+           proto_tree_add_text(bpdu_tree, offset + BPDU_ROOT_IDENTIFIER, 8, "Root Identifier: %d / %s", root_identifier_bridge_priority, root_identifier_mac);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_ROOT_PATH_COST, 4, "Root Path Cost: %d", root_path_cost);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_BRIDGE_IDENTIFIER, 8, "Bridge Identifier: %d / %s", 
+                               bridge_identifier_bridge_priority, 
+                               bridge_identifier_mac);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_PORT_IDENTIFIER, 2, "Port identifier: 0x%04x", port_identifier);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_MESSAGE_AGE, 2, "Message Age: %f", message_age);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_MAX_AGE, 2, "Max Age: %f", max_age);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_HELLO_TIME, 2, "Hello Time: %f", hello_time);
+           proto_tree_add_text(bpdu_tree, offset + BPDU_FORWARD_DELAY, 2, "Forward Delay: %f", forward_delay);
+      }
+}
+
+void
+proto_register_bpdu(void)
+{
+        proto_bpdu = proto_register_protocol("Spanning Tree Protocol", "STP");
+}
index d2c4edf84ee8e6f7de58ed74d2a0cc443feebd27..a0bc8dbf3201b18fa80646509d6b546e7ca8d170 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for IEEE 802.2 LLC layer
  * Gilbert Ramirez <gramirez@tivoli.com>
  *
- * $Id: packet-llc.c,v 1.24 1999/09/27 08:39:10 guy Exp $
+ * $Id: packet-llc.c,v 1.25 1999/10/08 20:50:38 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@unicom.net>
@@ -90,7 +90,7 @@ static struct sap_info        saps[] = {
        { 0x06, capture_ip,     dissect_ip },
        { 0x08, NULL,           NULL },
        { 0x0C, NULL,           NULL },
-       { 0x42, NULL,           NULL },
+       { 0x42, NULL,           dissect_bpdu },
        { 0x7F, NULL,           NULL },
        { 0x80, NULL,           NULL },
        { 0xAA, NULL,           NULL },
index d27ac3078639c8e7b161bdded2520b861e2c9e7e..b1a1ab2346cd90a6713cfad3973d47839bbb137c 100644 (file)
--- a/packet.h
+++ b/packet.h
@@ -1,7 +1,7 @@
 /* packet.h
  * Definitions for packet disassembly structures and routines
  *
- * $Id: packet.h,v 1.101 1999/10/03 01:14:33 sharpe Exp $
+ * $Id: packet.h,v 1.102 1999/10/08 20:50:38 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -172,6 +172,7 @@ enum {
        ETT_TR_MAC,
        ETT_PPP,
        ETT_ARP,
+       ETT_BPDU,
        ETT_FDDI,
        ETT_NULL,
        ETT_IP,
@@ -437,6 +438,7 @@ int dissect_ah(const u_char *, int, frame_data *, proto_tree *);
 void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
 void dissect_arp(const u_char *, int, frame_data *, proto_tree *);
 void dissect_bootp(const u_char *, int, frame_data *, proto_tree *);
+void dissect_bpdu(const u_char *, int, frame_data *, proto_tree *);
 void dissect_cdp(const u_char *, int, frame_data *, proto_tree *);
 void dissect_cotp(const u_char *, int, frame_data *, proto_tree *);
 void dissect_data(const u_char *, int, frame_data *, proto_tree *);
diff --git a/proto.c b/proto.c
index 3e7beaf6e388f61958e74c94286bf033882c186e..2f7e1c9bb5320b9720d4b462f8f92aeac5fce4a6 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.31 1999/10/04 18:09:05 gram Exp $
+ * $Id: proto.c,v 1.32 1999/10/08 20:50:37 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -91,6 +91,7 @@ void proto_register_ascend(void);
 void proto_register_atalk(void);
 void proto_register_atm(void);
 void proto_register_bootp(void);
+void proto_register_bpdu(void);
 void proto_register_cdp(void);
 void proto_register_clnp(void);
 void proto_register_cotp(void);
@@ -198,6 +199,7 @@ proto_init(void)
        proto_register_atalk();
        proto_register_atm();
        proto_register_bootp();
+       proto_register_bpdu();
        proto_register_cdp();
        proto_register_clnp();
        proto_register_cotp();