2 * Routines for RIPng disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
4 * derived from packet-rip.c
6 * $Id: packet-ripng.c,v 1.27 2002/08/28 21:00:29 jmayer Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include "packet-ripng.h"
35 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
38 static int proto_ripng = -1;
39 static int hf_ripng_cmd = -1;
40 static int hf_ripng_version = -1;
42 static gint ett_ripng = -1;
43 static gint ett_ripng_addr = -1;
45 #define UDP_PORT_RIPNG 521
47 static const value_string cmdvals[] = {
48 { RIP6_REQUEST, "Request" },
49 { RIP6_RESPONSE, "Response" },
54 dissect_ripng(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
58 proto_tree *ripng_tree = NULL;
59 proto_tree *subtree = NULL;
62 if (check_col(pinfo->cinfo, COL_PROTOCOL))
63 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIPng");
64 if (check_col(pinfo->cinfo, COL_INFO))
65 col_clear(pinfo->cinfo, COL_INFO);
67 /* avoid alignment problem */
68 tvb_memcpy(tvb, (guint8 *)&rip6, offset, sizeof(rip6));
70 if (check_col(pinfo->cinfo, COL_PROTOCOL))
71 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "RIPng version %u", rip6.rip6_vers);
72 if (check_col(pinfo->cinfo, COL_INFO))
73 col_add_str(pinfo->cinfo, COL_INFO,
74 val_to_str(rip6.rip6_cmd, cmdvals, "Unknown command (%u)"));
77 ti = proto_tree_add_item(tree, proto_ripng, tvb, offset, -1, FALSE);
78 ripng_tree = proto_item_add_subtree(ti, ett_ripng);
80 proto_tree_add_uint(ripng_tree, hf_ripng_cmd, tvb, offset, 1,
82 proto_tree_add_uint(ripng_tree, hf_ripng_version, tvb, offset + 1, 1,
86 while (tvb_reported_length_remaining(tvb, offset) > 0) {
87 tvb_memcpy(tvb, (guint8 *)&ni6, offset, sizeof(ni6));
89 ti = proto_tree_add_text(ripng_tree, tvb, offset,
90 sizeof(ni6), "IP Address: %s/%u, Metric: %u, tag: 0x%04x",
91 ip6_to_str(&ni6.rip6_dest),
94 g_ntohs(ni6.rip6_tag));
96 ti = proto_tree_add_text(ripng_tree, tvb, offset,
97 sizeof(ni6), "IP Address: %s/%u, Metric: %u",
98 ip6_to_str(&ni6.rip6_dest),
102 subtree = proto_item_add_subtree(ti, ett_ripng_addr);
103 proto_tree_add_text(subtree, tvb,
104 offset + offsetof(struct netinfo6, rip6_dest),
105 sizeof(ni6.rip6_dest), "IP Address: %s",
106 ip6_to_str(&ni6.rip6_dest));
107 proto_tree_add_text(subtree, tvb,
108 offset + offsetof(struct netinfo6, rip6_tag),
109 sizeof(ni6.rip6_tag), "Tag: 0x%04x",
110 g_ntohs(ni6.rip6_tag));
111 proto_tree_add_text(subtree, tvb,
112 offset + offsetof(struct netinfo6, rip6_plen),
113 sizeof(ni6.rip6_plen), "Prefix length: %u",
115 proto_tree_add_text(subtree, tvb,
116 offset + offsetof(struct netinfo6, rip6_metric),
117 sizeof(ni6.rip6_metric), "Metric: %u",
120 offset += sizeof(ni6);
126 proto_register_ripng(void)
128 static hf_register_info hf[] = {
130 { "Command", "ripng.cmd",
131 FT_UINT8, BASE_DEC, VALS(cmdvals),
134 { "Version", "ripng.version",
135 FT_UINT8, BASE_DEC, NULL,
138 static gint *ett[] = {
143 proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng");
144 proto_register_field_array(proto_ripng, hf, array_length(hf));
145 proto_register_subtree_array(ett, array_length(ett));
149 proto_reg_handoff_ripng(void)
151 dissector_handle_t ripng_handle;
153 ripng_handle = create_dissector_handle(dissect_ripng, proto_ripng);
154 dissector_add("udp.port", UDP_PORT_RIPNG, ripng_handle);