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.18 2001/01/22 08:03:45 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
57 static const value_string cmdvals[] = {
58 { RIP6_REQUEST, "Request" },
59 { RIP6_RESPONSE, "Response" },
64 dissect_ripng(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
67 proto_tree *ripng_tree = NULL;
68 proto_tree *subtree = NULL;
71 if (check_col(fd, COL_PROTOCOL))
72 col_set_str(fd, COL_PROTOCOL, "RIPng");
73 if (check_col(fd, COL_INFO))
74 col_clear(fd, COL_INFO);
76 /* avoid alignment problem */
77 memcpy(&rip6, &pd[offset], sizeof(rip6));
79 if (check_col(fd, COL_PROTOCOL))
80 col_add_fstr(fd, COL_PROTOCOL, "RIPng version %u", rip6.rip6_vers);
81 if (check_col(fd, COL_INFO))
82 col_add_str(fd, COL_INFO,
83 val_to_str(rip6.rip6_cmd, cmdvals, "Unknown command (%u)"));
86 ti = proto_tree_add_item(tree, proto_ripng, NullTVB, offset, END_OF_FRAME, FALSE);
87 ripng_tree = proto_item_add_subtree(ti, ett_ripng);
89 proto_tree_add_uint(ripng_tree, hf_ripng_cmd, NullTVB, offset, 1,
91 proto_tree_add_uint(ripng_tree, hf_ripng_version, NullTVB, offset + 1, 1,
95 while ((pi.captured_len - offset) >= sizeof(struct netinfo6)){
96 if (! BYTES_ARE_IN_FRAME(offset, sizeof(ni6))) {
97 proto_tree_add_text(ripng_tree, NullTVB, offset, sizeof(ni6), "No IP Address information");
101 memcpy(&ni6, &pd[offset], sizeof(ni6));
103 ti = proto_tree_add_text(ripng_tree, NullTVB, offset,
104 sizeof(ni6), "IP Address: %s/%u, Metric: %u, tag: 0x%04x",
105 ip6_to_str(&ni6.rip6_dest),
108 ntohs(ni6.rip6_tag));
110 ti = proto_tree_add_text(ripng_tree, NullTVB, offset,
111 sizeof(ni6), "IP Address: %s/%u, Metric: %u",
112 ip6_to_str(&ni6.rip6_dest),
116 subtree = proto_item_add_subtree(ti, ett_ripng_addr);
117 proto_tree_add_text(subtree, NullTVB,
118 offset + offsetof(struct netinfo6, rip6_dest),
119 sizeof(ni6.rip6_dest), "IP Address: %s",
120 ip6_to_str(&ni6.rip6_dest));
121 proto_tree_add_text(subtree, NullTVB,
122 offset + offsetof(struct netinfo6, rip6_tag),
123 sizeof(ni6.rip6_tag), "Tag: 0x%04x",
124 ntohs(ni6.rip6_tag));
125 proto_tree_add_text(subtree, NullTVB,
126 offset + offsetof(struct netinfo6, rip6_plen),
127 sizeof(ni6.rip6_plen), "Prefix length: %u",
129 proto_tree_add_text(subtree, NullTVB,
130 offset + offsetof(struct netinfo6, rip6_metric),
131 sizeof(ni6.rip6_metric), "Metric: %u",
134 offset += sizeof(ni6);
140 proto_register_ripng(void)
142 static hf_register_info hf[] = {
144 { "Command", "ripng.cmd",
145 FT_UINT8, BASE_DEC, VALS(cmdvals),
148 { "Version", "ripng.version",
149 FT_UINT8, BASE_DEC, NULL,
152 static gint *ett[] = {
157 proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng");
158 proto_register_field_array(proto_ripng, hf, array_length(hf));
159 proto_register_subtree_array(ett, array_length(ett));
163 proto_reg_handoff_ripng(void)
165 old_dissector_add("udp.port", UDP_PORT_RIPNG, dissect_ripng, proto_ripng);