* Added column formatting functionality.
[obnox/wireshark/wip.git] / packet-ipv6.c
1 /* packet-ipv6.c
2  * Routines for IPv6 packet disassembly 
3  *
4  * $Id: packet-ipv6.c,v 1.5 1998/11/17 04:28:55 gerald 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 #include <gtk/gtk.h>
31
32 #include <stdio.h>
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include "ethereal.h"
43 #include "packet.h"
44 #include "packet-ipv6.h"
45 #include "etypes.h"
46
47 void
48 dissect_ipv6(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
49   GtkWidget *ipv6_tree, *ti;
50
51   e_ipv6_header ipv6;
52
53   memcpy(&ipv6, (void *) &pd[offset], 8); 
54
55   switch(ipv6.next_header){
56       /*
57       case IP_PROTO_ICMP:
58       case IP_PROTO_IGMP:
59       case IP_PROTO_TCP:
60       case IP_PROTO_UDP:
61       case IP_PROTO_OSPF:
62       */
63       /* Names are set in the associated dissect_* routines */
64       /*    break; */
65      default:
66          if (check_col(fd, COL_PROTOCOL))
67              col_add_str(fd, COL_PROTOCOL, "IPv6");
68          if (check_col(fd, COL_INFO))
69              col_add_fstr(fd, COL_INFO, "IPv6 support is still under development (%d)", ipv6.next_header);
70   }
71
72   if (tree) {
73     /* !!! specify length */
74     ti = add_item_to_tree(GTK_WIDGET(tree), offset, 40,
75       "Internet Protocol Version 6");
76     ipv6_tree = gtk_tree_new();
77     add_subtree(ti, ipv6_tree, ETT_IPv6);
78
79     /* !!! warning: version also contains 4 Bit priority */
80     add_item_to_tree(ipv6_tree, offset,      1, "Version: %d Priority: %d", ipv6.version >> 4 , ipv6.version & 15);
81     add_item_to_tree(ipv6_tree, offset + 6,  1, "Next Header: %d", ipv6.next_header);
82     add_item_to_tree(ipv6_tree, offset + 4,  2, "Payload Length: %d", ntohs(ipv6.payload_length));
83   }
84
85   /* start of the new header (could be a extension header) */
86   offset += 40;
87   switch (ipv6.next_header) {
88       case IP_PROTO_ICMP:
89           dissect_icmp(pd, offset, fd, tree);
90           break;
91       case IP_PROTO_IGMP:
92           dissect_igmp(pd, offset, fd, tree);
93           break;
94       case IP_PROTO_TCP:
95           dissect_tcp(pd, offset, fd, tree);
96           break;
97       case IP_PROTO_UDP:
98           dissect_udp(pd, offset, fd, tree);
99           break;
100       case IP_PROTO_OSPF:
101           dissect_ospf(pd, offset, fd, tree);
102           break;
103       default:
104           dissect_data(pd, offset, fd, tree);
105   }
106 }
107