2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-rip.c,v 1.24 2001/03/13 21:34:23 gram 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 if (check_col(pinfo->fd, COL_PROTOCOL))
86 col_set_str(pinfo->fd, COL_PROTOCOL, "RIP");
87 if (check_col(pinfo->fd, COL_INFO))
88 col_clear(pinfo->fd, COL_INFO);
90 command = tvb_get_guint8(tvb, 0);
91 version = tvb_get_guint8(tvb, 1);
93 if (check_col(pinfo->fd, COL_PROTOCOL))
94 col_add_str(pinfo->fd, COL_PROTOCOL,
95 val_to_str(version, version_vals, "RIP"));
96 if (check_col(pinfo->fd, COL_INFO))
97 col_add_str(pinfo->fd, COL_INFO,
98 val_to_str(command, command_vals, "Unknown command (%u)"));
101 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, tvb_length(tvb), FALSE);
102 rip_tree = proto_item_add_subtree(ti, ett_rip);
104 proto_tree_add_text(rip_tree, tvb, 0, 1, "Command: %u (%s)", command,
105 val_to_str(command, command_vals, "Unknown"));
106 proto_tree_add_text(rip_tree, tvb, 1, 1, "Version: %u", version);
107 if (version == RIPv2)
108 proto_tree_add_text(rip_tree, tvb, 2, 2, "Routing Domain: %u",
109 tvb_get_ntohs(tvb, 2));
112 offset = RIP_HEADER_LENGTH;
114 /* zero or more entries */
115 reported_length = tvb_reported_length(tvb);
116 while (offset < reported_length) {
117 family = tvb_get_ntohs(tvb, offset);
120 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
123 dissect_rip_authentication(tvb, offset, rip_tree);
126 proto_tree_add_text(rip_tree, tvb, offset,
127 RIP_ENTRY_LENGTH, "Unknown address family %u",
132 offset += RIP_ENTRY_LENGTH;
138 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
142 proto_tree *rip_vektor_tree;
146 ip = tvb_get_ptr(tvb, offset+4, 4);
147 metric = tvb_get_ntohl(tvb, offset+16);
148 ti = proto_tree_add_text(tree, tvb, offset,
149 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
150 ip_to_str(ip), metric);
151 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
153 proto_tree_add_text(rip_vektor_tree, tvb, offset, 2,
154 "Address Family ID: IP");
155 if (version == RIPv2)
156 proto_tree_add_text(rip_vektor_tree, tvb, offset + 2, 2,
157 "Route Tag: %u", tvb_get_ntohs(tvb, offset+2));
158 proto_tree_add_text(rip_vektor_tree, tvb, offset + 4, 4, "IP Address: %s",
160 if (version == RIPv2) {
161 proto_tree_add_text(rip_vektor_tree, tvb, offset + 8, 4,
163 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
164 proto_tree_add_text(rip_vektor_tree, tvb, offset + 12, 4,
166 ip_to_str(tvb_get_ptr(tvb, offset+12, 4)));
168 proto_tree_add_text(rip_vektor_tree, tvb, offset + 16, 4, "Metric: %u",
173 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
176 proto_tree *rip_authentication_tree;
178 char authentication[16];
180 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
182 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
184 authtype = tvb_get_ntohs(tvb, offset + 2);
185 proto_tree_add_text(rip_authentication_tree, tvb, offset + 2, 2,
186 "Authentication type: %u", authtype);
188 tvb_get_nstringz0(tvb, offset + 4, 16, authentication);
189 proto_tree_add_text(rip_authentication_tree, tvb, offset + 4, 16,
190 "Password: %s", authentication);
195 proto_register_rip(void)
197 /* static hf_register_info hf[] = {
199 { "Name", "rip.abbreviation", TYPE, VALS_POINTER }},
201 static gint *ett[] = {
206 proto_rip = proto_register_protocol("Routing Information Protocol",
208 /* proto_register_field_array(proto_rip, hf, array_length(hf));*/
209 proto_register_subtree_array(ett, array_length(ett));
213 proto_reg_handoff_rip(void)
215 dissector_add("udp.port", UDP_PORT_RIP, dissect_rip, proto_rip);