Un-comment "AC_CONFIG_SUBDIRS()", so that it'll run "configure" in the
[obnox/wireshark/wip.git] / packet-eth.c
1 /* packet-eth.c
2  * Routines for ethernet packet disassembly
3  *
4  * $Id: packet-eth.c,v 1.6 1998/11/12 00:06:26 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
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.
15  * 
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.
20  * 
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #include <gtk/gtk.h>
35
36 #include <stdio.h>
37
38
39 #include "ethereal.h"
40 #include "packet.h"
41 #include "etypes.h"
42 #include "resolv.h"
43
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
52 */
53 #define ETHERNET_II     0
54 #define ETHERNET_802_2  1
55 #define ETHERNET_802_3  2
56 #define ETHERNET_SNAP   3
57
58 void
59 dissect_eth(const u_char *pd, frame_data *fd, GtkTree *tree) {
60   guint16    etype, length;
61   int        offset = 14;
62   GtkWidget *fh_tree = NULL, *ti;
63   int           ethhdr_type;    /* the type of ethernet frame */
64
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");
69   }
70
71   etype = (pd[12] << 8) | pd[13];
72
73         /* either ethernet802.3 or ethernet802.2 */
74   if (etype <= IEEE_802_3_MAX_LEN) {
75     length = etype;
76
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;
85     }
86     else {
87       ethhdr_type = ETHERNET_802_2;
88     }
89
90     if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_INFO], "802.3"); }
91     if (tree) {
92       ti = add_item_to_tree(GTK_WIDGET(tree), 0, offset,
93         "IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
94
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);
104     }
105
106   } else {
107     ethhdr_type = ETHERNET_II;
108     if (tree) {
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]));
118     }
119   }
120
121         /* either ethernet802.3 or ethernet802.2 */
122   switch (ethhdr_type) {
123         case ETHERNET_802_3:
124                 dissect_ipx(pd, offset, fd, tree);
125                 return;
126         case ETHERNET_802_2:
127                 dissect_llc(pd, offset, fd, tree);
128                 return;
129   }
130
131         /* Ethernet_II */
132         ethertype(etype, offset, pd, fd, tree, fh_tree);
133 }
134