Add the "Maximize security" type of service for IP, from RFC
[obnox/wireshark/wip.git] / packet-rip.c
1 /* packet-ospf.c
2  * Routines for RIPv1 and RIPv2 packet disassembly
3  * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
4  *
5  * $Id: packet-rip.c,v 1.3 1998/09/27 22:12:38 gerald Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  * 
11  * 
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.
16  * 
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.
21  * 
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.
25  */
26  
27 #include "config.h"
28
29 #include <gtk/gtk.h>
30
31 #include <stdio.h>
32
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
39 #endif
40
41 #include "ethereal.h"
42 #include "packet.h"
43 #include "packet-rip.h"
44
45
46 void 
47 dissect_rip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
48     e_riphdr *rip_header;
49     e_rip_vektor rip_vektor;
50     int auth = FALSE;
51
52     GtkWidget *rip_tree = NULL, *ti; 
53     GtkWidget *rip_vektor_tree;
54
55
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" };
60
61
62     rip_header = (e_riphdr *) &pd[offset];
63     /* Check if we 've realy got a RIP packet */
64
65     switch(rip_header->version) {
66         case RIPv1:
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);
70                 return;
71             }
72             /* the RIPv2 checks are also made for v1 packets */
73         case RIPv2:
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) 
76              */
77             if( !( (rip_header->command > 0) && (rip_header->command <= 7) )){ 
78                 dissect_data(pd, offset, fd, tree);
79                 return;
80             }
81             break;
82         default:
83             /* we only know RIPv1 and RIPv2 */
84             dissect_data(pd, offset, fd, tree);
85             return;
86     }
87
88
89     if (fd->win_info[COL_NUM]) {
90         strcpy(fd->win_info[COL_PROTOCOL], version[rip_header->version] );
91         sprintf(fd->win_info[COL_INFO], "%s", packet_type[rip_header->command]); 
92     }  
93
94     if (tree) {
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);
98
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)){
102             case 2: /* IP */
103                 add_item_to_tree(rip_tree, offset + 4 , 2, "Address Family ID: IP"); 
104                 break;
105             case 0xFFFF:
106                 add_item_to_tree(rip_tree, offset + 4 , 2, "Authenticated Packet"); 
107                 auth = TRUE;
108                 break;
109             default:
110                 /* return; */
111         } 
112
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)); 
116         }
117         /* skip header */
118         offset += RIP_HEADER_LENGTH;
119
120         /* if present, skip the authentication */
121         if(auth){
122             offset += RIP_VEKTOR_LENGTH;
123         }
124         /* zero or more distance vektors */
125
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);
130            
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))); 
133
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))); 
139             }
140
141             add_item_to_tree(rip_vektor_tree, offset + 12 , 4, "Metric: %ld", (long)ntohl(rip_vektor.metric)); 
142
143             offset += RIP_VEKTOR_LENGTH;
144         };
145     }
146 }