Tvbuffify the STP dissector, have it register itself and have the LLC
[obnox/wireshark/wip.git] / packet-ethertype.c
1 /* ethertype.c
2  * Routines for calling the right protocol for the ethertype.
3  *
4  * $Id: packet-ethertype.c,v 1.8 2000/11/16 07:35:37 guy Exp $
5  *
6  * Gilbert Ramirez <gram@xiexie.org>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <glib.h>
37 #include "packet.h"
38 #include "packet-ip.h"
39 #include "packet-ipx.h"
40 #include "packet-vlan.h"
41 #include "packet-vines.h"
42 #include "etypes.h"
43
44 static dissector_table_t ethertype_dissector_table;
45
46 const value_string etype_vals[] = {
47     {ETHERTYPE_IP,              "IP"                            },
48     {ETHERTYPE_IPv6,            "IPv6"                          },
49     {ETHERTYPE_X25L3,           "X.25 Layer 3"                  },
50     {ETHERTYPE_ARP,             "ARP"                           },
51     {ETHERTYPE_REVARP,          "RARP"                          },
52     {ETHERTYPE_DEC_LB,          "DEC LanBridge"                 },
53     {ETHERTYPE_ATALK,           "Appletalk"                     },
54     {ETHERTYPE_AARP,            "AARP"                          },
55     {ETHERTYPE_IPX,             "Netware IPX/SPX"               },
56     {ETHERTYPE_VINES,           "Vines"                         },
57     {ETHERTYPE_TRAIN,           "Netmon Train"                  },
58     {ETHERTYPE_LOOP,            "Loopback"                      }, /* Ethernet Loopback */
59     {ETHERTYPE_PPPOED,          "PPPoE Discovery"               }, 
60     {ETHERTYPE_PPPOES,          "PPPoE Session"                 }, 
61     {ETHERTYPE_VLAN,            "802.1Q Virtual LAN"            },
62     {ETHERTYPE_MPLS,            "MPLS label switched packet"    },
63     {ETHERTYPE_MPLS_MULTI,      "MPLS multicast label switched packet" },
64     {ETHERTYPE_3C_NBP_DGRAM,    "3Com NBP Datagram"             },
65     {ETHERTYPE_DEC,             "DEC proto"                     },
66     {ETHERTYPE_DNA_DL,          "DEC DNA Dump/Load"             },
67     {ETHERTYPE_DNA_RC,          "DEC DNA Remote Console"        },
68     {ETHERTYPE_DNA_RT,          "DEC DNA Routing"               },
69     {ETHERTYPE_LAT,             "DEC LAT"                       },
70     {ETHERTYPE_DEC_DIAG,        "DEC Diagnostics"               },
71     {ETHERTYPE_DEC_CUST,        "DEC Customer use"              },
72     {ETHERTYPE_DEC_SCA,         "DEC LAVC/SCA"                  },
73     {0,                         NULL                            } };
74
75 void
76 capture_ethertype(guint16 etype, int offset,
77                 const u_char *pd, packet_counts *ld)
78 {
79   switch (etype) {
80     case ETHERTYPE_IP:
81       capture_ip(pd, offset, ld);
82       break;
83     case ETHERTYPE_IPX:
84       capture_ipx(pd, offset, ld);
85       break;
86     case ETHERTYPE_VLAN:
87       capture_vlan(pd, offset, ld);
88       break;
89     case ETHERTYPE_VINES:
90       capture_vines(pd, offset, ld);
91       break;
92     default:
93       ld->other++;
94       break;
95   }
96 }
97
98 void
99 ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype, packet_info *pinfo,
100                 proto_tree *tree, proto_tree *fh_tree, int item_id)
101 {
102         char            *description;
103         tvbuff_t        *next_tvb;
104         
105         /* Add to proto_tree */
106         if (tree) {
107                 proto_tree_add_uint(fh_tree, item_id, tvb, offset_after_etype - 2, 2, etype);
108         }
109
110         next_tvb = tvb_new_subset(tvb, offset_after_etype, -1, -1);
111
112         /* Look for sub-dissector */
113         if (!dissector_try_port(ethertype_dissector_table, etype,
114             next_tvb, pinfo, tree)) {
115                 /* No sub-dissector found.
116                    Label rest of packet as "Data" */
117                 dissect_data(next_tvb, 0, pinfo, tree);
118
119                 /* Label protocol */
120                 switch(etype) {
121
122                 case ETHERTYPE_LOOP:
123                         if (check_col(pinfo->fd, COL_PROTOCOL)) {
124                                 col_add_fstr(pinfo->fd, COL_PROTOCOL, "LOOP");
125                         }
126                         break;
127                 default:
128                         if (check_col(pinfo->fd, COL_PROTOCOL)) {
129                                 col_add_fstr(pinfo->fd, COL_PROTOCOL, "0x%04x", etype);
130                         }
131                         break;
132                 }
133                 if (check_col(pinfo->fd, COL_INFO)) {
134                         description = match_strval(etype, etype_vals);
135                         if (description) {
136                                 col_add_fstr(pinfo->fd, COL_INFO, "%s", description);
137                         }
138                 }
139         }
140 }
141
142
143 void
144 proto_register_ethertype(void)
145 {
146         /* subdissector code */
147         ethertype_dissector_table = register_dissector_table("ethertype");
148 }