2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-rip.c,v 1.10 1999/07/29 05:47:02 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>
39 #include "packet-rip.h"
41 static int proto_rip = -1;
43 static void dissect_ip_rip_vektor(guint8 version,
44 const e_rip_vektor *rip_vektor, int offset, proto_tree *tree);
45 static void dissect_rip_authentication(const e_rip_authentication *rip_authentication,
46 int offset, proto_tree *tree);
49 dissect_rip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
51 e_rip_entry rip_entry;
53 proto_tree *rip_tree = NULL;
56 /* we do the range checking of the index when checking wether or not this is a RIP packet */
57 static char *packet_type[8] = { "never used", "Request", "Response",
58 "Traceon", "Traceoff", "Vendor specific (Sun)" };
59 static char *version[3] = { "RIP", "RIPv1", "RIPv2" };
61 /* avoid alignment problem */
62 memcpy(&rip_header, &pd[offset], sizeof(rip_header));
64 /* Check if we 've realy got a RIP packet */
66 switch(rip_header.version) {
68 /* the domain field has to be set to zero for RIPv1 */
69 if(!(rip_header.domain == 0)){
70 dissect_data(pd, offset, fd, tree);
73 /* the RIPv2 checks are also made for v1 packets */
75 /* check wether or not command nr. is between 1-7
76 * (range checking for index of char* packet_type is done at the same time)
78 if( !( (rip_header.command > 0) && (rip_header.command <= 7) )){
79 dissect_data(pd, offset, fd, tree);
84 /* we only know RIPv1 and RIPv2 */
85 dissect_data(pd, offset, fd, tree);
89 if (check_col(fd, COL_PROTOCOL))
90 col_add_str(fd, COL_PROTOCOL, version[rip_header.version] );
91 if (check_col(fd, COL_INFO))
92 col_add_str(fd, COL_INFO, packet_type[rip_header.command]);
95 ti = proto_tree_add_item(tree, proto_rip, offset, (fd->cap_len - offset), NULL);
96 rip_tree = proto_item_add_subtree(ti, ETT_RIP);
98 proto_tree_add_text(rip_tree, offset, 1, "Command: %d (%s)", rip_header.command, packet_type[rip_header.command]);
99 proto_tree_add_text(rip_tree, offset + 1, 1, "Version: %d", rip_header.version);
100 if(rip_header.version == RIPv2)
101 proto_tree_add_text(rip_tree, offset + 2 , 2, "Routing Domain: %d", ntohs(rip_header.domain));
104 offset += RIP_HEADER_LENGTH;
106 /* zero or more entries */
108 while((fd->cap_len - offset) >= RIP_ENTRY_LENGTH){
109 memcpy(&rip_entry, &pd[offset], sizeof(rip_entry)); /* avoid alignment problem */
110 family = ntohs(rip_entry.vektor.family);
113 ti = proto_tree_add_text(rip_tree, offset,
114 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %ld",
115 ip_to_str((guint8 *) &(rip_entry.vektor.ip)),
116 (long)ntohl(rip_entry.vektor.metric));
117 dissect_ip_rip_vektor(rip_header.version, &rip_entry.vektor,
121 proto_tree_add_text(rip_tree, offset,
122 RIP_ENTRY_LENGTH, "Authentication");
123 dissect_rip_authentication(&rip_entry.authentication,
127 proto_tree_add_text(rip_tree, offset,
128 RIP_ENTRY_LENGTH, "Unknown address family %u",
133 offset += RIP_ENTRY_LENGTH;
139 dissect_ip_rip_vektor(guint8 version, const e_rip_vektor *rip_vektor,
140 int offset, proto_tree *tree)
142 proto_tree *rip_vektor_tree;
144 rip_vektor_tree = proto_item_add_subtree(tree, ETT_RIP_VEC);
146 proto_tree_add_text(rip_vektor_tree, offset, 2, "Address Family ID: IP");
148 proto_tree_add_text(rip_vektor_tree, offset + 2 , 2, "Route Tag: %d",
149 ntohs(rip_vektor->tag));
150 proto_tree_add_text(rip_vektor_tree, offset + 4, 4, "IP Address: %s",
151 ip_to_str((guint8 *) &(rip_vektor->ip)));
152 if(version == RIPv2) {
153 proto_tree_add_text(rip_vektor_tree, offset + 8 , 4, "Netmask: %s",
154 ip_to_str((guint8 *) &(rip_vektor->mask)));
155 proto_tree_add_text(rip_vektor_tree, offset + 12, 4, "Next Hop: %s",
156 ip_to_str((guint8 *) &(rip_vektor->next_hop)));
158 proto_tree_add_text(rip_vektor_tree, offset + 16, 4, "Metric: %ld",
159 (long)ntohl(rip_vektor->metric));
163 dissect_rip_authentication(const e_rip_authentication *rip_authentication,
164 int offset, proto_tree *tree)
166 proto_tree *rip_authentication_tree;
169 rip_authentication_tree = proto_item_add_subtree(tree, ETT_RIP_VEC);
171 authtype = ntohs(rip_authentication->authtype);
172 proto_tree_add_text(rip_authentication_tree, offset + 2, 2,
173 "Authentication type: %u", authtype);
175 proto_tree_add_text(rip_authentication_tree, offset + 4 , 16,
177 rip_authentication->authentication);
181 proto_register_rip(void)
183 /* static hf_register_info hf[] = {
185 { "Name", "rip.abbreviation", TYPE, VALS_POINTER }},
188 proto_rip = proto_register_protocol("Routing Information Protocol", "rip");
189 /* proto_register_field_array(proto_rip, hf, array_length(hf));*/