Nathan Neulinger's 802.1q VLAN patch.
[obnox/wireshark/wip.git] / ethertype.c
1 /* ethertype.c
2  * Routines for calling the right protocol for the ethertype.
3  * This is called by both packet-eth.c (Ethernet II) and packet-llc.c (SNAP)
4  *
5  * $Id: ethertype.c,v 1.17 1999/10/20 22:41:11 guy Exp $
6  *
7  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * 
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36
37 #include <glib.h>
38 #include "packet.h"
39 #include "etypes.h"
40
41 const value_string etype_vals[] = {
42     {ETHERTYPE_IP,     "IP"             },
43     {ETHERTYPE_IPv6,   "IPv6"           },
44     {ETHERTYPE_ARP,    "ARP"            },
45     {ETHERTYPE_REVARP, "RARP"           },
46     {ETHERTYPE_ATALK,  "Appletalk"      },
47     {ETHERTYPE_AARP,   "AARP"           },
48     {ETHERTYPE_IPX,    "Netware IPX/SPX"},
49     {ETHERTYPE_VINES,  "Vines"          },
50     {ETHERTYPE_CDP,    "CDP"            }, /* Cisco Discovery Protocol */
51     {ETHERTYPE_TRAIN,   "Netmon Train"  },
52     {ETHERTYPE_LOOP,   "Loopback"       }, /* Ethernet Loopback */
53     {ETHERTYPE_PPPOED, "PPPoE Discovery"}, 
54     {ETHERTYPE_PPPOES, "PPPoE Session"  }, 
55     {ETHERTYPE_VLAN,   "802.1Q Virtual LAN" },
56     {0,                 NULL            } };
57
58 void
59 capture_ethertype(guint16 etype, int offset,
60                 const u_char *pd, guint32 cap_len, packet_counts *ld)
61 {
62   switch (etype) {
63     case ETHERTYPE_IP:
64       capture_ip(pd, offset, cap_len, ld);
65       break;
66     default:
67       ld->other++;
68       break;
69   }
70 }
71
72 void
73 ethertype(guint16 etype, int offset,
74                 const u_char *pd, frame_data *fd, proto_tree *tree, proto_tree
75                 *fh_tree, int item_id)
76 {
77   if (tree) {
78         proto_tree_add_item(fh_tree, item_id, offset - 2, 2, etype);
79   }
80   switch (etype) {
81     case ETHERTYPE_IP:
82       dissect_ip(pd, offset, fd, tree);
83       break;
84     case ETHERTYPE_IPv6:
85       dissect_ipv6(pd, offset, fd, tree);
86       break;
87     case ETHERTYPE_ARP:
88       dissect_arp(pd, offset, fd, tree);
89       break;
90     case ETHERTYPE_REVARP:
91       dissect_arp(pd, offset, fd, tree);
92       break;
93     case ETHERTYPE_ATALK:
94       dissect_ddp(pd, offset, fd, tree);
95       break;
96     case ETHERTYPE_AARP:
97       dissect_aarp(pd, offset, fd, tree);
98       break;
99     case ETHERTYPE_IPX:
100       dissect_ipx(pd, offset, fd, tree);
101       break;
102     case ETHERTYPE_VINES:
103       dissect_vines(pd, offset, fd, tree);
104       break;
105     case ETHERTYPE_CDP:
106       dissect_cdp(pd, offset, fd, tree);
107       break;
108     case ETHERTYPE_LOOP:
109       dissect_data(pd, offset, fd, tree);
110       if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "LOOP"); }
111       break;
112     case ETHERTYPE_PPPOED:
113       dissect_pppoed(pd, offset, fd, tree);
114       break;
115     case ETHERTYPE_PPPOES:
116       dissect_pppoes(pd, offset, fd, tree);
117       break;
118     case ETHERTYPE_VLAN:
119       dissect_vlan(pd, offset, fd, tree);
120       break;
121     default:
122       dissect_data(pd, offset, fd, tree);
123       if (check_col(fd, COL_PROTOCOL)) { col_add_fstr(fd, COL_PROTOCOL, "0x%04x", etype); }
124       break;
125   }
126 }
127
128
129