MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-ripng.c
blob1dd809670a716b321c86b4bf9d439c61cb841fcd
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
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Enhance RIPng by Alexis La Goutte
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * References:
29 * RFC2080: RIPng for IPv6
32 #include "config.h"
34 #include <glib.h>
35 #include <epan/packet.h>
36 #include <epan/to_str.h>
38 static int proto_ripng = -1;
39 static int hf_ripng_cmd = -1;
40 static int hf_ripng_version = -1;
41 static int hf_ripng_reserved = -1;
43 static int hf_ripng_rte = -1;
44 static int hf_ripng_rte_ipv6_prefix = -1;
45 static int hf_ripng_rte_route_tag = -1;
46 static int hf_ripng_rte_prefix_length = -1;
47 static int hf_ripng_rte_metric = -1;
49 static gint ett_ripng = -1;
50 static gint ett_ripng_rte = -1;
52 #define UDP_PORT_RIPNG 521
54 #define RIP6_REQUEST 1
55 #define RIP6_RESPONSE 2
57 static const value_string cmdvals[] = {
58 { RIP6_REQUEST, "Request" },
59 { RIP6_RESPONSE, "Response" },
60 { 0, NULL },
63 static void
64 dissect_ripng(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
65 int offset = 0;
66 proto_tree *ripng_tree = NULL, *rte_tree = NULL;
67 proto_item *ti, *rte_ti;
69 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIPng");
70 col_add_fstr(pinfo->cinfo, COL_INFO," Command %s, Version %u",
71 val_to_str(tvb_get_guint8(tvb, offset), cmdvals, "Unknown (%u)"),
72 tvb_get_guint8(tvb, offset +1));
74 if (tree) {
75 ti = proto_tree_add_item(tree, proto_ripng, tvb, offset, -1, ENC_NA);
76 ripng_tree = proto_item_add_subtree(ti, ett_ripng);
78 /* Command */
79 proto_tree_add_item(ripng_tree, hf_ripng_cmd, tvb, offset, 1, ENC_BIG_ENDIAN);
80 offset += 1;
82 /* Version */
83 proto_tree_add_item(ripng_tree, hf_ripng_version, tvb, offset, 1, ENC_BIG_ENDIAN);
84 offset += 1;
86 /* Reserved */
87 proto_tree_add_item(ripng_tree, hf_ripng_reserved, tvb, offset, 2, ENC_NA);
88 offset += 2;
90 /* Route Table Entry */
91 while (tvb_reported_length_remaining(tvb, offset) > 0) {
93 rte_ti = proto_tree_add_item(ripng_tree, hf_ripng_rte, tvb, offset, 16 + 2 + 1 + 1, ENC_NA);
94 rte_tree = proto_item_add_subtree(rte_ti, ett_ripng_rte);
96 /* IPv6 Prefix */
97 proto_tree_add_item(rte_tree, hf_ripng_rte_ipv6_prefix, tvb, offset, 16, ENC_NA);
98 proto_item_append_text(rte_ti, ": IPv6 Prefix: %s", tvb_ip6_to_str(tvb, offset));
99 offset += 16;
101 /* Route Tag */
102 proto_tree_add_item(rte_tree, hf_ripng_rte_route_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
103 offset += 2;
105 /* Prefix Length */
106 proto_tree_add_item(rte_tree, hf_ripng_rte_prefix_length, tvb, offset, 1, ENC_BIG_ENDIAN);
107 proto_item_append_text(rte_ti, "/%u", tvb_get_guint8(tvb, offset));
108 offset += 1;
110 /* Metric */
111 proto_tree_add_item(rte_tree, hf_ripng_rte_metric, tvb, offset, 1, ENC_BIG_ENDIAN);
112 proto_item_append_text(rte_ti, " Metric: %u", tvb_get_guint8(tvb, offset));
113 offset += 1;
118 void
119 proto_register_ripng(void)
121 static hf_register_info hf[] = {
122 { &hf_ripng_cmd,
123 { "Command", "ripng.cmd",
124 FT_UINT8, BASE_DEC, VALS(cmdvals), 0x0,
125 "Used to specify the purpose of this message", HFILL }},
126 { &hf_ripng_version,
127 { "Version", "ripng.version",
128 FT_UINT8, BASE_DEC, NULL, 0x0,
129 "Version of RIPng", HFILL }},
130 { &hf_ripng_reserved,
131 { "Reserved", "ripng.reserved",
132 FT_BYTES, BASE_NONE, NULL, 0x0,
133 "Must be Zero", HFILL }},
134 { &hf_ripng_rte,
135 { "Route Table Entry", "ripng.rte",
136 FT_NONE, BASE_NONE, NULL, 0x0,
137 NULL, HFILL }},
138 { &hf_ripng_rte_ipv6_prefix,
139 { "IPv6 Prefix", "ripng.rte.ipv6_prefix",
140 FT_IPv6, BASE_NONE, NULL, 0x0,
141 "Destination", HFILL }},
142 { &hf_ripng_rte_route_tag,
143 { "Route Tag", "ripng.rte.route_tag",
144 FT_UINT16, BASE_HEX, NULL, 0x0,
145 "Provides a method of separating internal RIPng routes (routes for networks within the RIPng routing domain) from external RIPng routes, which may have been imported from an EGP or another IGP", HFILL }},
147 { &hf_ripng_rte_prefix_length,
148 { "Prefix Length", "ripng.rte.prefix_length",
149 FT_UINT8, BASE_DEC, NULL, 0x0,
150 "The length in bits of the significant part of the prefix starting from the left of the prefix", HFILL }},
152 { &hf_ripng_rte_metric,
153 { "Metric", "ripng.rte.metric",
154 FT_UINT8, BASE_DEC, NULL, 0x0,
155 "The current metric for the destination; the value 16 (infinity) indicates that the destination is not reachable", HFILL }},
158 static gint *ett[] = {
159 &ett_ripng,
160 &ett_ripng_rte,
163 proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng");
164 proto_register_field_array(proto_ripng, hf, array_length(hf));
165 proto_register_subtree_array(ett, array_length(ett));
168 void
169 proto_reg_handoff_ripng(void)
171 dissector_handle_t ripng_handle;
173 ripng_handle = create_dissector_handle(dissect_ripng, proto_ripng);
174 dissector_add_uint("udp.port", UDP_PORT_RIPNG, ripng_handle);