2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-rip.c,v 1.21 2001/01/03 06:55:31 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * 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.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
41 #define UDP_PORT_RIP 520
46 static const value_string version_vals[] = {
52 static const value_string command_vals[] = {
57 { 5, "Vendor specific (Sun)" },
61 #define RIP_HEADER_LENGTH 4
62 #define RIP_ENTRY_LENGTH 20
64 static int proto_rip = -1;
66 static gint ett_rip = -1;
67 static gint ett_rip_vec = -1;
69 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
71 static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
75 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
78 proto_tree *rip_tree = NULL;
83 guint reported_length;
85 CHECK_DISPLAY_AS_DATA(proto_rip, tvb, pinfo, tree);
87 pinfo->current_proto = "RIP";
89 command = tvb_get_guint8(tvb, 0);
90 version = tvb_get_guint8(tvb, 1);
92 if (check_col(pinfo->fd, COL_PROTOCOL))
93 col_add_str(pinfo->fd, COL_PROTOCOL,
94 val_to_str(version, version_vals, "RIP"));
95 if (check_col(pinfo->fd, COL_INFO))
96 col_add_str(pinfo->fd, COL_INFO,
97 val_to_str(command, command_vals, "Unknown command (%u)"));
100 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, tvb_length(tvb), FALSE);
101 rip_tree = proto_item_add_subtree(ti, ett_rip);
103 proto_tree_add_text(rip_tree, tvb, 0, 1, "Command: %u (%s)", command,
104 val_to_str(command, command_vals, "Unknown"));
105 proto_tree_add_text(rip_tree, tvb, 1, 1, "Version: %u", version);
106 if (version == RIPv2)
107 proto_tree_add_text(rip_tree, tvb, 2, 2, "Routing Domain: %u",
108 tvb_get_ntohs(tvb, 2));
111 offset = RIP_HEADER_LENGTH;
113 /* zero or more entries */
114 reported_length = tvb_reported_length(tvb);
115 while (offset < reported_length) {
116 family = tvb_get_ntohs(tvb, offset);
119 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
122 dissect_rip_authentication(tvb, offset, rip_tree);
125 proto_tree_add_text(rip_tree, tvb, offset,
126 RIP_ENTRY_LENGTH, "Unknown address family %u",
131 offset += RIP_ENTRY_LENGTH;
137 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
141 proto_tree *rip_vektor_tree;
145 ip = tvb_get_ptr(tvb, offset+4, 4);
146 metric = tvb_get_ntohl(tvb, offset+16);
147 ti = proto_tree_add_text(tree, tvb, offset,
148 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
149 ip_to_str(ip), metric);
150 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
152 proto_tree_add_text(rip_vektor_tree, tvb, offset, 2,
153 "Address Family ID: IP");
154 if (version == RIPv2)
155 proto_tree_add_text(rip_vektor_tree, tvb, offset + 2, 2,
156 "Route Tag: %u", tvb_get_ntohs(tvb, offset+2));
157 proto_tree_add_text(rip_vektor_tree, tvb, offset + 4, 4, "IP Address: %s",
159 if (version == RIPv2) {
160 proto_tree_add_text(rip_vektor_tree, tvb, offset + 8, 4,
162 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
163 proto_tree_add_text(rip_vektor_tree, tvb, offset + 12, 4,
165 ip_to_str(tvb_get_ptr(tvb, offset+12, 4)));
167 proto_tree_add_text(rip_vektor_tree, tvb, offset + 16, 4, "Metric: %u",
172 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
175 proto_tree *rip_authentication_tree;
177 char authentication[16];
179 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
181 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
183 authtype = tvb_get_ntohs(tvb, offset + 2);
184 proto_tree_add_text(rip_authentication_tree, tvb, offset + 2, 2,
185 "Authentication type: %u", authtype);
187 tvb_get_nstringz0(tvb, offset + 4, 16, authentication);
188 proto_tree_add_text(rip_authentication_tree, tvb, offset + 4, 16,
189 "Password: %s", authentication);
194 proto_register_rip(void)
196 /* static hf_register_info hf[] = {
198 { "Name", "rip.abbreviation", TYPE, VALS_POINTER }},
200 static gint *ett[] = {
205 proto_rip = proto_register_protocol("Routing Information Protocol",
207 /* proto_register_field_array(proto_rip, hf, array_length(hf));*/
208 proto_register_subtree_array(ett, array_length(ett));
212 proto_reg_handoff_rip(void)
214 dissector_add("udp.port", UDP_PORT_RIP, dissect_rip);