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.5 1999/10/18 00:37:35 itojun 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>
40 #include "packet-ipv6.h"
41 #include "packet-ripng.h"
44 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
47 static int proto_ripng = -1;
48 static int hf_ripng_cmd = -1;
49 static int hf_ripng_version = -1;
52 dissect_ripng(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
55 proto_tree *ripng_tree = NULL;
56 proto_tree *subtree = NULL;
58 static const value_string cmdvals[] = {
59 { RIP6_REQUEST, "Request" },
60 { RIP6_RESPONSE, "Response" },
65 /* avoid alignment problem */
66 memcpy(&rip6, &pd[offset], sizeof(rip6));
68 cmd = val_to_str(rip6.rip6_cmd, cmdvals, "Unknown");
70 if (check_col(fd, COL_PROTOCOL))
71 col_add_fstr(fd, COL_PROTOCOL, "RIPng version %d", rip6.rip6_vers);
72 if (check_col(fd, COL_INFO))
73 col_add_fstr(fd, COL_INFO, "%s", cmd);
76 ti = proto_tree_add_item(tree, proto_ripng, offset, END_OF_FRAME, NULL);
77 ripng_tree = proto_item_add_subtree(ti, ETT_RIPNG);
79 proto_tree_add_item_format(ripng_tree, hf_ripng_cmd, offset, 1,
81 "Command: %s (%u)", cmd, rip6.rip6_cmd);
82 proto_tree_add_item(ripng_tree, hf_ripng_version, offset + 1, 1,
86 while ((pi.captured_len - offset) >= sizeof(struct netinfo6)){
87 memcpy(&ni6, &pd[offset], sizeof(ni6));
89 ti = proto_tree_add_text(ripng_tree, offset,
90 sizeof(ni6), "IP Address: %s/%d, Metric: %ld, tag: 0x%04x",
91 ip6_to_str(&ni6.rip6_dest),
96 ti = proto_tree_add_text(ripng_tree, offset,
97 sizeof(ni6), "IP Address: %s/%d, Metric: %ld",
98 ip6_to_str(&ni6.rip6_dest),
102 subtree = proto_item_add_subtree(ti, ETT_RIPNG_ADDR);
103 proto_tree_add_text(subtree,
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,
108 offset + offsetof(struct netinfo6, rip6_tag),
109 sizeof(ni6.rip6_tag), "Tag: 0x%04x",
110 ntohs(ni6.rip6_tag));
111 proto_tree_add_text(subtree,
112 offset + offsetof(struct netinfo6, rip6_plen),
113 sizeof(ni6.rip6_plen), "Prefix length: %d",
115 proto_tree_add_text(subtree,
116 offset + offsetof(struct netinfo6, rip6_metric),
117 sizeof(ni6.rip6_metric), "Metric: %d",
120 offset += sizeof(ni6);
126 proto_register_ripng(void)
128 static hf_register_info hf[] = {
130 { "Command", "ripng.cmd",
131 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
133 { "Version", "ripng.version",
134 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
137 proto_ripng = proto_register_protocol("RIPng", "ripng");
138 proto_register_field_array(proto_ripng, hf, array_length(hf));