2 * Routines for ethernet packet disassembly
4 * $Id: packet-eth.c,v 1.6 1998/11/12 00:06:26 gram Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
44 /* These are the Netware-ish names for the different Ethernet frame types.
45 EthernetII: The ethernet with a Type field instead of a length field
46 Ethernet802.2: An 802.3 header followed by an 802.3 header
47 Ethernet802.3: A raw 802.3 packet. IPX/SPX can be the only payload.
48 There's not 802.2 hdr in this.
49 EthernetSNAP: Basically 802.2, just with 802.2SNAP. For our purposes,
50 there's no difference between 802.2 and 802.2SNAP, since we just
51 pass it down to dissect_llc(). -- Gilbert
54 #define ETHERNET_802_2 1
55 #define ETHERNET_802_3 2
56 #define ETHERNET_SNAP 3
59 dissect_eth(const u_char *pd, frame_data *fd, GtkTree *tree) {
60 guint16 etype, length;
62 GtkWidget *fh_tree = NULL, *ti;
63 int ethhdr_type; /* the type of ethernet frame */
65 if (fd->win_info[COL_NUM]) {
66 strcpy(fd->win_info[COL_DESTINATION], get_ether_name((u_char *)&pd[0]));
67 strcpy(fd->win_info[COL_SOURCE], get_ether_name((u_char *)&pd[6]));
68 strcpy(fd->win_info[COL_INFO], "Ethernet II");
71 etype = (pd[12] << 8) | pd[13];
73 /* either ethernet802.3 or ethernet802.2 */
74 if (etype <= IEEE_802_3_MAX_LEN) {
77 /* Is there an 802.2 layer? I can tell by looking at the first 2
78 bytes after the 802.3 header. If they are 0xffff, then what
79 follows the 802.3 header is an IPX payload, meaning no 802.2.
80 (IPX/SPX is they only thing that can be contained inside a
81 straight 802.3 packet). A non-0xffff value means that there's an
82 802.2 layer inside the 802.3 layer */
83 if (pd[14] == 0xff && pd[15] == 0xff) {
84 ethhdr_type = ETHERNET_802_3;
87 ethhdr_type = ETHERNET_802_2;
90 if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_INFO], "802.3"); }
92 ti = add_item_to_tree(GTK_WIDGET(tree), 0, offset,
93 "IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
95 fh_tree = gtk_tree_new();
96 add_subtree(ti, fh_tree, ETT_IEEE8023);
97 add_item_to_tree(fh_tree, 0, 6, "Destination: %s (%s)",
98 ether_to_str((guint8 *) &pd[0]),
99 get_ether_name((u_char *) &pd[0]));
100 add_item_to_tree(fh_tree, 6, 6, "Source: %s (%s)",
101 ether_to_str((guint8 *) &pd[6]),
102 get_ether_name((u_char *)&pd[6]));
103 add_item_to_tree(fh_tree, 12, 2, "Length: %d", length);
107 ethhdr_type = ETHERNET_II;
109 ti = add_item_to_tree(GTK_WIDGET(tree), 0, 14, "Ethernet II");
110 fh_tree = gtk_tree_new();
111 add_subtree(ti, fh_tree, ETT_ETHER2);
112 add_item_to_tree(fh_tree, 0, 6, "Destination: %s (%s)",
113 ether_to_str((guint8 *) &pd[0]),
114 get_ether_name((u_char *)&pd[0]));
115 add_item_to_tree(fh_tree, 6, 6, "Source: %s (%s)",
116 ether_to_str((guint8 *) &pd[6]),
117 get_ether_name((u_char *)&pd[6]));
121 /* either ethernet802.3 or ethernet802.2 */
122 switch (ethhdr_type) {
124 dissect_ipx(pd, offset, fd, tree);
127 dissect_llc(pd, offset, fd, tree);
132 ethertype(etype, offset, pd, fd, tree, fh_tree);