The Sniffer-reading code in wiretap now decodes the time field for each
[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.9 1998/11/12 00:06:20 gram 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 <gtk/gtk.h>
38
39 #include <stdio.h>
40
41 #include "ethereal.h"
42 #include "packet.h"
43 #include "etypes.h"
44
45 gchar *
46 ethertype_to_str(guint16 etype, const char *fmt)
47 {
48   static const value_string etype_vals[] = {
49     {ETHERTYPE_IP,     "IP"             },
50     {ETHERTYPE_IPv6,   "IPv6"           },
51     {ETHERTYPE_ARP,    "ARP"            },
52     {ETHERTYPE_REVARP, "RARP"           },
53     {ETHERTYPE_ATALK,  "Appletalk"      },
54     {ETHERTYPE_AARP,   "AARP"           },
55     {ETHERTYPE_IPX,    "Netware IPX/SPX"},
56     {ETHERTYPE_VINES,  "Vines"          },
57     {0,                 NULL            } };
58
59     return val_to_str(etype, etype_vals, fmt);
60 }
61
62 void
63 ethertype(guint16 etype, int offset,
64                 const u_char *pd, frame_data *fd, GtkTree *tree, GtkWidget
65                 *fh_tree)
66 {
67   if (tree) {
68     add_item_to_tree(fh_tree, offset - 2, 2, "Type: %s (0x%04x)",
69       ethertype_to_str(etype, "Unknown"), etype);
70   }
71   switch (etype) {
72     case ETHERTYPE_IP:
73       dissect_ip(pd, offset, fd, tree);
74       break;
75     case ETHERTYPE_IPv6:
76       dissect_ipv6(pd, offset, fd, tree);
77       break;
78     case ETHERTYPE_ARP:
79       dissect_arp(pd, offset, fd, tree);
80       break;
81     case ETHERTYPE_REVARP:
82       dissect_arp(pd, offset, fd, tree);
83       break;
84     case ETHERTYPE_ATALK:
85       dissect_ddp(pd, offset, fd, tree);
86       break;
87     case ETHERTYPE_AARP:
88       dissect_aarp(pd, offset, fd, tree);
89       break;
90     case ETHERTYPE_IPX:
91       dissect_ipx(pd, offset, fd, tree);
92       break;
93     case ETHERTYPE_VINES:
94       dissect_vines(pd, offset, fd, tree);
95       break;
96     default:
97       dissect_data(pd, offset, fd, tree);
98       if (fd->win_info[COL_NUM]) { sprintf(fd->win_info[COL_PROTOCOL], "0x%04x", etype); }
99       break;
100   }
101  }