01b8a5949173cee392d7155359425f17a89a7395
[obnox/wireshark/wip.git] / packet-ripng.c
1 /* packet-ripng.c
2  * Routines for RIPng disassembly
3  * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
4  * derived from packet-rip.c
5  *
6  * $Id: packet-ripng.c,v 1.4 1999/10/15 13:21:14 itojun Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  * 
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27  
28 #include "config.h"
29
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
36 #endif
37
38 #include <glib.h>
39 #include "packet.h"
40 #include "packet-ipv6.h"
41 #include "packet-ripng.h"
42
43 static int proto_ripng = -1;
44 static int hf_ripng_cmd = -1;
45 static int hf_ripng_version = -1;
46
47 void 
48 dissect_ripng(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
49     struct rip6 rip6;
50     struct netinfo6 ni6;
51     proto_tree *ripng_tree = NULL;
52         proto_item *ti; 
53     static const value_string cmdvals[] = {
54         { RIP6_REQUEST, "Request" },
55         { RIP6_RESPONSE, "Response" },
56         { 0, NULL },
57     };
58     const char *cmd;
59
60     /* avoid alignment problem */
61     memcpy(&rip6, &pd[offset], sizeof(rip6));
62   
63     cmd = val_to_str(rip6.rip6_cmd, cmdvals, "Unknown");
64
65     if (check_col(fd, COL_PROTOCOL))
66         col_add_fstr(fd, COL_PROTOCOL, "RIPng version %d", rip6.rip6_vers);
67     if (check_col(fd, COL_INFO))
68         col_add_fstr(fd, COL_INFO, "%s", cmd); 
69
70     if (tree) {
71         ti = proto_tree_add_item(tree, proto_ripng, offset, END_OF_FRAME, NULL);
72         ripng_tree = proto_item_add_subtree(ti, ETT_RIPNG);
73
74         proto_tree_add_item_format(ripng_tree, hf_ripng_cmd, offset, 1,
75             rip6.rip6_cmd,
76             "Command: %s (%u)", cmd, rip6.rip6_cmd); 
77         proto_tree_add_item(ripng_tree, hf_ripng_version, offset + 1, 1,
78             rip6.rip6_vers);
79
80         offset += 4;
81         while ((pi.captured_len - offset) >= sizeof(struct netinfo6)){
82             memcpy(&ni6, &pd[offset], sizeof(ni6));
83             if (ni6.rip6_tag) {
84                 ti = proto_tree_add_text(ripng_tree, offset,
85                                 sizeof(ni6), "IP Address: %s/%d, Metric: %ld, tag: 0x%04x",
86                                 ip6_to_str(&ni6.rip6_dest),
87                                 ni6.rip6_plen,
88                                 ni6.rip6_metric,
89                                 ntohs(ni6.rip6_tag));
90             } else {
91                 ti = proto_tree_add_text(ripng_tree, offset,
92                                 sizeof(ni6), "IP Address: %s/%d, Metric: %ld",
93                                 ip6_to_str(&ni6.rip6_dest),
94                                 ni6.rip6_plen,
95                                 ni6.rip6_metric);
96             }
97
98             offset += sizeof(ni6);
99         }
100     }
101 }
102
103 void
104 proto_register_ripng(void)
105 {
106     static hf_register_info hf[] = {
107       { &hf_ripng_cmd,
108         { "Command",            "ripng.cmd",
109                                 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
110       { &hf_ripng_version,
111         { "Version",            "ripng.version",
112                                 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
113     };
114
115     proto_ripng = proto_register_protocol("RIPng", "ripng");
116     proto_register_field_array(proto_ripng, hf, array_length(hf));
117 }