2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-rip.c,v 1.2 1998/09/16 03:22:10 gerald 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.
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
43 #include "packet-rip.h"
47 dissect_rip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
49 e_rip_vektor rip_vektor;
52 GtkWidget *rip_tree = NULL, *ti;
53 GtkWidget *rip_vektor_tree;
56 /* we do the range checking of the index when checking wether or not this is a RIP packet */
57 char *packet_type[8] = { "never used", "Request", "Response",
58 "Traceon", "Traceoff", "Vendor specific (Sun)" };
59 char *version[3] = { "RIP", "RIPv1", "RIPv2" };
62 rip_header = (e_riphdr *) &pd[offset];
63 /* Check if we 've realy got a RIP packet */
65 switch(rip_header->version) {
67 /* the domain field has to be set to zero for RIPv1 */
68 if(!(rip_header->domain == 0)){
69 dissect_data(pd, offset, fd, tree);
72 /* the RIPv2 checks are also made for v1 packets */
74 /* check wether or not command nr. is between 1-7
75 * (range checking for index of char* packet_type is done at the same time)
77 if( !( (rip_header->command > 0) && (rip_header->command <= 7) )){
78 dissect_data(pd, offset, fd, tree);
83 /* we only know RIPv1 and RIPv2 */
84 dissect_data(pd, offset, fd, tree);
89 if (fd->win_info[0]) {
90 strcpy(fd->win_info[3], version[rip_header->version] );
91 sprintf(fd->win_info[4], "%s", packet_type[rip_header->command]);
95 ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset), "Routing Information Protocol");
96 rip_tree = gtk_tree_new();
97 add_subtree(ti, rip_tree, ETT_RIP);
99 add_item_to_tree(rip_tree, offset + 1, 1, "Version: %d", rip_header->version);
100 add_item_to_tree(rip_tree, offset, 1, "Command: %d (%s)", rip_header->command, packet_type[rip_header->command]);
101 switch(ntohs(rip_header->family)){
103 add_item_to_tree(rip_tree, offset + 4 , 2, "Address Family ID: IP");
106 add_item_to_tree(rip_tree, offset + 4 , 2, "Authenticated Packet");
113 if(rip_header->version == RIPv2) {
114 add_item_to_tree(rip_tree, offset + 2 , 2, "Routing Domain: %d", ntohs(rip_header->domain));
115 add_item_to_tree(rip_tree, offset + 6 , 2, "Route Tag: %d", ntohs(rip_header->tag));
118 offset += RIP_HEADER_LENGTH;
120 /* if present, skip the authentication */
122 offset += RIP_VEKTOR_LENGTH;
124 /* zero or more distance vektors */
126 while((fd->cap_len - offset) >= RIP_VEKTOR_LENGTH){
127 ti = add_item_to_tree(GTK_WIDGET(rip_tree), offset, RIP_VEKTOR_LENGTH, "RIP Vektor");
128 rip_vektor_tree = gtk_tree_new();
129 add_subtree(ti, rip_vektor_tree, ETT_RIP_VEC);
131 memcpy(&rip_vektor, &pd[offset], sizeof(rip_vektor)); /* avoid alignment problem */
132 add_item_to_tree(rip_vektor_tree, offset, 4, "IP Address: %s", ip_to_str((guint8 *) &(rip_vektor.ip)));
134 if(rip_header->version == RIPv2) {
135 add_item_to_tree(rip_vektor_tree, offset + 4 , 4, "Netmask: %s",
136 ip_to_str((guint8 *) &(rip_vektor.mask)));
137 add_item_to_tree(rip_vektor_tree, offset + 8 , 4, "Next Hop: %s",
138 ip_to_str((guint8 *) &(rip_vektor.next_hop)));
141 add_item_to_tree(rip_vektor_tree, offset + 12 , 4, "Metric: %d", ntohl(rip_vektor.metric));
143 offset += RIP_VEKTOR_LENGTH;