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.16 2001/01/03 06:55:31 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
41 #include "packet-ipv6.h"
42 #include "packet-ripng.h"
45 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
48 static int proto_ripng = -1;
49 static int hf_ripng_cmd = -1;
50 static int hf_ripng_version = -1;
52 static gint ett_ripng = -1;
53 static gint ett_ripng_addr = -1;
55 #define UDP_PORT_RIPNG 521
58 dissect_ripng(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
61 proto_tree *ripng_tree = NULL;
62 proto_tree *subtree = NULL;
64 static const value_string cmdvals[] = {
65 { RIP6_REQUEST, "Request" },
66 { RIP6_RESPONSE, "Response" },
71 OLD_CHECK_DISPLAY_AS_DATA(proto_ripng, pd, offset, fd, tree);
73 /* avoid alignment problem */
74 memcpy(&rip6, &pd[offset], sizeof(rip6));
76 cmd = val_to_str(rip6.rip6_cmd, cmdvals, "Unknown");
78 if (check_col(fd, COL_PROTOCOL))
79 col_add_fstr(fd, COL_PROTOCOL, "RIPng version %u", rip6.rip6_vers);
80 if (check_col(fd, COL_INFO))
81 col_add_fstr(fd, COL_INFO, "%s", cmd);
84 ti = proto_tree_add_item(tree, proto_ripng, NullTVB, offset, END_OF_FRAME, FALSE);
85 ripng_tree = proto_item_add_subtree(ti, ett_ripng);
87 proto_tree_add_uint_format(ripng_tree, hf_ripng_cmd, NullTVB, offset, 1,
89 "Command: %s (%u)", cmd, rip6.rip6_cmd);
90 proto_tree_add_uint(ripng_tree, hf_ripng_version, NullTVB, offset + 1, 1,
94 while ((pi.captured_len - offset) >= sizeof(struct netinfo6)){
95 if (! BYTES_ARE_IN_FRAME(offset, sizeof(ni6))) {
96 proto_tree_add_text(ripng_tree, NullTVB, offset, sizeof(ni6), "No IP Address information");
100 memcpy(&ni6, &pd[offset], sizeof(ni6));
102 ti = proto_tree_add_text(ripng_tree, NullTVB, offset,
103 sizeof(ni6), "IP Address: %s/%u, Metric: %u, tag: 0x%04x",
104 ip6_to_str(&ni6.rip6_dest),
107 ntohs(ni6.rip6_tag));
109 ti = proto_tree_add_text(ripng_tree, NullTVB, offset,
110 sizeof(ni6), "IP Address: %s/%u, Metric: %u",
111 ip6_to_str(&ni6.rip6_dest),
115 subtree = proto_item_add_subtree(ti, ett_ripng_addr);
116 proto_tree_add_text(subtree, NullTVB,
117 offset + offsetof(struct netinfo6, rip6_dest),
118 sizeof(ni6.rip6_dest), "IP Address: %s",
119 ip6_to_str(&ni6.rip6_dest));
120 proto_tree_add_text(subtree, NullTVB,
121 offset + offsetof(struct netinfo6, rip6_tag),
122 sizeof(ni6.rip6_tag), "Tag: 0x%04x",
123 ntohs(ni6.rip6_tag));
124 proto_tree_add_text(subtree, NullTVB,
125 offset + offsetof(struct netinfo6, rip6_plen),
126 sizeof(ni6.rip6_plen), "Prefix length: %u",
128 proto_tree_add_text(subtree, NullTVB,
129 offset + offsetof(struct netinfo6, rip6_metric),
130 sizeof(ni6.rip6_metric), "Metric: %u",
133 offset += sizeof(ni6);
139 proto_register_ripng(void)
141 static hf_register_info hf[] = {
143 { "Command", "ripng.cmd",
144 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
146 { "Version", "ripng.version",
147 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
149 static gint *ett[] = {
154 proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng");
155 proto_register_field_array(proto_ripng, hf, array_length(hf));
156 proto_register_subtree_array(ett, array_length(ett));
160 proto_reg_handoff_ripng(void)
162 old_dissector_add("udp.port", UDP_PORT_RIPNG, dissect_ripng);