Back out change that Hannes Boehm said he didn't intend to commit,
[obnox/wireshark/wip.git] / ethertype.c
index 55fe9bebbb80d153bb57821fe081c6662d347240..2cb06c96b9c7186bd99b4b72a74328d7bde415a2 100644 (file)
@@ -2,6 +2,8 @@
  * Routines for calling the right protocol for the ethertype.
  * This is called by both packet-eth.c (Ethernet II) and packet-llc.c (SNAP)
  *
+ * $Id: ethertype.c,v 1.11 1998/12/19 00:12:19 hannes Exp $
+ *
  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
  *
  * Ethereal - Network traffic analyzer
 # include "config.h"
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
 #include <gtk/gtk.h>
 
 #include <stdio.h>
 
-#include <pcap.h>
-
-#include "packet.h"
 #include "ethereal.h"
+#include "packet.h"
 #include "etypes.h"
 
+gchar *
+ethertype_to_str(guint16 etype, const char *fmt)
+{
+  static const value_string etype_vals[] = {
+    {ETHERTYPE_IP,     "IP"             },
+    {ETHERTYPE_IPv6,   "IPv6"           },
+    {ETHERTYPE_ARP,    "ARP"            },
+    {ETHERTYPE_REVARP, "RARP"           },
+    {ETHERTYPE_ATALK,  "Appletalk"      },
+    {ETHERTYPE_AARP,   "AARP"           },
+    {ETHERTYPE_IPX,    "Netware IPX/SPX"},
+    {ETHERTYPE_VINES,  "Vines"          },
+    {ETHERTYPE_CDP,    "CDP"            }, /* Cisco Discovery Protocol */
+    {ETHERTYPE_LOOP,   "Loopback"       }, /* Ethernet Loopback */
+    {0,                 NULL            } };
+
+    return val_to_str(etype, etype_vals, fmt);
+}
+
 void
 ethertype(guint16 etype, int offset,
                const u_char *pd, frame_data *fd, GtkTree *tree, GtkWidget
                *fh_tree)
 {
-  gchar      etype_str[][10] = {"IP", "ARP", "RARP", "AppleTalk", "AARP"};
-
+  if (tree) {
+    add_item_to_tree(fh_tree, offset - 2, 2, "Type: %s (0x%04x)",
+      ethertype_to_str(etype, "Unknown"), etype);
+  }
   switch (etype) {
     case ETHERTYPE_IP:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2, "Type: IP (0x%04x)",
-          etype);
-      }
       dissect_ip(pd, offset, fd, tree);
       break;
     case ETHERTYPE_IPv6:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2, "Type: IPv6 (0x%04x)",
-          etype);
-      }
       dissect_ipv6(pd, offset, fd, tree);
       break;
     case ETHERTYPE_ARP:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: ARP (0x%04x)", etype);
-      }
       dissect_arp(pd, offset, fd, tree);
       break;
     case ETHERTYPE_REVARP:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: RARP (0x%04x)", etype);
-      }
       dissect_arp(pd, offset, fd, tree);
       break;
     case ETHERTYPE_ATALK:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: AppleTalk (0x%04x)", etype);
-      }
-      if (fd->win_info[0]) { strcpy(fd->win_info[3], etype_str[3]); }
+      dissect_ddp(pd, offset, fd, tree);
       break;
     case ETHERTYPE_AARP:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: AARP (0x%04x)", etype);
-      }
-      if (fd->win_info[0]) { strcpy(fd->win_info[3], etype_str[4]); }
+      dissect_aarp(pd, offset, fd, tree);
       break;
     case ETHERTYPE_IPX:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: Netware IPX/SPX (0x%04x)", etype);
-      }
       dissect_ipx(pd, offset, fd, tree);
       break;
+    case ETHERTYPE_VINES:
+      dissect_vines(pd, offset, fd, tree);
+      break;
+    case ETHERTYPE_CDP:
+      dissect_cdp(pd, offset, fd, tree);
+      break;
+    case ETHERTYPE_LOOP:
+      dissect_data(pd, offset, fd, tree);
+      if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "LOOP"); }
+      break;
     default:
-      if (tree) {
-        add_item_to_tree(fh_tree, offset - 2, 2,
-          "Type: Unknown (0x%04x)", etype);
-                 dissect_data(pd, offset, fd, tree);
-         }
-      if (fd->win_info[0]) { sprintf(fd->win_info[3], "0x%04x", etype); }
+      dissect_data(pd, offset, fd, tree);
+      if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "0x%04x", etype); }
       break;
   }
  }